-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add optional hooks for DCD and HCD events #2303
Conversation
These are intended to allow bare metal platforms with one-shot scheduling capabilities to schedule the TinyUSB task handlers whenever they know there is work for them to do. Signed-off-by: Angus Gratton <angus@redyak.com.au>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you very much, this is a great idea and I really like it. Though I would like to tweak it to use weak callback function to be consistent with the rest of API. e.g
void tud_event_hook_cb(const void* event, bool in_isr) _weak
void tuh_event_hook_cb(const void* event, bool in_isr) _weak
The reasson to change to void*
is dcd_event_t/hcd_event_t type are not public (not included with tusb.h).
Let me know if this suggestion make sense to you.
That's great, thanks! Would you like me to update the PR to change the hooks? Probably the "event" parameter can be removed from the hook. I added it on a whim as they're "free" with a macro, but I can't think of a use case so it can probably be removed. I guess passing through "in_isr" is still potentially useful, though. |
Yeah, please do it when you have the time.
Yeah, you are right, application does not have any usage with internal data. Maybe we can change it to have rhport, eventid (header of the event) is better. I don't know if applications ever need that but maybe useful some cases especially rhport when there could be multiple host controllers. void tud_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr) _weak
void tuh_event_hook_cb(uint8_t rhport, uint32_t eventid, bool in_isr) _weak |
actually, since I am working on PRs, I could do it just now, if you haven't started thge update yet. |
I haven't, so feel free if you have time. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all is good now, thank you very much for the PR
@hathach Sorry I didn't reply earlier, that looks great thank you! |
All is good. |
These are intended to allow bare metal platforms with one-shot scheduling capabilities to schedule the TinyUSB task handlers whenever they know there is work for them to do.
I've been experimenting with this approach for MicroPython, where we don't usually have an RTOS but we do have scheduling capability. Selectively scheduling
tud_task_ext()
to run when we know there are events in the queue reduces latency for processing, while also avoiding the overhead of pollingtud_task_ext()
when there may not have been any USB activity.(For context, see micropython/micropython#12846 - that PR uses a linker wrap around
dcd_event_handler
to hook it. If this PR is accepted then we can change to using the new macro for the hooks.)Thanks for all your work on TinyUSB, it's a fantastic library!