diff options
| author | hathach <[email protected]> | 2023-03-22 09:23:44 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2023-03-22 09:23:44 +0700 |
| commit | f8a5cde3c7fde62c3d6bd379fea6eaa9a629ded6 (patch) | |
| tree | 052dd386e0b1429a56a9e21c38141971e097588e /src/host/usbh.c | |
| parent | 0921edaf5924d498e8115815dc23acfb1decb7a0 (diff) | |
add tuh_task_event_ready(), better implement blocking control transfer for rtos
Diffstat (limited to 'src/host/usbh.c')
| -rw-r--r-- | src/host/usbh.c | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/src/host/usbh.c b/src/host/usbh.c index dc347c458..3eff0830a 100644 --- a/src/host/usbh.c +++ b/src/host/usbh.c @@ -360,6 +360,14 @@ bool tuh_init(uint8_t controller_id) return true; } +bool tuh_task_event_ready(void) +{ + // Skip if stack is not initialized + if ( !tuh_inited() ) return false; + + return !osal_queue_empty(_usbh_q); +} + /* USB Host Driver task * This top level thread manages all host controller event and delegates events to class-specific drivers. * This should be called periodically within the mainloop or rtos thread. @@ -383,7 +391,7 @@ void tuh_task_ext(uint32_t timeout_ms, bool in_isr) (void) in_isr; // not implemented yet // Skip if stack is not initialized - if ( !tusb_inited() ) return; + if ( !tuh_inited() ) return; // Loop until there is no more events in the queue while (1) @@ -565,12 +573,12 @@ bool tuh_control_xfer (tuh_xfer_t* xfer) while (result == XFER_RESULT_INVALID) { - // only need to call task if not preempted RTOS - #if CFG_TUSB_OS == OPT_OS_NONE || CFG_TUSB_OS == OPT_OS_PICO - tuh_task(); - #else - osal_task_delay(1); // TODO maybe yield() - #endif + // Note: this can be called within an callback ie. part of tuh_task() + // therefore event with RTOS tuh_task() still need to be invoked + if (tuh_task_event_ready()) + { + tuh_task(); + } // TODO probably some timeout to prevent hanged } |
