Skip to content

Commit 9fd3e09

Browse files
committed
Prevent recursive processing of us_ticker in FSL
When a ticker is scheduled to run so fast that it is pending again before the previous event has been processed then this next event is processed (recursively) by calling into us_ticker_irq_handle(). This can lead to a stack overflow. This patch prevents this recursion by replacing the call to us_ticker_irq_handler() with a call to set the interrupt to pending again. This allows the next timer event to be processed without making the stack deeper.
1 parent 47c580b commit 9fd3e09

File tree

1 file changed

+5
-2
lines changed
  • libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS

1 file changed

+5
-2
lines changed

libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KPSDK_MCUS/us_ticker.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,11 @@ void us_ticker_clear_interrupt(void) {
6868
void us_ticker_set_interrupt(timestamp_t timestamp) {
6969
int delta = (int)(timestamp - us_ticker_read());
7070
if (delta <= 0) {
71-
// This event was in the past:
72-
us_ticker_irq_handler();
71+
// This event was in the past.
72+
// Set the interrupt as pending, but don't process it here.
73+
// This prevents a recurive loop under heavy load
74+
// which can lead to a stack overflow.
75+
NVIC_SetPendingIRQ(PIT3_IRQn);
7376
return;
7477
}
7578

0 commit comments

Comments
 (0)