add tuh_task_event_ready(), better implement blocking control transfer for rtos

This commit is contained in:
hathach 2023-03-22 09:23:44 +07:00
parent 0921edaf59
commit f8a5cde3c7
2 changed files with 25 additions and 7 deletions

View File

@ -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
}

View File

@ -69,6 +69,13 @@ struct tuh_xfer_s
// uint32_t timeout_ms; // place holder, not supported yet
};
// Subject to change
typedef struct
{
uint8_t daddr;
tusb_desc_interface_t desc;
} tuh_itf_info_t;
// ConfigID for tuh_config()
enum
{
@ -118,6 +125,9 @@ void tuh_task(void)
tuh_task_ext(UINT32_MAX, false);
}
// Check if there is pending events need processing by tuh_task()
bool tuh_task_event_ready(void);
#ifndef _TUSB_HCD_H_
extern void hcd_int_handler(uint8_t rhport);
#endif