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

interrupts and critical section

Is it possible for gpiote_event_handler interrupt to get executed while the program is executing code inside timer_event_handler?

These events modify same variables so to be safe I put CRITICAL_REGION_ENTER/EXIT in both of them but is that necessary?

  • Yes its possible if the gpiote interrupt has higher priority than the timer event handler. And vice-versa if the timer interrupt has higher priority than the gpiote one the timer could interrupt the gpiote. If they have the same priority however then no, one will not interrupt the other.

    In general having a critical region around code like that is a good idea as long as it's not causing you performance issues because as code develops and changes over time it's very easy to change an interrupt priority without remembering that you are relying on them being the same for your mutex.

Related