Hello Roberto,
Even though automatic vector redirection is available for the 'QE64, it cannot be used whenever the bootloader itself requires interrupt usage. Therefore the bootloader will need to implement vector redirection from the normal vector range. I would suggest the following criteria for this process.
- Bootloader ISR code and user program ISR code should be kept entirely independent, even if functionally similar. Any global variables needed in each case should also be kept entirely separate.
- The user code should not require "special" ISR functions, and should operate correctly if directly loaded using BDM, without the presence of the bootloader code. In this case, the user vector table would be situated within the normal range.
- During programming by the bootloader, the bootloader would shift the vector table for the user code to a position within the user flash space, usually immediately below the bootloader code (similar to automatic redirection).
A small function within the bootloader would be required for every interrupt vector available within the MCU. For the interrupts that are applicable to both the bootloader and the user program, the function would need to ascertain whether bootloader mode was current or not, and direct execution to the appropriate ISR function within the bootloader or user code. For the other interrupts applicable to only the user code, the function would always redirect execution to the address contained within the specific entry of the shifted user vector table.
For HCS08 devices, the redirection process is complicated by the fact that the H-register is not automatically saved to the stack when an interrupt occurs. Therefore, the redirection process must not corrupt the H-register value, and when the true ISR function commences, the stack pointer must be identical to when the redirection function was first entered (since the true ISR function will terminate with a RTI instruction). It is not possible to achieve this with a conventional indexed jump, but is possible with a bit of stack manipulation.
The attached code snippet I hope will demonstrate the suggested process a little more clearly.
Regards,
Mac