From e56ef99593c5fc1b4acd51f51ba0e17ee03d9fc4 Mon Sep 17 00:00:00 2001 From: Przemyslaw Stekiel Date: Mon, 12 Feb 2018 14:40:11 +0000 Subject: [PATCH] Fix for issue #6054 - interrupts scheduled in the past. When ticker is not driven by the 1 MHz clock and HAL driver need to perform conversion between microseconds and ticks, then the interrupt might be scheduled in the past. For details see: https://github.com/ARMmbed/mbed-os/issues/6054. This patch provides fix for such case. Interrupt is fired immidiatelly when last read tick is equal to the calculated tick when interrupt should be generated. --- hal/mbed_ticker_api.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hal/mbed_ticker_api.c b/hal/mbed_ticker_api.c index 765a077c0e..6a20006180 100644 --- a/hal/mbed_ticker_api.c +++ b/hal/mbed_ticker_api.c @@ -235,6 +235,14 @@ static void schedule_interrupt(const ticker_data_t *const ticker) } timestamp_t match_tick = compute_tick(ticker, match_time); + // The time has been checked to be future, but it could still round + // to the last tick as a result of us to ticks conversion + if (match_tick == queue->tick_last_read) { + // Match time has already expired so fire immediately + ticker->interface->fire_interrupt(); + return; + } + ticker->interface->set_interrupt(match_tick); timestamp_t cur_tick = ticker->interface->read();