diff options
| author | Angus Gratton <angus@redyak.com.au> | 2023-12-07 13:32:41 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-12-08 13:17:15 +1100 |
| commit | 2c828a88153dfdbd767fc0d8f2124cfbefdcbc81 (patch) | |
| tree | 3e21bad9ab25b8b9240fa40eb064bb9b7c4a1116 | |
| parent | 73879734d9954477607199e92fe945537c3c3745 (diff) | |
unix: Update port to use the new event functions.
Necessary to get coverage of the new event functions.
Deletes the case that called usleep(delay) for mp_hal_delay_ms(), it seems
like this wouldn't have ever happened anyhow (MICROPY_EVENT_POOL_HOOK is
always defined for the unix port).
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
| -rw-r--r-- | ports/unix/coverage.c | 5 | ||||
| -rw-r--r-- | ports/unix/mpconfigport.h | 12 | ||||
| -rw-r--r-- | ports/unix/unix_mphal.c | 9 |
3 files changed, 8 insertions, 18 deletions
diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index 88dd48bfa..543af365c 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -578,9 +578,10 @@ STATIC mp_obj_t extra_coverage(void) { mp_sched_unlock(); mp_printf(&mp_plat_print, "unlocked\n"); - // drain pending callbacks + // drain pending callbacks, and test mp_event_wait_indefinite(), mp_event_wait_ms() + mp_event_wait_indefinite(); // the unix port only waits 500us in this call while (mp_sched_num_pending()) { - mp_handle_pending(true); + mp_event_wait_ms(1); } // setting the keyboard interrupt and raising it during mp_handle_pending diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index e7ce534a7..c7e7347cb 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -222,14 +222,10 @@ static inline unsigned long mp_random_seed_init(void) { #endif // In lieu of a WFI(), slow down polling from being a tight loop. -#ifndef MICROPY_EVENT_POLL_HOOK -#define MICROPY_EVENT_POLL_HOOK \ - do { \ - extern void mp_handle_pending(bool); \ - mp_handle_pending(true); \ - usleep(500); /* equivalent to mp_hal_delay_us(500) */ \ - } while (0); -#endif +// +// Note that we don't delay for the full TIMEOUT_MS, as execution +// can't be woken from the delay. +#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) mp_hal_delay_us(500) // Configure the implementation of machine.idle(). #include <sched.h> diff --git a/ports/unix/unix_mphal.c b/ports/unix/unix_mphal.c index eafc915ca..8d6539c88 100644 --- a/ports/unix/unix_mphal.c +++ b/ports/unix/unix_mphal.c @@ -237,17 +237,10 @@ uint64_t mp_hal_time_ns(void) { #ifndef mp_hal_delay_ms void mp_hal_delay_ms(mp_uint_t ms) { - #ifdef MICROPY_EVENT_POLL_HOOK mp_uint_t start = mp_hal_ticks_ms(); while (mp_hal_ticks_ms() - start < ms) { - // MICROPY_EVENT_POLL_HOOK does usleep(500). - MICROPY_EVENT_POLL_HOOK + mp_event_wait_ms(1); } - #else - // TODO: POSIX et al. define usleep() as guaranteedly capable only of 1s sleep: - // "The useconds argument shall be less than one million." - usleep(ms * 1000); - #endif } #endif |
