This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

detect if in critical region

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

Parents
  • 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

Reply
  • 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

Children
No Data
Related