Skip to content

Commit cb0c189

Browse files
c1728p9Cruz Monrreal II
authored andcommitted
Don't reschedule ticker while dispatching
Wait until dispatching is finished before scheduling the next ticker interrupt. This prevents unnecissary calls to set_interrupt from periodic elements being added back. This is particularly useful for the low power ticker on devices with LPTICKER_DELAY_TICKS set to a non-zero value. This is because the low power ticker cannot be reschduled immediately and needs to fall back onto the microsecond ticker which temporarily locks deep sleep.
1 parent 39d5e2d commit cb0c189

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

hal/mbed_ticker_api.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static void initialize(const ticker_data_t *ticker)
6969
ticker->queue->max_delta = max_delta;
7070
ticker->queue->max_delta_us = max_delta_us;
7171
ticker->queue->present_time = 0;
72+
ticker->queue->dispatching = false;
7273
ticker->queue->initialized = true;
7374

7475
update_present_time(ticker);
@@ -229,6 +230,12 @@ int _ticker_match_interval_passed(timestamp_t prev_tick, timestamp_t cur_tick, t
229230
static void schedule_interrupt(const ticker_data_t *const ticker)
230231
{
231232
ticker_event_queue_t *queue = ticker->queue;
233+
if (ticker->queue->dispatching) {
234+
// Don't schedule the next interrupt until dispatching is
235+
// finished. This prevents repeated calls to interface->set_interrupt
236+
return;
237+
}
238+
232239
update_present_time(ticker);
233240

234241
if (ticker->queue->head) {
@@ -280,6 +287,7 @@ void ticker_irq_handler(const ticker_data_t *const ticker)
280287
ticker->interface->clear_interrupt();
281288

282289
/* Go through all the pending TimerEvents */
290+
ticker->queue->dispatching = true;
283291
while (1) {
284292
if (ticker->queue->head == NULL) {
285293
break;
@@ -302,6 +310,7 @@ void ticker_irq_handler(const ticker_data_t *const ticker)
302310
break;
303311
}
304312
}
313+
ticker->queue->dispatching = false;
305314

306315
schedule_interrupt(ticker);
307316

hal/ticker_api.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ typedef struct {
8080
uint64_t tick_remainder; /**< Ticks that have not been added to base_time */
8181
us_timestamp_t present_time; /**< Store the timestamp used for present time */
8282
bool initialized; /**< Indicate if the instance is initialized */
83+
bool dispatching; /**< The function ticker_irq_handler is dispatching */
8384
uint8_t frequency_shifts; /**< If frequency is a value of 2^n, this is n, otherwise 0 */
8485
} ticker_event_queue_t;
8586

0 commit comments

Comments
 (0)