diff options
| author | Sean Cross <sean@xobs.io> | 2020-05-08 12:38:23 +0800 |
|---|---|---|
| committer | Sean Cross <sean@xobs.io> | 2020-05-21 21:43:52 +0800 |
| commit | 77cf4dce8f1ae03edbe275cb82e250daeba8990f (patch) | |
| tree | 854f2aebbee164f045d57814ffe4f1d168811ea1 | |
| parent | d1a7fdd9d4720c43d0ab9f16267fd124a414ce9d (diff) | |
nrf: disable interrupts before running wfi
In order to ensure we don't have any outstanding requests, disable
interrupts prior to issuing `WFI`.
As part of this process, check to see if there are any pending USB
requests, and only execute the `WFI` if there is no pending data.
This fixes #2855 on NRF.
Signed-off-by: Sean Cross <sean@xobs.io>
| -rw-r--r-- | ports/nrf/supervisor/port.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/ports/nrf/supervisor/port.c b/ports/nrf/supervisor/port.c index ea09115f7..aa138e481 100644 --- a/ports/nrf/supervisor/port.c +++ b/ports/nrf/supervisor/port.c @@ -51,8 +51,11 @@ #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" +#include "lib/tinyusb/src/device/usbd.h" + #ifdef CIRCUITPY_AUDIOBUSIO #include "common-hal/audiobusio/I2SOut.h" #endif @@ -264,7 +267,15 @@ void port_sleep_until_interrupt(void) { sd_app_evt_wait(); } else { // Call wait for interrupt ourselves if the SD isn't enabled. - __WFI(); + // 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(); + if (!tud_task_event_ready()) + __WFI(); + common_hal_mcu_enable_interrupts(); } } |
