I am back again trying to make a bootloader. I still have problems with interrupt vector. This is the way I am doing it:
This is the bootloader ISR vector (not relocated).
void (* near const _vect[])() @0xFFC0 = {
Bootload_ISR_00,
Bootload_ISR_01,
Bootload_ISR_02,
Bootload_ISR_03,
Bootload_ISR_04,
Bootload_ISR_05,
Bootload_ISR_06,
Bootload_ISR_07,
Bootload_ISR_08,
Bootload_ISR_09,
Bootload_ISR_10,
Bootload_ISR_11,
Bootload_ISR_12,
Bootload_ISR_13,
Bootload_ISR_14,
Bootload_ISR_15,
Bootload_ISR_16,
Bootload_ISR_17,
Bootload_ISR_18,
Bootload_ISR_19,
Bootload_ISR_20,
Bootload_ISR_21,
Bootload_ISR_22,
Bootload_ISR_23,
Bootload_ISR_24,
Bootload_ISR_25,
Bootload_ISR_26,
Bootload_ISR_27,
Bootload_ISR_28,
Bootload_ISR_29,
Bootload_ISR_30
};
void (* near const _vectReset[])() @0xFFFE = {
_BootEntryPoint
};
This is how every Bootload_ISR_## function looks like(If it is signal to run loader, it runs loader ISR, if not it executes the ISR from the application
ISR(Bootload_ISR_03)
{
dword ID;
byte type, len,format;
byte buff[8];
int i;
if(RunFromLoader){
CAN1_ReadFrame(&ID,&type,&format,&len,buff);
for(i = 0; i < 8 ; i++){
CanMessage[i] =buff[i];
}
MssgReceived = TRUE;
CANRFLG = CANRFLG_RXF_MASK;
}
else{
asm {
LDX $1907
PSHX
LDX $1906
PSHX
RTS
}
}
}
Now, in the part of the application code I am also NOT relocating the Interrupt Vector as I want my bootloader to ALWAYS decide wich routine to execute in order to serve an interrupt (application or loader). I am only defining a vector in address 0x1900 which looks like the following ( that is the reason the values above are $1905 and $1906 for ISR 03):
void (* near const _vect[])() @0x1900 = { /* Interrupt vector table */
Cpu_Interrupt,
Cpu_Interrupt,
CAN1_InterruptTx,
CAN1_InterruptRx,
CAN1_InterruptError,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
SM1_Interrupt,
Buzzer_Interrupt,
Cpu_Interrupt,
TmDt1_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
Cpu_Interrupt,
_EntryPoint
};
The bootloader decides whether to run the loader or the application using the following:
if(RunFromLoader)
__asm jmp _BootStartup ;
else
__asm jmp 0x1941 ;
My application Interrupt Vector must end at 193F, and that is why I am jumping directly to 0x1941.
I have a couple of problems I have detected:
1.- When I add this code to my loader ISR 03 which corresponds to Receive CAN interrupt the loader failes as the first interrrupt arrives, even if that code is never executed. Its like if the addition of those 5 instructions exceeded the time or the code allowed for an interrupt. (Sounds wierd but it is what it looks like).
2.-Sometimes inverting the order of the ISR 03, for example :
ISR(Bootload_ISR_03){ if(!RunFromLoader){ asm { LDX $1907 PSHX LDX $1906 PSHX RTS } } else{ CAN1_ReadFrame(&ID,&type,&format,&len,buff); for(i = 0; i < 8 ; i++){ CanMessage[i] =buff[i]; } MssgReceived = TRUE; CANRFLG = CANRFLG_RXF_MASK; }}
instead of what I posted at the beggining ( ! RunFromLoader ) and the if and else inverted. When I do that the loader works ( I dont whant to leave it like that because it seems like any small change in the code would make the loader fail) but the application still doesnt work even if the program is completely flash as the S19 file is. I believe the problem are the ISRs but I am speculating since I have no means of debugging because I can only debugg the bootloader which is not running anymore once the application is flashed.
Application is not the problem because when I flash the application directly using BDM programmer it runs without any problem (I just have to place the vector at 0xFFC0 instead of 0x1900).
I am running out of ideas, does anyone knows something that I am not considering?, I will wait for any ideas.
This is the prm I am using for application and loader}:
LOADERSECTIONS ROM = READ_ONLY 0xEE00 TO 0xFFFF; APPLICATION = READ_ONLY 0x1900 TO 0xEDFD; EEPROM = READ_ONLY 0x1400 TO 0x17FF; RAM = READ_WRITE 0x00A0 TO 0x107F; Z_RAM = READ_WRITE 0x0080 TO 0x009F; ENDAPPLICATIONSECTIONS Z_RAM = READ_WRITE 0x0080 TO 0x009F; RAM = READ_WRITE 0x00A0 TO 0x107F; ROM = READ_ONLY 0x1940 TO 0xEDFD; EEPROM = READ_ONLY 0x1400 TO 0x17FF;END
Regards,