Fully asynchrounous host code#3482
Conversation
…r continuation chunks This introduce a usbh_wait_delay_ms() function that calls tusb_time_delay_ms_api() followed by the continuation function. After this preparatory patch, no behaviour change should occur.
This is the interesting part of the patchset, which removes tusb_time_delay_ms_api() and instead call continuation functions asynchronously
This addresses a TODO and use a proper separate queue for deferred attachments instead of the existing hack which busy loop during deferred attachments.
| usbh_wait_delay_ms(ENUM_DEBOUNCING_DELAY_MS, enum_after_debouncing_delay); | ||
| } | ||
|
|
||
| static void enum_after_debouncing_delay(void) { |
Check notice
Code scanning / CodeQL
Unused static function Note
|
How to handle the few platforms missing tusb_time_millis_api()? |
I see you can't wait longer :) I've asked Claude if OSAL ports has millis API: ✅ Already supported:
❌ Not yet supported in board_api.h:
We can add a Another challenge is control transfer and buffer management. To save ressource USBH only manage one control transfer (composed by setup+data+status packets) each time. Line 729 in 707fb52 With the state managed here: Line 191 in 707fb52 And the buffer, which is also exposed to class driver as temporary buffer by Line 202 in 707fb52 |
| xfer.daddr = 0; | ||
| xfer.result = XFER_RESULT_SUCCESS; | ||
| xfer.user_data = ENUM_ADDR0_DEVICE_DESC; | ||
| process_enumeration(&xfer); |
Check notice
Code scanning / CodeQL
Unused static function Note
| // Stop enumeration gracefully | ||
| enum_full_complete(false); | ||
| TU_ASSERT(false,); | ||
| } |
Check notice
Code scanning / CodeQL
Unused static function Note
|
Ok, now all compilation checks pass.
Hey, I've customers waiting :) Regarding tusb_time_millis_api(), I've added a configuration option, CFG_TUH_TASK_USE_TIME_MILLIS_API, which is enabled by default except for OPT_OS_RTX4 and OPT_OS_PICO. I've also disabled the feature for expressif. For OPT_OS_PICO this is weird because in ./hw/bsp/board_api.h, board_millis() is defined, but I think ./hw/bsp/board.c, which implements tusb_time_millis_api() by calling board_millis(), is simply not compiled for some platforms (rp2040, expressif in particular). I'll look at the control transfer issue after lunch. |
Ok, I've looked at tuh_control_xfer() and I think I see some of the issues. here are a few of my observations:
Am I correct? do we agree on all that? |
Also, use a timeout of 0 instead of tuh_task_event_ready() check.
|
My goodness, is there a way to silence this "advanced" security bot? |
that is OK, just ignore it if it does not make sense. It is static analyzer warning from PVS-studio and/or other tool, but I currently configure some of the tusb config (this thing take lots of time to tweak and tune-up) therefore code may be mistaken as unreachable. I got annoyed by it as well, but we do review with a pair of human eye. |
1 . Yes @hathach what do you think ? |
Reading the code, adding a transfer status to each device for use after enumeration was also my first idea (but keeping a global transfer status and buffer global for enumeration). For the buffer, acm_set_line_coding() and friends could maybe just put the small buffers they need right into the CDC private structure, or worst case use malloc/free instead of the shared buffer when the system is configured with > 1 device. Honestly, I can see Logitech selling a mouse with TinyUSB and a 8051... but I don't think many people would want to use TinyUSB as host with a "smaller MCU", especially with multiple devices.... |
|
|
||
| #if OSAL_MUTEX_REQUIRED | ||
| #if CFG_TUH_HUB | ||
| osal_queue_delete(_usbh_daq); |
Check warning
Code scanning / CodeQL
Expression has no effect Warning
Size Difference ReportBecause TinyUSB code size varies by port and configuration, the metrics below represent the averaged totals across all example builds. Note: If there is no change, only one value is shown. Changes >1% in size
Changes <1% in size
No changes
|
|
Deleted in favour of #3490 (same final code) |
Describe the PR
This remove all calls to tusb_time_delay_ms_api() from inside tuh_task_ext().
Additional context
Use of the host API was not really possible with OPT_OS_NONE due to blocking calls in tuh_task_ext().
With an OS, it will also improve the situation because:
I've split this in 3 main patches (the last 6 are fixes for warnings discovered after generating the PR)