CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to change start address in program memory
Goto page Previous  1, 2, 3  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ttelmah



Joined: 11 Mar 2010
Posts: 19219

View user's profile Send private message

PostPosted: Wed Mar 14, 2012 3:23 pm     Reply with quote

That is what the interrupt= entry does in #build....

Best Wishes
jeremiah



Joined: 20 Jul 2010
Posts: 1317

View user's profile Send private message

PostPosted: Wed Mar 14, 2012 3:27 pm     Reply with quote

ok, this is where it gets tricky. You need to HOPE that the bootloader already thought of that and has an address programmed at 0x0022. What you need to do is look at JUST the bootloader hex file (not one linked with your app) and find the corresponding address for that location to see what value it programs there. Be careful trying to locate it. I *think* intel hex file format uses BYTE addresses and the program memory is WORD aligned, so you may have to divide by 2 to get the right address (I.E. Address 0x0044 in the hex file MIGHT actually be 0x0022 in program memory).

Also, while you are there, look at addresses around that spot. Those will make a difference in how you approach the ISRs. We need to make sure all the addresses are 4 or more addresses apart.

Figure out what the address is (it will be 16 bits), and see if it is outside of the 0x0000-0x03FF range.

Let me know what you find:
1. Address stored at 0x0022 in the bootloader without your app:
2. Addresses around that location:


We can go from there.



richi-d wrote:

This is from the Program memory of the Version 1 of my app:
18 00022 00791E TIMER2_isr

This is from the Program memory of the Version 2 of my app:
18 00022 00790E TIMER2_isr

I tried your code, but get a lot of error messages:
//Remap IVT table, #ORG empty spaces
#ORG 0x0004,0x0019 {}
#ROM 0x001A = {0x0830} //Timer1 Interrupt will always be at 0x0830
#ORG 0x001C,0x01FE {}


How can I easilymake it that this example above is always on 00791


Oh that code was from before I realized you cannot edit the bootloader. You said it was always supplied. All that code does is load the IVT in the bootloader so we can use ISRs in the app code. This is what I am hoping the bootloader did for you. The app code will have something more like:

Code:

#build (interrupt=address)


Where the address in this code will correspond to where the bootloader provided you a new IVT (outside of the normal one).

For example, if you are lucky and the bootloader said "lets always make sure TIMER2 ISR happens at 0x0840", then assuming they kept the new IVT ordered the same as the old table, you would call #BUILD (interrupt=0x0804) and what will happen is you can place ISR's in your code with no problem. The pic will go to 0x0022 for the interrupt, get the 0x840 address and go there and what it will see is a GOTO instruction placed by the compiler sending it to the ISR in the right location (works just like the reset vector). Again, you wouldn't have to manually change anything at that point.

EDIT: The "address=0x0804" was intentional in that example and not a digit swap. Remember, the address is the top of the IVT. I just happen to know that a top address of 0x804 will correspond to a timer2 isr entry of 0x0840, based on the math.
jeremiah



Joined: 20 Jul 2010
Posts: 1317

View user's profile Send private message

PostPosted: Wed Mar 14, 2012 7:05 pm     Reply with quote

richi-d,

I put together a quick example of what needs to be done for it to work with ISR. I had to make a CCS based bootloader since I don't have the setup to test a real bootloader, but I wanted you to see how all the memory lines up. I am using compiler version 4.130 btw. You might consider taking both projects and compiling them and comparing both the LST files and the hex files to see how they would work.

Lets start with the bootloader. I generated this just to get something that would provide the mapping. This bootloader does the following:

1. Sets the "application" reset vector to 0x0800 (LOADER_END+1 ends up being this value).
2. Expects the "application" to use addresses 0x0804-0x9FF for the application IVT.

bootloader.c
Code:

#case
#include <24FJ256GA106.h>

#DEVICE *=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOWINDIS                 //Watch Dog Timer in Window mode
#FUSES NOJTAG                   //JTAG disabled
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES PR                       //Primary Oscillator

//Set application space at two pages away
#DEFINE LOADER_END (getenv("FLASH_ERASE_SIZE")-1)  //FLASH_ERASE_SIZE is bytes

//Just for convenience
#DEFINE BL_IVT_START  0x0004
#DEFINE APP_IVT_START (LOADER_END+5)
#DEFINE BL_IVT_STEP  2     //Just addresses, so only 32bits per
#DEFINE APP_IVT_STEP 4     //GOTO instructions, so 64bits per


