pico-sdk
pico-sdk copied to clipboard
`alarm_pool_add_alarm_at` fires when timestamp missed, even if interrupts are disabled
Context
I have an application that queues alarms at different timestamps, which can be very small depending on the context. However, before calling alarm_pool_add_alarm_at
I disable interrupts with the save_and_disable_interrupts
API.
Expected behaviour.
When disabling interrupts, I expect that my alarm callback cannot be called until the interrupts are re-enabled. However, in alarm_pool_add_alarm_at()
, the callback is called if the timestamp was missed, regardless of state of the interrupts.
Possible Fix
In add_alarm_under_lock
, when is_missed
is true, check the state of the interrupts. If the interrupt level of the alarm is currently blocked, don't remove the entry from the pool and set the timer IRQ. This way, when interrupts are re-enabled, the timer IRQ will fire and the callback will be called without bypassing the interrupt block.