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
This commit is contained in:
parent
4735cf4747
commit
e20c65d8f0
@ -63,8 +63,6 @@ void common_hal_audiobusio_i2sout_construct(audiobusio_i2sout_obj_t* self,
|
|||||||
self->bit_clock = bit_clock;
|
self->bit_clock = bit_clock;
|
||||||
self->word_select = word_select;
|
self->word_select = word_select;
|
||||||
self->data = data;
|
self->data = data;
|
||||||
|
|
||||||
supervisor_enable_tick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool common_hal_audiobusio_i2sout_deinited(audiobusio_i2sout_obj_t* self) {
|
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) {
|
|||||||
port_i2s_reset_instance(self->peripheral.instance);
|
port_i2s_reset_instance(self->peripheral.instance);
|
||||||
}
|
}
|
||||||
self->peripheral.instance = -1;
|
self->peripheral.instance = -1;
|
||||||
|
|
||||||
supervisor_disable_tick();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
|
void common_hal_audiobusio_i2sout_play(audiobusio_i2sout_obj_t* self,
|
||||||
|
@ -111,6 +111,12 @@ safe_mode_t port_init(void) {
|
|||||||
heap = NULL;
|
heap = NULL;
|
||||||
never_reset_module_internal_pins();
|
never_reset_module_internal_pins();
|
||||||
|
|
||||||
|
#if defined(DEBUG)
|
||||||
|
// debug UART
|
||||||
|
common_hal_never_reset_pin(&pin_GPIO43);
|
||||||
|
common_hal_never_reset_pin(&pin_GPIO44);
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(DEBUG) || defined(ENABLE_JTAG)
|
#if defined(DEBUG) || defined(ENABLE_JTAG)
|
||||||
// JTAG
|
// JTAG
|
||||||
common_hal_never_reset_pin(&pin_GPIO39);
|
common_hal_never_reset_pin(&pin_GPIO39);
|
||||||
@ -291,10 +297,14 @@ void port_disable_tick(void) {
|
|||||||
esp_timer_stop(_tick_timer);
|
esp_timer_stop(_tick_timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sleep_timer_cb(void* arg) {
|
void port_wake_main_task() {
|
||||||
xTaskNotifyGive(circuitpython_task);
|
xTaskNotifyGive(circuitpython_task);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sleep_timer_cb(void* arg) {
|
||||||
|
port_wake_main_task();
|
||||||
|
}
|
||||||
|
|
||||||
void port_interrupt_after_ticks(uint32_t ticks) {
|
void port_interrupt_after_ticks(uint32_t ticks) {
|
||||||
uint64_t timeout_us = ticks * 1000000ull / 1024;
|
uint64_t timeout_us = ticks * 1000000ull / 1024;
|
||||||
if (esp_timer_start_once(_sleep_timer, timeout_us) != ESP_OK) {
|
if (esp_timer_start_once(_sleep_timer, timeout_us) != ESP_OK) {
|
||||||
|
@ -99,4 +99,8 @@ void port_background_task(void);
|
|||||||
void port_start_background_task(void);
|
void port_start_background_task(void);
|
||||||
void port_finish_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
|
#endif // MICROPY_INCLUDED_SUPERVISOR_PORT_H
|
||||||
|
@ -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_BEGIN (common_hal_mcu_disable_interrupts())
|
||||||
#define CALLBACK_CRITICAL_END (common_hal_mcu_enable_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) {
|
void background_callback_add_core(background_callback_t *cb) {
|
||||||
CALLBACK_CRITICAL_BEGIN;
|
CALLBACK_CRITICAL_BEGIN;
|
||||||
if (cb->prev || callback_head == cb) {
|
if (cb->prev || callback_head == cb) {
|
||||||
@ -55,6 +57,8 @@ void background_callback_add_core(background_callback_t *cb) {
|
|||||||
}
|
}
|
||||||
callback_tail = cb;
|
callback_tail = cb;
|
||||||
CALLBACK_CRITICAL_END;
|
CALLBACK_CRITICAL_END;
|
||||||
|
|
||||||
|
port_wake_main_task();
|
||||||
}
|
}
|
||||||
|
|
||||||
void background_callback_add(background_callback_t *cb, background_callback_fun fun, void *data) {
|
void background_callback_add(background_callback_t *cb, background_callback_fun fun, void *data) {
|
||||||
|
Loading…
Reference in New Issue
Block a user