Skip to content

Commit ef18fe4

Browse files
committed
nrf: disable interrupts before running wfi
Also, run background tasks with interrupts disabled. This ensures that any buffers are drained, and if an interrupt arrives after buffers are drained but before the WFI is executed then the WFI instruction will return immediately. This fixes #2855 on NRF. Signed-off-by: Sean Cross <[email protected]>
1 parent c9a3664 commit ef18fe4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

ports/nrf/supervisor/port.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,15 @@ void port_sleep_until_interrupt(void) {
247247
sd_app_evt_wait();
248248
} else {
249249
// Call wait for interrupt ourselves if the SD isn't enabled.
250+
// Note that `wfi` should be called with interrupts disabled,
251+
// to ensure that the queue is properly drained. The `wfi`
252+
// instruction will returned as long as an interrupt is
253+
// available, even though the actual handler won't fire until
254+
// we re-enable interrupts.
255+
__disable_irq();
256+
RUN_BACKGROUND_TASKS; // Drain any buffers remaining
250257
__WFI();
258+
__enable_irq();
251259
}
252260
}
253261

0 commit comments

Comments
 (0)