Hello there,
During my development I have discovered an issue with app_timer library. It is fragile for calling stop/start functions from interrupts which has higher priority than app_timer. This results in missing some timers interrupts - which may be crucial (like in my case - since I have a communication watchdog based on app_timer). Here is the code taken from file app_timer2.c with my comments:
static void timer_req_process(drv_rtc_t const * const p_instance)
{
nrf_atfifo_item_get_t fifo_ctx;
timer_req_t * p_req = nrf_atfifo_item_get(m_req_fifo, &fifo_ctx);
while (p_req)
{
switch (p_req->type)
{
case TIMER_REQ_START:
if (!p_req->p_timer->active)
{
// my input-> < place where an interrupt may trigger problems >
p_req->p_timer->active = true;
nrf_sortlist_add(&m_app_timer_sortlist, &(p_req->p_timer->list_item));
NRF_LOG_INST_DEBUG(p_req->p_timer->p_log,"Start request (expiring at %d/0x%08x).",
p_req->p_timer->end_val, p_req->p_timer->end_val);
}
break;
case TIMER_REQ_STOP:
if (p_req->p_timer == mp_active_timer)
{
mp_active_timer = NULL;
}
else
{
bool found = nrf_sortlist_remove(&m_app_timer_sortlist, &(p_req->p_timer->list_item));
if (!found)
{
NRF_LOG_INFO("Timer not found on sortlist (stopping expired timer).");
}
}
// my input-> v solution proposition
// my input-> p_req->p_timer->active = false;
NRF_LOG_INST_DEBUG(p_req->p_timer->p_log,"Stop request.");
break;
case TIMER_REQ_STOP_ALL:
sorted_list_stop_all();
m_global_active = true;
NRF_LOG_INFO("Stop all request.");
break;
default:
break;
So, there is a chance that `p_req->p_timer->active` variable is set to false by app_timer_stop call during timer activation in `case TIMER_REQ_START:`. This may lead to serious issues.
My question is - is it going to be fixed in the future or do I have to make some permanent workaround for this (for example such like shown in `case TIMER_REQ_STOP:`)?
I am using SDK 16.0
Best regards,