Skip to content

Commit

Permalink
nrf: disable interrupts before running wfi
Browse files Browse the repository at this point in the history
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 adafruit#2855 on NRF.

Signed-off-by: Sean Cross <sean@xobs.io>
  • Loading branch information
xobs committed May 15, 2020
1 parent c207b68 commit 4be4b96
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions ports/nrf/supervisor/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
#include "common-hal/rtc/RTC.h"
#include "common-hal/neopixel_write/__init__.h"

#include "shared-bindings/microcontroller/__init__.h"
#include "shared-bindings/rtc/__init__.h"

#ifdef CIRCUITPY_AUDIOBUSIO
Expand Down Expand Up @@ -247,7 +248,15 @@ void port_sleep_until_interrupt(void) {
sd_app_evt_wait();
} else {
// Call wait for interrupt ourselves if the SD isn't enabled.
// Note that `wfi` should be called with interrupts disabled,
// to ensure that the queue is properly drained. The `wfi`
// instruction will returned as long as an interrupt is
// available, even though the actual handler won't fire until
// we re-enable interrupts.
common_hal_mcu_disable_interrupts();
RUN_BACKGROUND_TASKS; // Drain any buffers remaining
__WFI();
common_hal_mcu_enable_interrupts();
}
}

Expand Down

0 comments on commit 4be4b96

Please sign in to comment.