Replies: 2 comments 4 replies
-
There is no standard answer, if data processing is complexe or with a RTOS, processing data in a task give you more flexibility. Otherwise processing in the rx callback has less latency and needs less code. For audio I usually put
Vendor class is different than CDC where data received could be individual packets instead of a stream, in which case a fifo backend is less practical since once put into a fifo it's hard to split them. To deal with packets you can set
The next transfer will be scheduled once there is enough space in the rx fifo or fifo is disabled. But bulk transfer (used by vendor or cdc class) |
Beta Was this translation helpful? Give feedback.
-
Setting For cdc and midi I now have the same routing in the callback and in a |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello everyone,
I have been using TinyUSB with great pleasure for quite some time now but am sort of struggling to find best practice on how to handle incoming data. My project has a working implementation of CDC, Midi and WebUSB(Vendor) combined based on the many great examples.
At some point I figured out I could use the
rx_cb
functions for these classes instead of having a dedicated_task
function in my main loop, this even seemed to improve incoming buffer handling for all 3 class types.Enter Vendor class, this class includes the previous buffer in the callback, which at first I found strange but accepted as is.
My project is an audio chip driver that converts incoming data to 8 bit parallel writes using an RPi Pico. This requires very small timings to make this work perfect.
The issue I am having is with WebUSB/Vendor class, this seems much slower then CDC due to
async await
overhead and the receive confirmation packet back to the host not being sent until the complete 64 byte packet is processed, I think.I figured out that this was also mainly due to the incoming packets being processed from within the Vendor class callback function. After moving this back into a
_task
function and calling it from the main loop the timing improved a lot.My 2 questions are:
_task
function in the main loop, an_rx_cb
function or even both?In my local codebase I am now running both
_task
functions in the main loop and_rx_cb
functions both using the same code, this seems to work but has me questioning its use.Thanks in advance!
LouD
Links to mentioned code
main loop:
https://github.com/LouDnl/USBSID-Pico/blob/0bd346452f8e332d6bbf3ab42dad17e3d7160469/src/usbsid.c#L691-L693
vendor callback:
https://github.com/LouDnl/USBSID-Pico/blob/0bd346452f8e332d6bbf3ab42dad17e3d7160469/src/usbsid.c#L421-L439
vendor task example:
Beta Was this translation helpful? Give feedback.
All reactions