//Remap the IVT using the APP IVT location to keep the compiler from
//not wanting to let you remap the IVT here.  This doesn't generate any code,
//but lets the #ROM and #ORG statements work
#BUILD (interrupt=APP_IVT_START)  //must do this to remap IVT table

//IVT Mapping to application code space
#ROM BL_IVT_START + BL_IVT_STEP *   0 = {APP_IVT_START + APP_IVT_STEP *   0}
#ROM BL_IVT_START + BL_IVT_STEP *   1 = {APP_IVT_START + APP_IVT_STEP *   1}
#ROM BL_IVT_START + BL_IVT_STEP *   2 = {APP_IVT_START + APP_IVT_STEP *   2}
#ROM BL_IVT_START + BL_IVT_STEP *   3 = {APP_IVT_START + APP_IVT_STEP *   3}
#ROM BL_IVT_START + BL_IVT_STEP *   4 = {APP_IVT_START + APP_IVT_STEP *   4}
#ROM BL_IVT_START + BL_IVT_STEP *   5 = {APP_IVT_START + APP_IVT_STEP *   5}
#ROM BL_IVT_START + BL_IVT_STEP *   6 = {APP_IVT_START + APP_IVT_STEP *   6}
#ROM BL_IVT_START + BL_IVT_STEP *   7 = {APP_IVT_START + APP_IVT_STEP *   7}
#ROM BL_IVT_START + BL_IVT_STEP *   8 = {APP_IVT_START + APP_IVT_STEP *   8}
#ROM BL_IVT_START + BL_IVT_STEP *   9 = {APP_IVT_START + APP_IVT_STEP *   9}
#ROM BL_IVT_START + BL_IVT_STEP *  10 = {APP_IVT_START + APP_IVT_STEP *  10}
#ROM BL_IVT_START + BL_IVT_STEP *  11 = {APP_IVT_START + APP_IVT_STEP *  11}
#ROM BL_IVT_START + BL_IVT_STEP *  12 = {APP_IVT_START + APP_IVT_STEP *  12}
#ROM BL_IVT_START + BL_IVT_STEP *  13 = {APP_IVT_START + APP_IVT_STEP *  13}
#ORG 0x0020,0x01FF {}  //I'm too lazy to finish the mapping here...
                       //just for example


#ORG 0x0200,LOADER_END
void main()
{
   //would normally do bootloader stuff here
   #asm
      GOTO (LOADER_END+1);
   #endasm
}


So this is very simple and doesn't really do anything except jump to the application. I didn't have time to create actual bootloader code, so that is just an example for alignment purposes.

Now here is the meat, the "application" which is what you are working on. To work with a bootloader, you need to have some instructions setup to handle the code start point (the reset vector), and to handle ISRs (since you have code protect on and cannot write directly to 0x0004-0x00FF). It is comprised of two files, bootloader.h, which has the alignment instructions (#ORG), and the reset vector/ivt mapper setup.

bootloader.h
Code:

#ifndef BOOTLOADER_H
#define BOOTLOADER_H

//These values should match what your particular bootloader expects
#DEFINE LOADER_END (getenv("FLASH_ERASE_SIZE")-1)
#BUILD (reset=LOADER_END+1,interrupt=LOADER_END+5)

//this line ensures application code won't be in this range, which is bootloader
#ORG 0x0000,LOADER_END{} 

#endif



It's a very simple file and just needs to be included after you setup your fuses and before any #use or code statements. Here is an example of an "application" using it:

application.c
Code:

#case
#include <24FJ256GA106.h>

#DEVICE *=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES NOWINDIS                 //Watch Dog Timer in Window mode
#FUSES NOJTAG                   //JTAG disabled
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOIOL1WAY                //Allows multiple reconfigurations of peripheral pins
#FUSES NOCKSFSM                 //Clock Switching is disabled, fail Safe clock monitor is disabled
#FUSES PR                       //Primary Oscillator

#include "bootloader.h"

#pin_select U1TX = PIN_B6
#pin_Select U1RX = PIN_B7

#use delay(clock=22118400)
#use rs232(UART1,ERRORS,bits=8,parity=N,stop=1)


unsigned int16 count = 0;
#INT_TIMER1
void timer1_isr(){
   if(count){count--;}
}

#define COUNTER_VAL 500;
void main(){

   setup_timer1(TMR_INTERNAL | TMR_DIV_BY_1,11060);
   set_timer1(0);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INTR_GLOBAL);

   count = COUNTER_VAL;
   while(TRUE){
      if(!count){
         printf("Timer Finished...Restarting\r\n");
         count = COUNTER_VAL;
      }
   }
}


