From 8c432ea2d437255eefb4aff18764936ad11b70c7 Mon Sep 17 00:00:00 2001 From: Angus Gratton Date: Tue, 31 Oct 2023 16:42:10 +1100 Subject: [PATCH] rp2: Remove 1ms timeout to make idle waiting tickless. The main motivation for doing this was to reduce the latency when the system is woken by a USB interrupt. The best_effort_wfe_or_timeout() function calls into the pico-sdk dynamic timer framework which sets up a new dynamic timer instance each time, and then has to tear it down before continuing after a WFE. Testing Python interrupt latency, it seems to be improved by about 12us (from average of 46us to 34us running a Pin IRQ). C-based "scheduled nodes" should see even lower latency. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton --- ports/rp2/modmachine.c | 2 +- ports/rp2/mpconfigport.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ports/rp2/modmachine.c b/ports/rp2/modmachine.c index 29a8dbed2c8f..4c428cbddf3e 100644 --- a/ports/rp2/modmachine.c +++ b/ports/rp2/modmachine.c @@ -111,7 +111,7 @@ STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) { STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq); STATIC mp_obj_t machine_idle(void) { - best_effort_wfe_or_timeout(make_timeout_time_ms(1)); + __wfe(); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle); diff --git a/ports/rp2/mpconfigport.h b/ports/rp2/mpconfigport.h index 0a6331273434..84a961db43e8 100644 --- a/ports/rp2/mpconfigport.h +++ b/ports/rp2/mpconfigport.h @@ -274,7 +274,7 @@ extern void mp_thread_end_atomic_section(uint32_t); #define MICROPY_EVENT_POLL_HOOK \ do { \ MICROPY_EVENT_POLL_HOOK_FAST; \ - best_effort_wfe_or_timeout(make_timeout_time_ms(1)); \ + __wfe(); \ } while (0); #define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1))