Hello,
I encountered an issue with the app_timer2 library (SDK 16.0 and 17.1) : in some cases the timers won't be executed in the correct order and delay.
The problem happens when timer operations are queued in a particular order in an interrupt context with a priority level higher or equal to the RTC1 interrupt priority.
Let's say that we have 3 timers running that will expire in:
T1 : 100ms
T2 : 200ms
T3 : 300ms
Then the following timer operations are queued in the interrupt context :
1. start a timer T4 with delay 1000ms.
2. stop timer T2.
3. start timer T2 with delay 2000ms.
T2 isn't removed from the queue yet because the stop request isn't processed but it's delay has been updated in app_timer_start.
So when exiting the interrupt the queue is the following:
T1 : 100ms
T2 : 2000ms
T3 : 300ms
Because when the start T4 operation will be processed we still have T2 at 2000ms on second position, T4 will be queued before T3. Then T2 will be removed from the queue and added again.
So after processing all the requests the queue is :
T1 : 100ms
T4 : 1000ms
T3 : 300ms
T2 : 2000ms
Hence the sortlist is not sorted anymore, some timers won't be executed in time.
One workaround would be to avoid queuing multiple timer operations in an interrupt context.
Another solution that still need to be fully tested : in app_timer_start we could also store the next delay and apply it only when the operation is processed.
Guillaume
