For example, I have the following code:
bool interruptFlag;
void interruptHanler(void)
{
interruptFlag = true;
}
void main(void)
{
while (true)
{
if (interruptFlag)
{ interruptFlag = false;
processThings(); // process heavier things here
}
// CRITICAL POINT: what if interrupt occurs here?
sd_app_evt_wait();
}
}
What if the interrupt occurs after checking the flag, but just before entering sd_app_evt_wait()? Does the sd_app_evt_wait() then just block and the system eventually jams to wait for the next possible interrupt?
The question: If the above speculation is true, can I somehow disable interrupts in-between checking my software flag and entering the sd_app_evt_wait()? The code could then look something like:
sd_nvic_critical_region_enter(...);
while (interruptFlag) // loop again if interrupt occurs while processing previous
{ sd_nvic_critical_region_exit(...);
interruptFlag = false;
processThings();
sd_nvic_critical_region_enter(...);
}
// Now we are inside critical region thus application interrupt cannot occur here.
sd_app_evt_wait(); // does this enable application interrupts automatically?
So, can I enter sd_app_evt_wait() while inside critical region?