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

Is critical section needed for glitch-less implementation of CPU sleep?

Hello,

I have the same question as mentioned in this article:

https://devzone.nordicsemi.com/f/nordic-q-a/19252/how-to-avoid-interrupt-handling-is-not-missed-with-sd_app_evt_wait

Additional question, just to make sure: For a glitch-free implementation,  do I need the second code part including the "sd_nvic_critical_region_enter(...);"?

Or does it also work (glitch free) with the first implementation without the critical section? I just want to make sure, if I am missing something. In my opinion, I need the critical section absolutely.

Thank you,
Regards

Parents
  • Hello,

    Would it be possible to include some snippets of your code here? I'm not sure I understand what you're trying to achieve in your code. E.g., Is it some code you have that has to be processed without interruption from other higher priority interrupts? Is it timing critical and/or exposed to race conditions from other application-level interrupts? Are you using a scheduler? 

    Thanks,

    Vidar

  • The creator of the above mentioned article showed an example code which fits exactly my needs to show an example. The creator showed a first and a second implementation of the code. Do you know what I mean, or should I copy the code in here?

  • I saw the ticket you linked to, but I wasn't sure what you meant by glitch-free in this context and suspected that maybe you had some other concerns than what the OP had. So to answer your question: critical regions should be redundant for this case. As pointed by the accepted answer, the event register will be set after the ISR is serviced so sd_app_evt_wait() will return immediately and reread the flag. You are thus eliminating the possibility of a race condition. 

Reply
  • I saw the ticket you linked to, but I wasn't sure what you meant by glitch-free in this context and suspected that maybe you had some other concerns than what the OP had. So to answer your question: critical regions should be redundant for this case. As pointed by the accepted answer, the event register will be set after the ISR is serviced so sd_app_evt_wait() will return immediately and reread the flag. You are thus eliminating the possibility of a race condition. 

Children
Related