My USB interrupt :
- Gets a SETUP packet,
- Wakes up a thread with a semaphore, which ...
- Parses the SETUP request
- Queues some buffers into the endpoint with the data to send
- The endpoint ISR returns "transfer completed" messages to the thread via a Mailbox
- The thread reads the mailbox and ACK's the transfer to the PC via STATUS stage packet... or perhaps it will queue more buffers if there is more data to send or receive.
You'll probably be happy to know that the shortest request takes about 19µs (with the CPU at 120 MHz). I replaced a huge ugly insane state machine with clean threaded code which is much smaller and also faster !
