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>
pull/13096/head
Angus Gratton 2023-12-07 13:32:41 +11:00 zatwierdzone przez Damien George
rodzic 73879734d9
commit 2c828a8815
3 zmienionych plików z 8 dodań i 18 usunięć

Wyświetl plik

@ -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

Wyświetl plik

@ -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>

Wyświetl plik

@ -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