Hello AjRj14,
Yes, the bootloader may use interrupts. The bootloader owns and protects the default vector table area in the flash.
In fact, the bootloader already uses for example SCI module in interrupt mode for serial communication.
What you need to do:
- You need to create and call timer init function
- You need to create interrupt service routine (ISR) for this timer
- (You need to check whether the bootloader with these modifications still may fit into the allocated Flash/RAM area. If not, give more space for bootloader (check map file – potentially edit prm linker file).)
In the case of S12Z, you may choose between several types of periodic interrupts:
- Real time interrupt (RTI),
- Autonomous periodic interrupt (API) or
- Timer (TIM) Output Compare mode.
The code for it is pretty simple in all three cases. It depends on your preference. Few write into registers and flag clearing in an interrupt routine. Only in the case of TIM, you need to also additionally update the TCx value in each ISR.
For example API:
//==============================================================================
// API_Init
//==============================================================================
void API_Init(void)
{
CPMUAPIR = 30D3; //1ms interval @25Mhz bus clock
CPMUAPICTL = 0x89; //bus clk is source of clock, API enable,
//interrupt disable, clear flag if set
CPMUAPICTL_APIFE = 1; //API enable
}
//==============================================================================// API_ISR//==============================================================================
interrupt VectorNumber_Vapi void API_ISR(void)
{
//your code
CPMUAPICTL = CPMUAPICTL_APIF_MASK; //clear APIF flag
}
Note: the vector number (e.g. VectorNumber_Vapi) may by found in your derivative header file - right on begining.
Note: If you use bootloader in self-rewritable mode, you need to relocate interrupt routine into RAM and set appropriate interrupt vector in RAM - follow the SCI example in AN12086 code.
I hope it helps you.
Best regards
RadekS