Skip to content

Commit 63d2c44

Browse files
committed
esp32: Pump the event loop while waiting for rx-chr or delay_ms.
1 parent bd77a0a commit 63d2c44

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

esp32/mphalport.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ int mp_hal_stdin_rx_chr(void) {
4848
if (c != -1) {
4949
return c;
5050
}
51+
MICROPY_EVENT_POLL_HOOK
5152
vTaskDelay(1);
5253
}
5354
}
@@ -92,12 +93,21 @@ uint32_t mp_hal_ticks_us(void) {
9293

9394
void mp_hal_delay_ms(uint32_t ms) {
9495
struct timeval tv_start;
95-
gettimeofday(&tv_start, NULL);
96-
vTaskDelay(ms / portTICK_PERIOD_MS);
9796
struct timeval tv_end;
98-
gettimeofday(&tv_end, NULL);
99-
uint64_t dt = (tv_end.tv_sec - tv_start.tv_sec) * 1000 + (tv_end.tv_usec - tv_start.tv_usec) / 1000;
97+
uint64_t dt;
98+
gettimeofday(&tv_start, NULL);
99+
for (;;) {
100+
gettimeofday(&tv_end, NULL);
101+
dt = (tv_end.tv_sec - tv_start.tv_sec) * 1000 + (tv_end.tv_usec - tv_start.tv_usec) / 1000;
102+
if (dt + portTICK_PERIOD_MS >= ms) {
103+
// doing a vTaskDelay would take us beyound requested delay time
104+
break;
105+
}
106+
MICROPY_EVENT_POLL_HOOK
107+
vTaskDelay(1);
108+
}
100109
if (dt < ms) {
110+
// do the remaining delay accurately
101111
ets_delay_us((ms - dt) * 1000);
102112
}
103113
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy