add tud_task_ext(), tuh_task_ext() as exteneded version that take timeout and in_isr

also allow exit tud_task,tuh_task after processing all events for
running other background task for user
This commit is contained in:
hathach
2022-04-20 18:29:41 +07:00
parent ccafb42c82
commit b034c18077
6 changed files with 50 additions and 15 deletions

View File

@@ -466,8 +466,10 @@ bool tud_task_event_ready(void)
}
@endcode
*/
void tud_task (void)
void tud_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;
@@ -475,7 +477,7 @@ void tud_task (void)
while (1)
{
dcd_event_t event;
if ( !osal_queue_receive(_usbd_q, &event, 1) ) return;
if ( !osal_queue_receive(_usbd_q, &event, timeout_ms) ) return;
#if CFG_TUSB_DEBUG >= 2
if (event.event_id == DCD_EVENT_SETUP_RECEIVED) TU_LOG2("\r\n"); // extra line for setup
@@ -592,6 +594,11 @@ void tud_task (void)
TU_BREAKPOINT();
break;
}
#if CFG_TUSB_OS != OPT_OS_NONE && CFG_TUSB_OS != OPT_OS_PICO
// return if there is no more events, for application to run other background
if (osal_queue_empty(_usbd_q)) return;
#endif
}
}