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

Mesh SDK 3.1.0 app_timer firing immediately

Consider the following steps: 

1. At t=0s: Set a timer that expires in 30 seconds.

2. At t=30s: The timer set in step 1 expires. This will cause the app_timer module to update its `m_latest_ticks` to around 30s.

3. Suppose during the next 482 seconds no other timer is set. `m_latest_ticks` will stay at 30s, whereas the RTC counter will wrap around to 0.

4. At t=522s: Now set a timer that expires in 1 second. The RTC counter is now 522 % 512 = 10s. Therefore the new timer's `ticks_at_start` is set to around 10s. In `list_insertions_handler`, we have `ticks_at_start` ~= 10s and `m_latest_ticks` ~= 30s. In the following code

if (
     ((p_timer->ticks_at_start - m_ticks_latest) & MAX_RTC_COUNTER_VAL)
     <
     (MAX_RTC_COUNTER_VAL / 2)
    )
{
    p_timer->ticks_to_expire = ticks_diff_get(p_timer->ticks_at_start, m_ticks_latest) +
                               p_timer->ticks_first_interval;
}
else
{
    uint32_t delta_current_start;

    delta_current_start = ticks_diff_get(m_ticks_latest, p_timer->ticks_at_start);
    if (p_timer->ticks_first_interval > delta_current_start)
    {
        p_timer->ticks_to_expire = p_timer->ticks_first_interval - delta_current_start;
    }
    else
    {
        // It ends up here.
        p_timer->ticks_to_expire = 0;
    }
}

it will end up in the last case, and set `ticks_to_expire` to 0. This will cause the timer we just set to fire immediately.

Meanwhile, the issue disappears if I set a dummy timer that fires every 20s just to keep `m_latest_ticks` up-to-date. 

Parents Reply Children
Related