Notice how in the application code, I didn't have to set where the TIMER1 isr was located or where main was located. The compiler auto-did it for me, using info from the #BUILD statement.

The tricks for you is the figuring out where the code start is and putting that in your #BUILD statement (which you already got working) and figuring out where the bootloader moved the IVT to so you can set that up in your #BUILD statement too.

Take a look at the LST files for both sets of files so you can get an idea how the flow works. Start out with trying to trace what happens when a timer1 interrupt occurs. Look at the bootloader ROM location 0x001A, which is the IVT entry for the timer1 interrupt (where the interrupt processing starts) and see if you can follow the path to the actual ISR in application code.
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Thu Mar 15, 2012 3:57 am     Reply with quote

Hello,

I made this now into the application, lot of handwork, but the Program doesn´t start - also not without bootloader...:

Code:

#include <24FJ192GA108.h>
#device adc=10
#device *=16

//#DEFINE LOADER_END (getenv("FLASH_ERASE_SIZE")-0x600)  //FLASH_ERASE_SIZE is bytes

//Just for convenience
#DEFINE BL_IVT_START  0x0004
#DEFINE APP_IVT_START (0x400)
#DEFINE BL_IVT_STEP  2     //Just addresses, so only 32bits per
#DEFINE APP_IVT_STEP 4     //GOTO instructions, so 64bits per


//Remap the IVT using the APP IVT location to keep the compiler from
//not wanting to let you remap the IVT here.  This doesn't generate any code,
//but lets the #ROM and #ORG statements work
#BUILD (interrupt=APP_IVT_START)  //must do this to remap IVT table

//IVT Mapping to application code space

#ROM 0x2E = {0x2E*2 + 0x400}
#ROM 0x38 = {0x38*2 + 0x400}
#ROM 0x9A = {0x9A *2 + 0x400}
#ROM 0xAE = {0xAE *2 + 0x400}
#ROM 0x14 = {0x14 *2 + 0x400}
#ROM 0x3C = {0x3C *2 + 0x400}
#ROM 0x4E = {0x4E *2 + 0x400}
#ROM 0x7E = {0x7E *2 + 0x400}
#ROM 0x80 = {0x80 *2 + 0x400}
#ROM 0x36 = {0x36 *2 + 0x400}
#ROM 0x34 = {0x34 *2 + 0x400}
#ROM 0x78 = {0x78 *2 + 0x400}
#ROM 0x76 = {0x76 *2 + 0x400}
#ROM 0xBE = {0xBE *2 + 0x400}
#ROM 0xBC = {0xBC *2 + 0x400}
#ROM 0x16 = {0x16 *2 + 0x400}
#ROM 0x1E = {0x1E *2 + 0x400}
#ROM 0x5E = {0x5E *2 + 0x400}
#ROM 0x60 = {0x60 *2 + 0x400}
#ROM 0x62 = {0x62 *2 + 0x400}
#ROM 0x64 = {0x64 *2 + 0x400}
#ROM 0x40 = {0x40 *2 + 0x400}
#ROM 0x42 = {0x42 *2 + 0x400}
#ROM 0xCE = {0xCE *2 + 0x400}
#ROM 0x3A = {0x3A *2 + 0x400}
#ROM 0xA4 = {0xA4 *2 + 0x400}
#ROM 0x18 = {0x18 *2 + 0x400}
#ROM 0x20 = {0x20 *2 + 0x400}
#ROM 0x46 = {0x46 *2 + 0x400}
#ROM 0x48 = {0x48 *2 + 0x400}
#ROM 0x66 = {0x66 *2 + 0x400}
#ROM 0x68 = {0x68 *2 + 0x400}
#ROM 0x6A = {0x6A *2 + 0x400}
#ROM 0x6C = {0x6C *2 + 0x400}
#ROM 0xCC = {0xCC *2 + 0x400}
#ROM 0x6E = {0x6E *2 + 0x400}
#ROM 0x90 = {0x90 *2 + 0x400}
#ROM 0x26 = {0x26 *2 + 0x400}
#ROM 0x28 = {0x28 *2 + 0x400}
#ROM 0x54 = {0x54 *2 + 0x400}
#ROM 0x56 = {0x56 *2 + 0x400}
#ROM 0xC8 = {0xC8 *2 + 0x400}
#ROM 0xCA = {0xCA *2 + 0x400}
#ROM 0x1A = {0x1A *2 + 0x400}
#ROM 0x22 = {0x22 *2 + 0x400}
#ROM 0x24 = {0x24 *2 + 0x400}
#ROM 0x4A = {0x4A *2 + 0x400}
#ROM 0x4C = {0x4C *2 + 0x400}
#ROM 0x96 = {0x96 *2 + 0x400}
#ROM 0x2A = {0x2A *2 + 0x400}
#ROM 0x2C = {0x2C *2 + 0x400}
#ROM 0x98 = {0x98 *2 + 0x400}
#ROM 0x50 = {0x50 *2 + 0x400}
#ROM 0x52 = {0x52 *2 + 0x400}
#ROM 0xB6 = {0xB6 *2 + 0x400}
#ROM 0xB8 = {0xB8 *2 + 0x400}
#ROM 0xBA = {0xBA *2 + 0x400}
#ROM 0xC2 = {0xC2 *2 + 0x400}
#ROM 0xC4 = {0xC4 *2 + 0x400}
#ROM 0xC6 = {0xC6 *2 + 0x400}

#ORG 0x0CF,0x01FF {}


#include <Main.h>

#include "Display_Steuerung.h"
#include "Display_Steuerung.c"
#include "Steuerung.h"
#include "Steuerung.c"
#include "SPI_EEPROM.h"
#include "SPI_EEPROM.c"
#include "Zeichensatz.h"
#include "Zeichensatz.c"
#include "IIC.h"
#include "IIC.c"
#include "Testprogramm.h"
#include "Testprogramm.c"
#include "Interrupts.h"
#include "Interrupts.c"

//#build (reset=0x0E000)

#ORG 0x0800,0x0D7FF
void main()
   {
   CLKDIV = 0x0000;


Last edited by richi-d on Thu Mar 15, 2012 4:46 am; edited 1 time in total
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Thu Mar 15, 2012 4:45 am     Reply with quote

I found out: short after I enable the interrupt, the program jumps to 0x00000
jeremiah



Joined: 20 Jul 2010
Posts: 1317

View user's profile Send private message

PostPosted: Thu Mar 15, 2012 6:19 am     Reply with quote

You're #ROM mapping is off.

Look at Timer1. It is normally at 0x1A right? Well, the start of the IVT is at 0x0004., so it is at offset 0x001A-0x0004 = 0x0016

So you should be doing lines like:

#ROM 0x002E = {(0x002E-0x0004)*2+0x0400}
AND
#ROM 0x001A = {(0x001A-0x0004)*2+0x0400}


EDIT: That said, you're application shouldn't need to do the #ROM parts. Your HOPE is that the bootloader did that already for you so all you would need in your application is #BUILD(interrupt=0x0400) and the compiler would do the rest. The #ROM statements will only work for your application if code protect is not enabled. If it is enable, the bootloader has to be the one providing that functionality.
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Thu Mar 15, 2012 7:53 am     Reply with quote

Hello,

we are done now. All is working. The bootloader cannot write the IVT because there is an error in the REV01 of the PIC Controller. REV03 was working fine. But now we had to make this work to be compatibel to all our PIC´s...
This f*** Pic error cost me 1 week! But now it seems o.k.

Here ist the code now:

Code:
#include <24FJ192GA108.h>
#device adc=10
#device *=16

#BUILD (interrupt=0x408)  //In diesem Bereich sind jetzt die Pointer für die Interrupts

//IVT Mapping to application code space

#ROM 0x04 = {0x04 *2 + 0x0400}
#ROM 0x05 = {0x00}
#ROM 0x06 = {0x06 *2 + 0x0400}
#ROM 0x07 = {0x00}
#ROM 0x08 = {0x08 *2 + 0x0400}
#ROM 0x09 = {0x00}
#ROM 0x0A = {0x0A *2 + 0x0400}
#ROM 0x0B = {0x00}
#ROM 0x0C = {0x0C *2 + 0x0400}
#ROM 0x0D = {0x00}
#ROM 0x0E = {0x0E *2 + 0x0400}
#ROM 0x0F = {0x00}
#ROM 0x10 = {0x10 *2 + 0x0400}
#ROM 0x11 = {0x00}
#ROM 0x12 = {0x12 *2 + 0x0400}
#ROM 0x13 = {0x00}
#ROM 0x2E = {0x2E *2 + 0x0400}
#ROM 0x2F = {0x00}
#ROM 0x38 = {0x38 *2 + 0x0400}
#ROM 0x39 = {0x00}
#ROM 0x9A = {0x9A *2 + 0x0400}
#ROM 0x9B = {0x00}
#ROM 0xAE = {0xAE *2 + 0x0400}
#ROM 0xAF = {0x00}
#ROM 0x14 = {0x14 *2 + 0x0400}
#ROM 0x15 = {0x00}
#ROM 0x3C = {0x3C *2 + 0x0400}
#ROM 0x3D = {0x00}
#ROM 0x4E = {0x4E *2 + 0x0400}
#ROM 0x4F = {0x00}
#ROM 0x7E = {0x7E *2 + 0x0400}
#ROM 0x7F = {0x00}
#ROM 0x80 = {0x80 *2 + 0x0400}
#ROM 0x81 = {0x00}
#ROM 0x36 = {0x36 *2 + 0x0400}
#ROM 0x37 = {0x00}
#ROM 0x34 = {0x34 *2 + 0x0400}
#ROM 0x35 = {0x00}
#ROM 0x78 = {0x78 *2 + 0x0400}
#ROM 0x79 = {0x00}
#ROM 0x76 = {0x76 *2 + 0x0400}
#ROM 0x77 = {0x00}
#ROM 0xBE = {0xBE *2 + 0x0400}
#ROM 0xBF = {0x00}
#ROM 0xBC = {0xBC *2 + 0x0400}
#ROM 0xBD = {0x00}
#ROM 0x16 = {0x16 *2 + 0x0400}
#ROM 0x17 = {0x00}
#ROM 0x1E = {0x1E *2 + 0x0400}
#ROM 0x1F = {0x00}
#ROM 0x5E = {0x5E *2 + 0x0400}
#ROM 0x5F = {0x00}
#ROM 0x60 = {0x60 *2 + 0x0400}
#ROM 0x61 = {0x00}
#ROM 0x62 = {0x62 *2 + 0x0400}
#ROM 0x63 = {0x00}
#ROM 0x64 = {0x64 *2 + 0x0400}
#ROM 0x65 = {0x00}
#ROM 0x40 = {0x40 *2 + 0x0400}
#ROM 0x41 = {0x00}
#ROM 0x42 = {0x42 *2 + 0x0400}
#ROM 0x43 = {0x00}
#ROM 0xCE = {0xCE *2 + 0x0400}
#ROM 0xCF = {0x00}
#ROM 0x3A = {0x3A *2 + 0x0400}
#ROM 0x3B = {0x00}
#ROM 0xA4 = {0xA4 *2 + 0x0400}
#ROM 0xA5 = {0x00}
#ROM 0x18 = {0x18 *2 + 0x0400}
#ROM 0x19 = {0x00}
#ROM 0x20 = {0x20 *2 + 0x0400}
#ROM 0x21 = {0x00}
#ROM 0x46 = {0x46 *2 + 0x0400}
#ROM 0x47 = {0x00}
#ROM 0x48 = {0x48 *2 + 0x0400}
#ROM 0x49 = {0x00}
#ROM 0x66 = {0x66 *2 + 0x0400}
#ROM 0x67 = {0x00}
#ROM 0x68 = {0x68 *2 + 0x0400}
#ROM 0x69 = {0x00}
#ROM 0x6A = {0x6A *2 + 0x0400}
#ROM 0x6B = {0x00}
#ROM 0x6C = {0x6C *2 + 0x0400}
#ROM 0x6D = {0x00}
#ROM 0xCC = {0xCC *2 + 0x0400}
#ROM 0xCD = {0x00}
#ROM 0x6E = {0x6E *2 + 0x0400}
#ROM 0x6F = {0x00}
#ROM 0x90 = {0x90 *2 + 0x0400}
#ROM 0x91 = {0x00}
#ROM 0x26 = {0x26 *2 + 0x0400}
#ROM 0x27 = {0x00}
#ROM 0x28 = {0x28 *2 + 0x0400}
#ROM 0x29 = {0x00}
#ROM 0x54 = {0x54 *2 + 0x0400}
#ROM 0x55 = {0x00}
#ROM 0x56 = {0x56 *2 + 0x0400}
#ROM 0x57 = {0x00}
#ROM 0xC8 = {0xC8 *2 + 0x0400}
#ROM 0xC9 = {0x00}
#ROM 0xCA = {0xCA *2 + 0x0400}
#ROM 0xCB = {0x00}
#ROM 0x1A = {0x1A *2 + 0x0400}
#ROM 0x1B = {0x00}
#ROM 0x22 = {0x22 *2 + 0x0400}
#ROM 0x23 = {0x00}
#ROM 0x24 = {0x24 *2 + 0x0400}
#ROM 0x25 = {0x00}
#ROM 0x4A = {0x4A *2 + 0x0400}
#ROM 0x4B = {0x00}
#ROM 0x4C = {0x4C *2 + 0x0400}
#ROM 0x4D = {0x00}
#ROM 0x96 = {0x96 *2 + 0x0400}
#ROM 0x97 = {0x00}
#ROM 0x2A = {0x2A *2 + 0x0400}
#ROM 0x2B = {0x00}
#ROM 0x2C = {0x2C *2 + 0x0400}
#ROM 0x2D = {0x00}
#ROM 0x98 = {0x98 *2 + 0x0400}
#ROM 0x99 = {0x00}
#ROM 0x50 = {0x50 *2 + 0x0400}
#ROM 0x51 = {0x00}
#ROM 0x52 = {0x52 *2 + 0x0400}
#ROM 0x53 = {0x00}
#ROM 0xB6 = {0xB6 *2 + 0x0400}
#ROM 0xB7 = {0x00}
#ROM 0xB8 = {0xB8 *2 + 0x0400}
#ROM 0xB9 = {0x00}
#ROM 0xBA = {0xBA *2 + 0x0400}
#ROM 0xBB = {0x00}
#ROM 0xC2 = {0xC2 *2 + 0x0400}
#ROM 0xC3 = {0x00}
#ROM 0xC4 = {0xC4 *2 + 0x0400}
#ROM 0xC5 = {0x00}
#ROM 0xC6 = {0xC6 *2 + 0x0400}
#ROM 0xC7 = {0x00}

#ORG 0x0D0,0x01FF {}   //Hier sind die Hardware IVT´s darf nicht überschrieben werden.


#include <Main.h>

#include "Display_Steuerung.h"
#include "Display_Steuerung.c"
#include "Steuerung.h"
#include "Steuerung.c"
#include "SPI_EEPROM.h"
#include "SPI_EEPROM.c"
#include "Zeichensatz.h"
#include "Zeichensatz.c"
#include "IIC.h"
#include "IIC.c"
#include "Testprogramm.h"
#include "Testprogramm.c"
#include "Interrupts.h"
#include "Interrupts.c"

#build (reset=0x800)   //Bleibt fix- nicht ändern wg. Bootloader Einsprung, Löschen für Standalone Programm

#ORG 0x0804,0x0B000    //Erweitern wen ROM FEHLER!!!
void main()
   {
jeremiah



Joined: 20 Jul 2010
Posts: 1317

View user's profile Send private message

PostPosted: Thu Mar 15, 2012 12:22 pm     Reply with quote

If it helps, I don't think you have to put the odd number addresses in there as they will already be zero from the default programming of the PIC.

You can also get all fancy and use a macro:

Code:

#DEFINE REMAP_IVT(entry) #ROM entry={entry*2 + 0x400}
 


And then below it do the mapping like this:
Code:

REMAP_IVT(0x0004)  //OSC FAIL
REMAP_IVT(0x0006)
REMAP_IVT(0x0008)


Makes for a more readable code, and if you ever need to change the algorithm, you just have to do it where the macro is defined.
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Fri Mar 16, 2012 4:16 am     Reply with quote

Hello Thank you,

I did that because in the programm memory was always for example 0xFF491 ...

But your solution looks better.
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Wed Mar 21, 2012 3:56 am     Reply with quote

Hi,

I tested your code, but in the program memory I found:

3 00004 FF0408 nopr
4 00006 FF040C nopr
.
.
.
.

So I need to overwrite the uneven adresses with 0x00. Else it doesn´t work. Thats strange...
jeremiah



Joined: 20 Jul 2010
Posts: 1317

View user's profile Send private message

PostPosted: Wed Mar 21, 2012 7:18 am     Reply with quote

That's interesting. In mine the code:
Code:

//Just for convenience
#DEFINE BL_IVT_START  0x0004
#DEFINE APP_RESET_LOC PM_PAGE_SIZE
#DEFINE APP_IVT_START (APP_RESET_LOC+4)

//App IVT entries are spaced twice as far apart as Bootloader IVT entries
//due to using GOTO commands (4 WORDs) instead of just addresses (2 WORDs)
#define REMAP_IVT(entry) #ROM entry = {(entry-BL_IVT_START)*2+APP_IVT_START}

//Remap the IVT using the APP IVT location to keep the compiler from
//not wanting to let you remap the IVT here.  This doesn't generate any code,
//but lets the #ROM and #ORG statements work
#BUILD (interrupt=APP_IVT_START)  //must do this to remap IVT table

//IVT Mapping to application code space
REMAP_IVT(0x0004)
REMAP_IVT(0x0006)
REMAP_IVT(0x0008)
REMAP_IVT(0x000A)
REMAP_IVT(0x000C)
REMAP_IVT(0x000E)
REMAP_IVT(0x0010)
REMAP_IVT(0x0012)
REMAP_IVT(0x0014)
REMAP_IVT(0x0016)
REMAP_IVT(0x0018)
REMAP_IVT(0x001A)  //TIMER1
REMAP_IVT(0x001C)
REMAP_IVT(0x001E)


Generates the following hex:
Code:

:1000080004040000080400000C04000010040000B0
:1000180014040000180400001C0400002004000060
:1000280024040000280400002C0400003004000010
:0800380034040000380400004C


I'm using the 4.130 revision of the compiler

EDIT: Try changing your macro to the following:
Code:

#DEFINE REMAP_IVT(entry)         \
   #ROM entry={entry*2 + 0x400}  \
   #ROM entry+1={0x0000}
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Wed Mar 21, 2012 7:55 am     Reply with quote

Hello,

thanks yes this works. Now I have another problem: I want to make another application with the same code and same controller. I tried, but it doesn´t run. Now I found out that the compiller put some Subroutines to this adresses:

Code:

 Line  Address  Opcode  Label                Disassembly             

    60  00076   0004EC         nop                                   
    61  00078   0004F0         nop                                   
    62  0007A   FFFFFF         nopr                                   
    63  0007C   FFFFFF         nopr                                   
    64  0007E   0004FC         nop                                   
    65  00080   000500         nop                                   
    66  00082   A80216 StartI2C2 bset.b 0x0216,#0                       
    67  00084   AF0216         btsc.b 0x0216,#0                       
    68  00086   37FFFE         bra 0x000084                           
    69  00088   060000         return                                 
    70  0008A   FFFFFF         nopr                                   
    71  0008C   FFFFFF         nopr                                   
    72  0008E   FFFFFF         nopr                                   
    73  00090   000520         nop                                   
    74  00092   FFFFFF         nopr                                   
    75  00094   FFFFFF         nopr                                   
    76  00096   00052C         nop                                   
    77  00098   000530         nop                                   
    78  0009A   000534         nop                                   
    79  0009C   EB4000 DataRdyI2C2 clr.b w0                               
    80  0009E   AF2218         btsc.b 0x0218,#1                       
    81  000A0   E80000         inc.w w0,w0                           
    82  000A2   060000         return                                 
    83  000A4   000548         nop                                   
    84  000A6   A84216 StopI2C2 bset.b 0x0216,#2                       
    85  000A8   AF4216         btsc.b 0x0216,#2                       
    86  000AA   37FFFE         bra 0x0000a8                           
    87  000AC   060000         return                                 
    88  000AE   00055C         nop                                   
    89  000B0   FFFFFF         nopr                                   
    90  000B2   FFFFFF         nopr                                   
    91  000B4   FFFFFF         nopr                                   
    92  000B6   00056C         nop                                   
    93  000B8   000570         nop                                   
    94  000BA   000574         nop                                   
    95  000BC   000578         nop                                   
    96  000BE   00057C         nop                                   
    97  000C0   FFFFFF         nopr                                   
    98  000C2   000584         nop                                   
    99  000C4   000588         nop                                   
   100  000C6   00058C         nop


How can this be? In the other application This space is only with my defined #ROM s
jeremiah



Joined: 20 Jul 2010
Posts: 1317

View user's profile Send private message

PostPosted: Wed Mar 21, 2012 4:22 pm     Reply with quote

This kind of goes back to what I was talking about a couple weeks ago in this thead.

Are those #ROM's in the application code or the bootloader?

Normally you put them in the bootloader (I realize you have a precompiled bootloader probably from what you said in earlier posts). Then in the application you only would have to put:


Code:

#define APPLICATION_RESET_VECTOR 0x0400  //make this whatever your bootloader expects the application code to start at
#define APPLICATION_REMAPPED_IVT  0x0408  //I think this is the value you used earlier???
#build (reset=APPLICATION_RESET_VECTOR)
#build (interrupt=APPLICATION_REMAPPED_IVT)
#org 0x0000,APPLICATION_RESET_VECTOR {}


That last line is the key to keeping your application code out of interrupt vector table you remapped.

Since I think you already have the #ROM's in the application code, the main thing is to use #org statement like that last line to keep application code from getting in there. The "{}" at the end says "don't let the compiler put anything here". Mind you if you are using the #ROM's, you can't do the #ORG over the whole range, but do multiple #ORG statements to block out the empty spaces.

I know that sounds complicated, so do you mind if I ask you to post something? Could you post up (using the code tags) the bootloader hex lines for addresses 0x0000 to 0x01FF? I want to see how the reset vector and bootloader IVT look like. I don't need to see any of the code lines, just those. It would help with me formulating something more simple for you.

As an example, this is what I am looking for:
Code:

:080000006CA9040002000000DD
:1000080004040000080400000C04000010040000B0
:1000180014040000180400001C0400002004000060
:1000280024040000280400002C0400003004000010
:0800380034040000380400004C


If the bootloader doesn't write to some of the lines, just include what it does. Your's will probably all lines of length 0x10. My first line is 0x08 because of how I wrote my bootloader code, and the last line is just where I stopped remapping, so it is short.
richi-d



Joined: 28 Aug 2007
Posts: 106

View user's profile Send private message

PostPosted: Thu Mar 22, 2012 1:54 am     Reply with quote

Hello Jeremiah,

it has nothing to do now with the bootloader, I just filled in the 'Roms in my application code and it is not running anymore... without bootloader!

#ORG 0x0000,0x0400 {} is not accepted, I get the error message: Invalid ORG range. I have: #ORG 0x00D0,0x0400 {}
This is the last space from the hardware IVT to the end of the first page (which cannot be writen because of the Codeprotect error in the REV01)

The //#build (reset=0x800) is outcommented because without bootloader I need 0x0000 as start adress.


Here is what I put in my code:
Code:


#include <24FJ128GA106.h>
#device adc=10
#device *=16

#BUILD (interrupt=0x408)  //In diesem Bereich sind jetzt die Pointer für die Interrupts

#include <Main.h>

//IVT Mapping to application code space

REMAP_IVT(0x0004)
REMAP_IVT(0x0006)
REMAP_IVT(0x0008)
REMAP_IVT(0x000A)
REMAP_IVT(0x000C)
REMAP_IVT(0x000E)
.
.
.
REMAP_IVT(0x00C2)
REMAP_IVT(0x00C4)
REMAP_IVT(0x00C6)

#ORG 0x0D0,0x0400 {}   //Hier sind die Hardware IVT´s darf nicht überschrieben werden.

#include "string.h"
#include "SPI_EEPROM.h"
#include "SPI_EEPROM.c"
#include "Steuerung.h"
#include "Steuerung.c"
#include "Display_Steuerung.h"
#include "Display_Steuerung.c"
#include "Save_Restore.h"
#include "Save_Restore.c"
#include "I2C.c"
#include "Steuerung_Sensor.h"
#include "Steuerung_Sensor.c"
#include "Interrupts.h"
#include "Interrupts.c"
#include "Init.h"
#include "Init.c"


//#build (reset=0x800)   //Bleibt fix- nicht ändern wg. Bootloader Einsprung, Löschen für Standalone Programm

#ORG 0x0804,0x0B000    //Erweitern wenn ROM FEHLER!!!
void main()
   {
   CLKDIV = 0x0000;
jeremiah



Joined: 20 Jul 2010
Posts: 1317

View user's profile Send private message

PostPosted: Thu Mar 22, 2012 6:01 am     Reply with quote

Yeah, 0x0000,0x0400{} won't work when there are ROM statements. Did the #ORG 0x00D0,0x400{} work?

Just a quick comment:

1. #ORG statements tend to end in odd address, so I would use 0x00D0,0x03FF instead. 0x400 should be ok to use with Code protect on. It is the start of the next page.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3  Next
Page 2 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group