esp32/mphalport: Always yield at least once in delay_ms.
This helps the OS switch to and give other threads processing time during the sleep. It also ensures that pending events are handled, even when sleeping for 0ms. Fixes issue #5344. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
2cfbe5bc0f
commit
6214fa3f9e
|
@ -142,14 +142,22 @@ void mp_hal_delay_ms(uint32_t ms) {
|
||||||
uint64_t dt;
|
uint64_t dt;
|
||||||
uint64_t t0 = esp_timer_get_time();
|
uint64_t t0 = esp_timer_get_time();
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
mp_handle_pending(true);
|
||||||
|
MICROPY_PY_USOCKET_EVENTS_HANDLER
|
||||||
|
MP_THREAD_GIL_EXIT();
|
||||||
uint64_t t1 = esp_timer_get_time();
|
uint64_t t1 = esp_timer_get_time();
|
||||||
dt = t1 - t0;
|
dt = t1 - t0;
|
||||||
if (dt + portTICK_PERIOD_MS * 1000 >= us) {
|
if (dt + portTICK_PERIOD_MS * 1000 >= us) {
|
||||||
// doing a vTaskDelay would take us beyond requested delay time
|
// doing a vTaskDelay would take us beyond requested delay time
|
||||||
|
taskYIELD();
|
||||||
|
MP_THREAD_GIL_ENTER();
|
||||||
|
t1 = esp_timer_get_time();
|
||||||
|
dt = t1 - t0;
|
||||||
break;
|
break;
|
||||||
|
} else {
|
||||||
|
ulTaskNotifyTake(pdFALSE, 1);
|
||||||
|
MP_THREAD_GIL_ENTER();
|
||||||
}
|
}
|
||||||
MICROPY_EVENT_POLL_HOOK
|
|
||||||
ulTaskNotifyTake(pdFALSE, 1);
|
|
||||||
}
|
}
|
||||||
if (dt < us) {
|
if (dt < us) {
|
||||||
// do the remaining delay accurately
|
// do the remaining delay accurately
|
||||||
|
|
Loading…
Reference in New Issue