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

app_timer.c - why clear timer

On line 301 of app_timer.c there is the following code:

    // No more timers in the list. Reset RTC1 in case Start timer operations are present in the queue.
    if (mp_timer_id_head == NULL)
    {
        NRF_RTC1->TASKS_CLEAR = 1;
        m_ticks_latest        = 0;
        m_rtc1_reset          = true;
    }

Why do you have to clear the timer to zero when there are no more running timers and start timer operations are present in the queue? What is it good for?

In my use I have only single shot timers that run and when they expire in the callback I setup a new timer. This is exactly that situation -> no running timers but new timer present in the queue.

I wish to use app_timer_cnt_get to get the lapsed time but it is impossible when you clear the timer with NRF_RTC1->TASKS_CLEAR = 1;.

As I see it you should never clear NRF_RTC1->TASKS_CLEAR = 1; because it makes app_timer_cnt_get unusable.

What do you think?

EDIT: If you remove the aforementioned code then you can also remove m_rtc1_reset because it is not used anywhere else.

Parents
  • I also came across this. I am using Eddystone library in sdk 14, and this causes that sometimes when i am using app_timer in my own application, the EID and uptime counters make a few hundred second jump, which is kinda bad because the EID is resolved based on that counter.

    So to repeat the original question: why is this done, and what is your recommendentation on how to circumvent the side effect?

Reply
  • I also came across this. I am using Eddystone library in sdk 14, and this causes that sometimes when i am using app_timer in my own application, the EID and uptime counters make a few hundred second jump, which is kinda bad because the EID is resolved based on that counter.

    So to repeat the original question: why is this done, and what is your recommendentation on how to circumvent the side effect?

Children
No Data
Related