In the Cortex M3 core, I am trying to have 2 interrupts with different priority.
I want the higher priority interrupt interrupting the lower priority interrupt.
One, the higher priority, supposes to increment counter, "volatile Uint32 mSecCounter", and I put it into SysTick interrupt which has priority 0 by default.
// The 1 millisecond tick timer, SysTick has priority 0
void SysTickIntHandler( void ) //when servicing lower priority interrupt, program does not stop there and not incrementing counter
{
mSecCounter++;// This simply increments and wraps, when it's used, the user zeroes the count beforehand
}
The second interrupt is Timer0 interrupt, it is a service interrupt, it can call a function which checks increment of mSecCounter and waits until it reaches certain value, like:
//inside one of the functions called from the lower priority interrupt:
mSecCounter=0;//reset counter
do {
//wait and do something, <<<<< program stack there, because counter is not incrementing in another interrupt
} while (mSecCounter<100);//until 100 ms passed
I tried to assign to it priority 2, so this timer interrupt and the function which checks counter, supposed to be interrupted by priority 0 interrupt (which increments counter).
I believe the following functions have a bug:
int i = IntPriorityGet(INT_TIMER0A); // default priority of TIMER0A = 0, register NVIC_PRI8
IntPrioritySet(INT_TIMER0A, (char)(i+1)<<5); //priority TIMER0A set to 1 (upper 3 bits of a byte)
i = IntPriorityGet(INT_TIMER0A); // read back priority of INT_TIMER0A = 32 (or 1 in upper 3 bits)
//IntPrioritySet(INT_TIMER0A, changes NVIC_PRI4 to 0x20000000 (WRONG NVIC_PRI4, IRQ16 to 19, should be NVIC_PRI8, IRQ32 to 35)
I checked with emulator, and the call IntPrioritySet(INT_TIMER0A, (char)(i+1)<<5); changes register NVIC_PRI3 to 0x20000000 , not register NVIC_PRI8 according to TRM.
Besides, even if I pause execution and manually change NVIC_PRI8 register to 0x20000000, I still see the program is stack inside the second interrupt with supposed to be lower priority (=1), in the function which was called from it, waiting for counter to increment. The higher priority(=0) SysTick interrupt is not called, counter is not incrementing.
If this waiting for counter function is NOT called from the second interrupt, the first interrupt IS working and incrementing counter.
Either there is a bug in IntPrioritySet(), or I do something incorrectly, or both.
Should the interrupts be re-enabled inside lower priority interrupt?
Any more detailed examples on interrupt priorities?
Thanks, Igor