Is there a way to know if we are in critical region? ie: between sd_nvic_critical_region_enter(&foo) and sd_nvic_critical_region_exit(0) without explicitly using a global variable to memorize the state
Is there a way to know if we are in critical region? ie: between sd_nvic_critical_region_enter(&foo) and sd_nvic_critical_region_exit(0) without explicitly using a global variable to memorize the state
Let us say that your app is using TIMER1 and has enabled its interrupt. Then you can check if this interrupt is temporarily disabled when inside the critical region.
if(NVIC->ISER[0] & ((1 << (uint32_t)TIMER1_IRQn)))
{
// interrupt is still enabled so NOT inside critical section
}
else
{
// inside the critical section
}
The basic idea is to see if any interrupt enabled by the app is temporarily disabled between sd_nvic_critical_region_enter
and sd_nvic_critical_region_exit