stmhal/systick: Make mp_hal_delay_ms release the GIL when sleeping.
This commit is contained in:
parent
2e3fc77809
commit
3509e2d307
|
@ -51,24 +51,17 @@ void HAL_Delay(uint32_t Delay) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Core delay function that does an efficient sleep and may switch thread context.
|
// 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) {
|
void mp_hal_delay_ms(mp_uint_t Delay) {
|
||||||
if (query_irq() == IRQ_STATE_ENABLED) {
|
if (query_irq() == IRQ_STATE_ENABLED) {
|
||||||
// IRQs enabled, so can use systick counter to do the delay
|
// IRQs enabled, so can use systick counter to do the delay
|
||||||
uint32_t start = uwTick;
|
uint32_t start = uwTick;
|
||||||
// Wraparound of tick is taken care of by 2's complement arithmetic.
|
// Wraparound of tick is taken care of by 2's complement arithmetic.
|
||||||
while (uwTick - start < Delay) {
|
while (uwTick - start < Delay) {
|
||||||
// Enter sleep mode, waiting for (at least) the SysTick interrupt.
|
// This macro will execute the necessary idle behaviour. It may
|
||||||
mp_handle_pending();
|
// raise an exception, switch threads or enter sleep mode (waiting for
|
||||||
#if MICROPY_PY_THREAD
|
// (at least) the SysTick interrupt).
|
||||||
if (pyb_thread_enabled) {
|
MICROPY_EVENT_POLL_HOOK
|
||||||
pyb_thread_yield();
|
|
||||||
} else {
|
|
||||||
__WFI();
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
__WFI();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// IRQs disabled, so need to use a busy loop for the delay.
|
// IRQs disabled, so need to use a busy loop for the delay.
|
||||||
|
|
Loading…
Reference in New Issue