Question

My bootloader needs to use the interrupt vector, but so is my application program. The high vector starts at address 0x08 and the low vector starts at address 0x18.

How can I share interrupt vectors so that I have a separate interrupt function in the bootloader and in the downloaded application? I am using PIC18F87J11 and MPLAB XC8 compiler.

Was it helpful?

Solution

I have faced similar problems at my work.

On the STM32, you could just change the location of the vector table at runtime, so that was great.

On the PIC18, I simply chose not to use interrupts in the bootloader, so the interrupt vectors at 0x08 and 0x18 can unconditionally redirect to the equivalent locations in the application section using a GOTO instruction. Are you sure you need to use interrupts in the bootloader?

If you really need interrupts, I think you need to have some clever way to tell at runtime whether the application is running or the bootloader is running so you can redirect to the right place. For simplicity, you want to be able to test for this without affecting the STATUS register or any other part of RAM.

I suggest reserving a special byte of RAM, perhaps the top byte of the access bank. XC8 lets you position a variable absolutely, so (if it isn't buggy) you could do that:

unsigned char inBootloader @ 0x5F;

Unfortunately, every application loaded by this bootloader must be aware of this convention and define this same variable in the same spot. Or they should at least avoid writing to that spot in memory and let the bootloader code maintain the state of the variable.

Then in your interrupt vectors at 0x08 and 0x18 put some simple logic to redirect to the right place:

btfss inBootloader, 0
goto 0x4008   ; go to application high vector
goto bootloaderHighIsr
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top