From 548f88d2bd254f1328014a303f8bf602a0646421 Mon Sep 17 00:00:00 2001 From: Andrew Leech Date: Wed, 31 Jul 2024 21:40:05 +1000 Subject: [PATCH] shared/tinyusb: Wake main task if needed at end of USB ISR. Signed-off-by: Andrew Leech --- ports/mimxrt/mphalport.h | 4 ++++ ports/nrf/mphalport.h | 4 ++++ ports/renesas-ra/mphalport.h | 4 ++++ ports/rp2/mphalport.h | 4 ++++ ports/samd/mphalport.h | 4 ++++ shared/tinyusb/mp_usbd.c | 3 ++- 6 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ports/mimxrt/mphalport.h b/ports/mimxrt/mphalport.h index c69ebf5810..a0e4575024 100644 --- a/ports/mimxrt/mphalport.h +++ b/ports/mimxrt/mphalport.h @@ -109,6 +109,10 @@ __attribute__((always_inline)) static inline uint32_t disable_irq(void) { void mp_hal_set_interrupt_char(int c); +static inline void mp_hal_wake_main_task_from_isr(void) { + // Defined for tinyusb support, nothing needs to be done here. +} + static inline mp_uint_t mp_hal_ticks_ms(void) { return ticks_ms32(); } diff --git a/ports/nrf/mphalport.h b/ports/nrf/mphalport.h index 50c61aefcd..a0bca58a62 100644 --- a/ports/nrf/mphalport.h +++ b/ports/nrf/mphalport.h @@ -53,6 +53,10 @@ void mp_hal_set_interrupt_char(int c); // -1 to disable int mp_hal_stdin_rx_chr(void); void mp_hal_stdout_tx_str(const char *str); +static inline void mp_hal_wake_main_task_from_isr(void) { + // Defined for tinyusb support, nothing needs to be done here. +} + void mp_hal_delay_ms(mp_uint_t ms); void mp_hal_delay_us(mp_uint_t us); diff --git a/ports/renesas-ra/mphalport.h b/ports/renesas-ra/mphalport.h index 14e6ee0c3e..0819abeaf6 100644 --- a/ports/renesas-ra/mphalport.h +++ b/ports/renesas-ra/mphalport.h @@ -52,6 +52,10 @@ static inline int mp_hal_status_to_neg_errno(HAL_StatusTypeDef status) { NORETURN void mp_hal_raise(HAL_StatusTypeDef status); void mp_hal_set_interrupt_char(int c); // -1 to disable +static inline void mp_hal_wake_main_task_from_isr(void) { + // Defined for tinyusb support, nothing needs to be done here. +} + // timing functions #include "irq.h" diff --git a/ports/rp2/mphalport.h b/ports/rp2/mphalport.h index 16ac4259a6..09ad54dd1e 100644 --- a/ports/rp2/mphalport.h +++ b/ports/rp2/mphalport.h @@ -77,6 +77,10 @@ void mp_thread_end_atomic_section(uint32_t); void mp_hal_set_interrupt_char(int c); void mp_hal_time_ns_set_from_rtc(void); +static inline void mp_hal_wake_main_task_from_isr(void) { + // Defined for tinyusb support, nothing needs to be done here. +} + static inline void mp_hal_delay_us_fast(mp_uint_t us) { busy_wait_us(us); } diff --git a/ports/samd/mphalport.h b/ports/samd/mphalport.h index ee1ebf7aea..6c9e525bb9 100644 --- a/ports/samd/mphalport.h +++ b/ports/samd/mphalport.h @@ -50,6 +50,10 @@ uint64_t mp_hal_ticks_us_64(void); void mp_hal_set_interrupt_char(int c); +static inline void mp_hal_wake_main_task_from_isr(void) { + // Defined for tinyusb support, nothing needs to be done here. +} + __attribute__((always_inline)) static inline void enable_irq(uint32_t state) { __set_PRIMASK(state); } diff --git a/shared/tinyusb/mp_usbd.c b/shared/tinyusb/mp_usbd.c index 436314dcde..7ccfa7018d 100644 --- a/shared/tinyusb/mp_usbd.c +++ b/shared/tinyusb/mp_usbd.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "py/mpconfig.h" +#include "py/mphal.h" #if MICROPY_HW_ENABLE_USBDEV @@ -55,6 +55,7 @@ extern void __real_dcd_event_handler(dcd_event_t const *event, bool in_isr); TU_ATTR_FAST_FUNC void __wrap_dcd_event_handler(dcd_event_t const *event, bool in_isr) { __real_dcd_event_handler(event, in_isr); mp_usbd_schedule_task(); + mp_hal_wake_main_task_from_isr(); } TU_ATTR_FAST_FUNC void mp_usbd_schedule_task(void) {