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

Sometime, the timer handler is not called with FreeRTOS.

Sometime, the timer handler is not call immediately after calling app_timer_start().

environment
- nrf52840
- SDK 15
- with FreeRTOS
- timer task priority is higher
- timeout_ticks = 1 (app_timer_start)

mechanism (maybe)
1. Call app_timer_start(timeout_ticks = 1).
2. app_timer_start() calls xTimerStart to send COMMAND_START to timer task.
3. The system timer increments tick count by interrupt.
3. Timer task processes COMMAND_START. (timer task priority is higher than the caller.)
4. Timer task calls prvInsertTimerInActiveList().
5. prvInsertTimerInActiveList() detects that timeout is already expire.
6. prvInsertTimerInActiveList() does not call vListInsert.
    prvInsertTimerInActiveList() returns pdTRUE.
7. Timer task calls pxCallbackFunction() immediately.
8. app_timer_callback() is called.
9. But, at this time, since pinfo->active is false, pinfo->func is not called.
    because, timing of "pinfo->active = true" is the last of app_timer_start().

I think that this problem can be fix by changing timing of "pinfo->active = true".
How about it?

Thanks,

Parents
  • Hi,

    Do you have any code/project or procedure that can be used to reproduce this behavior?

    You say "Sometime, the timer handler is not call immediately after calling app_timer_start()", do you have any examples of when it is called and when it is not called?

    Best regards,
    Jørgen

  • I have checked this with our FreeRTOS expert, and your findings makes sense. Unfortunately, this is a limitation with the library that is not well described in the documentation. In the app_timer library used for non-FreeRTOS application, there is a minimum ticks config of 5 ticks (APP_TIMER_MIN_TIMEOUT_TICKS). This limitation is also present in the FreeRTOS version of app_timer, but there is no check to make sure ticks are not set to a lower value than this in the implementation. I have added a bug report internally to get this added to future versions.

    Your workaround will most likely work in most cases, but it is not fail-safe. I would strongly recommend that you do not set the ticks value to anything lower than 5. If the function app_timer_start fails, then setting the flag active = true before the function returns is not good.

  • HI,

    Thank you the advice.

    I think that there is active flag for the exclusive control of the timer start,
    And, I have modified to add "pinfo->active = false" if RTOS API failed,
    But, I will consider about the minimum ticks of 5 ticks along your advice.

    Thank you. 

Reply Children
No Data
Related