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

Issue with blocking wait using app_timer

Hello everyone, I am trying to implement a blocking wait using the app_timer.

To do this, I am starting a one-shot timer whose callback function sets an initially false flag to true.

I tried to "block" using the following code:

while (!flag)
{
    sd_app_evt_wait();
}

However, when I use the debugger, it appears that the timer handler is never called.

When I remove the while statement and only use sd_app_evt_wait(), the timer handler is called.

What could cause this? Is there another recommended way to implement an accurate blocking wait?

  • well you've given no context as to where you're calling this code from. If you're calling it from another timer handler or an IRQ handler with higher priority you're blocking your own interrupts and so you'll never get the callback. 99% that's what you're doing. 

    The recommended way to implement an accurate blocking wait is not to. Blocking waits waste power and, as you're finding out, can cause you to deadlock yourself or block other events which need processing. Make your code asynchronous, implement state machines and get away from blocking anything. 

  • Hi RK, thank you for your answer.

    It seems that there was indeed an issue with priority. The timer handler was not executed until my application code returned.

    The "Application Timer" documentation also discusses priority.

    Instead, I used an RTC directly, whose handler was not blocked.

Related