-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Provides new tud_task_ext2() and tuh_task_ext2() entry points #3432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
These new variants allows the main application loop to limit how much time is spend on these functions, to ensure that other critical code can run often enough.
|
I think this is just a poor man's solution, the number of events per cycle is not directly proportional to how long tud_task will run. For your MSC case the long latency is due to disk IO in blocked callback functions. The right way is using RTOS + non-blocking asynchronous IO like cdc_msc_freertos example. Without RTOS you can also use PendSV interrupt (or other free interrupts):
|
It might be a poor man's solution, but it still is a solution to a real problem.
Well, in my case, disk IO was pretty fast because it is a Ramdisk (I might be a poor man, but I'm not stupid enough to block on callbacks :) I agree with you that RTOS is better for these, but I'm writing monitoring code on the M4 side (I'm using a rtos on the M7). In any case TinyUSB claims to be working without RTOS - which is great - so I think this patch adresses a real problem. |
Use uint32_t for 'events' variable
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 sizeNo entries. Changes <1% in size
No changes
|
These new function variants allows the main application loop to limit how much time is spend on these functions, to ensure that other critical code can run fast enough.
Describe the PR
An application main loop (without os) that usually tinyusb host and device stack look like:
Unfortunately, without patching, tud_task() and tuh_task() can take arbitrarily long, if the CPU is slow and USB traffic fast.
the other day I got tud_task() running many seconds mounting a FATFS partition using a msc device on slow full speed USB.
Infinite loop can also happen in weird situations (bugs or stuff like usbh.c line 626).
This PR solves all of these by allowing the caller of these function to limit the number of events processed at once, ensuring the other stack and application_code run quickly. The leftover events will be processed on the next call.