Based on the nRF5_SDK_15.0.0_a53641a\examples\ble_peripheral\ble_app_uart\pca10040\s132 sample code, I've defined a long button(button 2) and 3 short buttons ( button 1, 3, 4) ,
then I randomly and quickly pressed the 4 buttons on nRF52 DK, It was easy to found a issue with App_timer into endless loop. I use DEBUG mode and locate the issue occurs the timer_list_remove(timer_node_t * p_timer) function with loop indefinitely while (p_current != NULL).
When the issue occurs, the value of p_timer is greater than the value of p_current.
static bool timer_list_remove(timer_node_t * p_timer)
{
timer_node_t * p_old_head;
timer_node_t * p_previous;
timer_node_t * p_current;
uint32_t timeout;
// Find the timer's position in timer list.
p_old_head = mp_timer_id_head;
p_previous = mp_timer_id_head;
p_current = p_previous;
while (p_current != NULL)
{
if (p_current == p_timer)
{
break;
}
p_previous = p_current;
p_current = p_current->next;
}
// Timer not in active list.
if (p_current == NULL)
{
return false;
}
// Timer is the first in the list
if (p_previous == p_current)
{
mp_timer_id_head = mp_timer_id_head->next;
// 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;
nrf_delay_us(MAX_RTC_TASKS_DELAY);
}
}
// Remaining timeout between next timeout.
timeout = p_current->ticks_to_expire;
// Link previous timer with next of this timer, i.e. removing the timer from list.
p_previous->next = p_current->next;
// If this is not the last timer, increment the next timer by this timer timeout.
p_current = p_previous->next;
if (p_current != NULL)
{
p_current->ticks_to_expire += timeout;
}
return (p_old_head != mp_timer_id_head);
}
If I define only 4 short buttons, and test them use same way, this problem won't happen.
Has anyone ever meet this issue?Can you give me some advice?
Thanks.