From 85be3d3da889af76219c8bbfff041e8a4faab0c8 Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 5 Jul 2022 16:11:42 +1000 Subject: [PATCH] rp2/mpconfigport: Factor core event handling to EVENT_POLL_HOOK_FAST. Signed-off-by: Damien George --- ports/rp2/mpconfigport.h | 9 +++++++-- ports/rp2/mphalport.c | 3 +-- ports/rp2/rp2_pio.c | 6 ++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 9143b5f6c5..53437d6c98 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -248,12 +248,17 @@ extern const struct _mod_network_nic_type_t mod_network_nic_type_wiznet5k; #define MICROPY_HW_USBDEV_TASK_HOOK #endif -#define MICROPY_EVENT_POLL_HOOK \ +#define MICROPY_EVENT_POLL_HOOK_FAST \ do { \ + MICROPY_HW_USBDEV_TASK_HOOK \ extern void mp_handle_pending(bool); \ mp_handle_pending(true); \ + } while (0) + +#define MICROPY_EVENT_POLL_HOOK \ + do { \ + MICROPY_EVENT_POLL_HOOK_FAST; \ best_effort_wfe_or_timeout(make_timeout_time_ms(1)); \ - MICROPY_HW_USBDEV_TASK_HOOK \ } while (0); #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1)) diff --git a/ports/rp2/mphalport.c b/ports/rp2/mphalport.c index aec4a96724..d3824d8f91 100644 --- a/ports/rp2/mphalport.c +++ b/ports/rp2/mphalport.c @@ -157,9 +157,8 @@ void mp_hal_stdout_tx_strn(const char *str, mp_uint_t len) { void mp_hal_delay_ms(mp_uint_t ms) { absolute_time_t t = make_timeout_time_ms(ms); while (!time_reached(t)) { - mp_handle_pending(true); + MICROPY_EVENT_POLL_HOOK_FAST; best_effort_wfe_or_timeout(t); - MICROPY_HW_USBDEV_TASK_HOOK } } diff --git a/ports/rp2/rp2_pio.c b/ports/rp2/rp2_pio.c index 9955cc5440..9900616966 100644 --- a/ports/rp2/rp2_pio.c +++ b/ports/rp2/rp2_pio.c @@ -657,8 +657,7 @@ STATIC mp_obj_t rp2_state_machine_get(size_t n_args, const mp_obj_t *args) { for (;;) { while (pio_sm_is_rx_fifo_empty(self->pio, self->sm)) { // This delay must be fast. - mp_handle_pending(true); - MICROPY_HW_USBDEV_TASK_HOOK + MICROPY_EVENT_POLL_HOOK_FAST; } uint32_t value = pio_sm_get(self->pio, self->sm) >> shift; if (dest == NULL) { @@ -716,8 +715,7 @@ STATIC mp_obj_t rp2_state_machine_put(size_t n_args, const mp_obj_t *args) { } while (pio_sm_is_tx_fifo_full(self->pio, self->sm)) { // This delay must be fast. - mp_handle_pending(true); - MICROPY_HW_USBDEV_TASK_HOOK + MICROPY_EVENT_POLL_HOOK_FAST; } pio_sm_put(self->pio, self->sm, value << shift); }