summaryrefslogtreecommitdiffstatshomepage
path: root/py/scheduler.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/scheduler.c')
-rw-r--r--py/scheduler.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/py/scheduler.c b/py/scheduler.c
index b9a43bfbdb..3eae8b4fa3 100644
--- a/py/scheduler.c
+++ b/py/scheduler.c
@@ -241,3 +241,39 @@ void mp_handle_pending(bool raise_exc) {
}
#endif
}
+
+// Handles any pending MicroPython events without waiting for an interrupt or event.
+void mp_event_handle_nowait(void) {
+ #if defined(MICROPY_EVENT_POLL_HOOK_FAST) && !MICROPY_PREVIEW_VERSION_2
+ // For ports still using the old macros.
+ MICROPY_EVENT_POLL_HOOK_FAST
+ #else
+ // Process any port layer (non-blocking) events.
+ MICROPY_INTERNAL_EVENT_HOOK;
+ mp_handle_pending(true);
+ #endif
+}
+
+// Handles any pending MicroPython events and then suspends execution until the
+// next interrupt or event.
+void mp_event_wait_indefinite(void) {
+ #if defined(MICROPY_EVENT_POLL_HOOK) && !MICROPY_PREVIEW_VERSION_2
+ // For ports still using the old macros.
+ MICROPY_EVENT_POLL_HOOK
+ #else
+ mp_event_handle_nowait();
+ MICROPY_INTERNAL_WFE(-1);
+ #endif
+}
+
+// Handle any pending MicroPython events and then suspends execution until the
+// next interrupt or event, or until timeout_ms milliseconds have elapsed.
+void mp_event_wait_ms(mp_uint_t timeout_ms) {
+ #if defined(MICROPY_EVENT_POLL_HOOK) && !MICROPY_PREVIEW_VERSION_2
+ // For ports still using the old macros.
+ MICROPY_EVENT_POLL_HOOK
+ #else
+ mp_event_handle_nowait();
+ MICROPY_INTERNAL_WFE(timeout_ms);
+ #endif
+}