This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

App timer into endless loop

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.

Parents
  • This could happen if you are trying to remove a timer that is already being removed. In that case the removed linked list stack memory is given back to the stack and could have been filled with some other value. And this value is not an element in linked list, making the while loop go crazy and loop for ever. I am not sure what  other changes you made, so hard to say.

  • Hi Aryan,

    Thank you for your reply.

    This software does not modify a lot, just added a long button function in code, and then print the key log through JLINK RTT.

    With the code in the attachment, it's easy to reproduce this issue.

    ble_app_uart_btn_test.zip

    Please place the test project under nRF5_SDK_15.0.0_a53641a\examples\ble_peripheral

    and add BSP_EVENT_KEY_LONG_1 to bsp_event_t in the bsp.h file.

    Best regards,
    Devin

  • Hi Devin,

    I am sorry for the late reply, I am on my vacation as many others in Norway. I would be back after 2 weeks, and if you wish, I can assign this case to someone else, but the response will still be limited as very few are working in Norway due to vacation times.

    Sorry very the inconvenience.

Reply
  • Hi Devin,

    I am sorry for the late reply, I am on my vacation as many others in Norway. I would be back after 2 weeks, and if you wish, I can assign this case to someone else, but the response will still be limited as very few are working in Norway due to vacation times.

    Sorry very the inconvenience.

Children
No Data
Related