Skip to content

Commit e20c65d

Browse files
committed
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
1 parent 4735cf4 commit e20c65d

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

ports/esp32s2/common-hal/audiobusio/I2SOut.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t* self,
6363
self->bit_clock = bit_clock;
6464
self->word_select = word_select;
6565
self->data = data;
66-
67-
supervisor_enable_tick();
6866
}
6967

7068
bool common_hal_audiobusio_i2sout_deinited(audiobusio_i2sout_obj_t* self) {
@@ -95,8 +93,6 @@ void common_hal_audiobusio_i2sout_deinit(audiobusio_i2sout_obj_t* self) {
9593
port_i2s_reset_instance(self->peripheral.instance);
9694
}
9795
self->peripheral.instance = -1;
98-
99-
supervisor_disable_tick();
10096
}
10197

10298
void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,

ports/esp32s2/supervisor/port.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ safe_mode_t port_init(void) {
111111
heap = NULL;
112112
never_reset_module_internal_pins();
113113

114+
#if defined(DEBUG)
115+
// debug UART
116+
common_hal_never_reset_pin(&pin_GPIO43);
117+
common_hal_never_reset_pin(&pin_GPIO44);
118+
#endif
119+
114120
#if defined(DEBUG) || defined(ENABLE_JTAG)
115121
// JTAG
116122
common_hal_never_reset_pin(&pin_GPIO39);
@@ -291,10 +297,14 @@ void port_disable_tick(void) {
291297
esp_timer_stop(_tick_timer);
292298
}
293299

294-
void sleep_timer_cb(void* arg) {
300+
void port_wake_main_task() {
295301
xTaskNotifyGive(circuitpython_task);
296302
}
297303

304+
void sleep_timer_cb(void* arg) {
305+
port_wake_main_task();
306+
}
307+
298308
void port_interrupt_after_ticks(uint32_t ticks) {
299309
uint64_t timeout_us = ticks * 1000000ull / 1024;
300310
if (esp_timer_start_once(_sleep_timer, timeout_us) != ESP_OK) {

supervisor/port.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,8 @@ void port_background_task(void);
9999
void port_start_background_task(void);
100100
void port_finish_background_task(void);
101101

102+
// Some ports need special handling to wake the main task from an interrupt
103+
// context or other task. The port must implement the necessary code in this
104+
// function. A default weak implementation is provided that does nothing.
105+
void port_wake_main_task(void);
102106
#endif // MICROPY_INCLUDED_SUPERVISOR_PORT_H

supervisor/shared/background_callback.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ STATIC volatile background_callback_t *callback_head, *callback_tail;
3838
#define CALLBACK_CRITICAL_BEGIN (common_hal_mcu_disable_interrupts())
3939
#define CALLBACK_CRITICAL_END (common_hal_mcu_enable_interrupts())
4040

41+
MP_WEAK void port_wake_main_task(void) {}
42+
4143
void background_callback_add_core(background_callback_t *cb) {
4244
CALLBACK_CRITICAL_BEGIN;
4345
if (cb->prev || callback_head == cb) {
@@ -55,6 +57,8 @@ void background_callback_add_core(background_callback_t *cb) {
5557
}
5658
callback_tail = cb;
5759
CALLBACK_CRITICAL_END;
60+
61+
port_wake_main_task();
5862
}
5963

6064
void background_callback_add(background_callback_t *cb, background_callback_fun fun, void *data) {

0 commit comments

Comments
 (0)