aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George2017-03-22 12:54:43 +1100
committerDamien George2017-03-22 12:54:43 +1100
commit3509e2d3074486e426b41aa89c6e01d591eb01ad (patch)
tree3d788803e07ddc10d4ddc22d498ea2fbccf82227
parent2e3fc778094c0c31c3e15e196e1c7b3b838239fe (diff)
stmhal/systick: Make mp_hal_delay_ms release the GIL when sleeping.
-rw-r--r--stmhal/systick.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/stmhal/systick.c b/stmhal/systick.c
index 71e3d3488..4eac583e2 100644
--- a/stmhal/systick.c
+++ b/stmhal/systick.c
@@ -51,24 +51,17 @@ void HAL_Delay(uint32_t Delay) {
}
// Core delay function that does an efficient sleep and may switch thread context.
-// Note: Upon entering this function we may or may not have the GIL.
+// If IRQs are enabled then we must have the GIL.
void mp_hal_delay_ms(mp_uint_t Delay) {
if (query_irq() == IRQ_STATE_ENABLED) {
// IRQs enabled, so can use systick counter to do the delay
uint32_t start = uwTick;
// Wraparound of tick is taken care of by 2's complement arithmetic.
while (uwTick - start < Delay) {
- // Enter sleep mode, waiting for (at least) the SysTick interrupt.
- mp_handle_pending();
- #if MICROPY_PY_THREAD
- if (pyb_thread_enabled) {
- pyb_thread_yield();
- } else {
- __WFI();
- }
- #else
- __WFI();
- #endif
+ // This macro will execute the necessary idle behaviour. It may
+ // raise an exception, switch threads or enter sleep mode (waiting for
+ // (at least) the SysTick interrupt).
+ MICROPY_EVENT_POLL_HOOK
}
} else {
// IRQs disabled, so need to use a busy loop for the delay.