diff options
| author | Angus Gratton <angus@redyak.com.au> | 2023-11-30 16:06:32 +1100 |
|---|---|---|
| committer | Damien George <damien@micropython.org> | 2023-12-08 12:47:00 +1100 |
| commit | f5be0128e4da1417136495c20888f8291cd22386 (patch) | |
| tree | 0a75714bdd2219bfdc36931c7e6a87d18b221950 /py/runtime.h | |
| parent | 66be82da7ce63e9c907d7d2ed00341dae80ee83f (diff) | |
py: Add port-agnostic inline functions for event handling.
These are intended to replace MICROPY_EVENT_POLL_HOOK and
MICROPY_EVENT_POLL_HOOK_FAST, which are insufficient for tickless ports.
This implementation is along the lines suggested here:
https://github.com/micropython/micropython/issues/12925#issuecomment-1803038430
Currently any usage of these functions expands to use the existing hook
macros, but this can be switched over port by port.
This work was funded through GitHub Sponsors.
Signed-off-by: Angus Gratton <angus@redyak.com.au>
Diffstat (limited to 'py/runtime.h')
| -rw-r--r-- | py/runtime.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/py/runtime.h b/py/runtime.h index 5fa072d7e..a04d4584f 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -109,6 +109,23 @@ bool mp_sched_schedule(mp_obj_t function, mp_obj_t arg); bool mp_sched_schedule_node(mp_sched_node_t *node, mp_sched_callback_t callback); #endif +// Handles any pending MicroPython events without waiting for an interrupt or event. +void mp_event_handle_nowait(void); + +// Handles any pending MicroPython events and then suspends execution until the +// next interrupt or event. +// +// Note: on "tickless" ports this can suspend execution for a long time, +// don't call unless you know an interrupt is coming to continue execution. +// On "ticked" ports it may return early due to the tick interrupt. +void mp_event_wait_indefinite(void); + +// Handle any pending MicroPython events and then suspends execution until the +// next interrupt or event, or until timeout_ms milliseconds have elapsed. +// +// On "ticked" ports it may return early due to the tick interrupt. +void mp_event_wait_ms(mp_uint_t timeout_ms); + // extra printing method specifically for mp_obj_t's which are integral type int mp_print_mp_int(const mp_print_t *print, mp_obj_t x, int base, int base_char, int flags, char fill, int width, int prec); |
