From e20c65d8f044cb9522cd1a7f4a3030efefa77cbb Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Sat, 9 Jan 2021 13:59:54 -0600 Subject: background tasks: Add, use port_wake_main_task Some ports need an extra operation to ensure that the main task is awoken so that a queued background task will execute during an ongoing light sleep. This removes the need to enable supervisor ticks while I2SOut is operating. Closes: #3952 --- supervisor/port.h | 4 ++++ supervisor/shared/background_callback.c | 4 ++++ 2 files changed, 8 insertions(+) (limited to 'supervisor') diff --git a/supervisor/port.h b/supervisor/port.h index 862400986..812cf715b 100644 --- a/supervisor/port.h +++ b/supervisor/port.h @@ -99,4 +99,8 @@ void port_background_task(void); void port_start_background_task(void); void port_finish_background_task(void); +// Some ports need special handling to wake the main task from an interrupt +// context or other task. The port must implement the necessary code in this +// function. A default weak implementation is provided that does nothing. +void port_wake_main_task(void); #endif // MICROPY_INCLUDED_SUPERVISOR_PORT_H diff --git a/supervisor/shared/background_callback.c b/supervisor/shared/background_callback.c index ef686cbab..288c9a4df 100644 --- a/supervisor/shared/background_callback.c +++ b/supervisor/shared/background_callback.c @@ -38,6 +38,8 @@ STATIC volatile background_callback_t *callback_head, *callback_tail; #define CALLBACK_CRITICAL_BEGIN (common_hal_mcu_disable_interrupts()) #define CALLBACK_CRITICAL_END (common_hal_mcu_enable_interrupts()) +MP_WEAK void port_wake_main_task(void) {} + void background_callback_add_core(background_callback_t *cb) { CALLBACK_CRITICAL_BEGIN; if (cb->prev || callback_head == cb) { @@ -55,6 +57,8 @@ void background_callback_add_core(background_callback_t *cb) { } callback_tail = cb; CALLBACK_CRITICAL_END; + + port_wake_main_task(); } void background_callback_add(background_callback_t *cb, background_callback_fun fun, void *data) { -- cgit v1.2.3