test
Fork of mbed-dev by
Diff: hal/mbed_ticker_api.c
- Revision:
- 175:b96e65c34a4d
- Parent:
- 168:e84263d55307
- Child:
- 176:af195413fb11
--- a/hal/mbed_ticker_api.c Fri Sep 15 14:59:18 2017 +0100 +++ b/hal/mbed_ticker_api.c Mon Oct 02 15:33:19 2017 +0100 @@ -117,14 +117,23 @@ // if the event at the head of the queue is in the past then schedule // it immediately. - if (next_event_timestamp < present) { - relative_timeout = 0; + if (next_event_timestamp <= present) { + ticker->interface->fire_interrupt(); + return; } else if ((next_event_timestamp - present) < MBED_TICKER_INTERRUPT_TIMESTAMP_MAX_DELTA) { relative_timeout = next_event_timestamp - present; } } - ticker->interface->set_interrupt(ticker->queue->present_time + relative_timeout); + us_timestamp_t new_match_time = ticker->queue->present_time + relative_timeout; + ticker->interface->set_interrupt(new_match_time); + // there could be a delay, reread the time, check if it was set in the past + // As result, if it is already in the past, we fire it immediately + update_present_time(ticker); + us_timestamp_t present = ticker->queue->present_time; + if (present >= new_match_time) { + ticker->interface->fire_interrupt(); + } } void ticker_set_handler(const ticker_data_t *const ticker, ticker_event_handler handler)