Skip to content

Commit

Permalink
shared/tinyusb: Wake main task if needed at end of USB ISR.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Leech <[email protected]>
  • Loading branch information
pi-anl committed Oct 5, 2024
1 parent b89e91f commit 67d9d67
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ports/mimxrt/mphalport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 4 additions & 0 deletions ports/nrf/mphalport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions ports/renesas-ra/mphalport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -117,5 +121,3 @@ enum {
};

void mp_hal_get_mac(int idx, uint8_t buf[6]);

void mp_hal_set_interrupt_char(int c); // -1 to disable
4 changes: 4 additions & 0 deletions ports/rp2/mphalport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions ports/samd/mphalport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions shared/tinyusb/mp_usbd.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/

#include "py/mpconfig.h"
#include "mphalport.h"

#if MICROPY_HW_ENABLE_USBDEV

Expand Down Expand Up @@ -55,6 +56,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) {
Expand Down

0 comments on commit 67d9d67

Please sign in to comment.