Reputation: 1712
I am developing simple loopback using gadgetfs, but I am a bit confused as to how gadgefs knows that host initiated IN transfer.
Gadgetfs use read/write on endpoints, so as to my understanding, it can only:
When using "read" on OUT endpoint file descriptor - accept a new transfer from host to device.
When using "write" on IN endpoint file descriptor - start transfer from device to host .
(1) above seems to be simple to understand, but I have misunderstanding about (2):
Isn't it that a write into IN endpoint should be accepted only when host initiated a transaction (according to usb standard) ?
If so, than how does gadget knows that host initiated a transaction in the IN endpoint, and expects a transfer at this moment ?
Upvotes: 0
Views: 1055
Reputation: 925
Gadget will have a USB device controller which handles all the requests from the USB host controller. So the job of the GadgetFS is to fill the Endpoint buffers with the help of device controller driver. Following is the sequence of events -
- Application running in USB gadget has some data to transfer to host
- Application uses GadgetFS interface to transfer the data
- GadgetFS then uses standard USB device controller driver API to send the data to the controller
- USB device controller driver take the buffer address passed down by gadgetFS and add it in Asynchronous list of the targeted controller Endpoint(EHCI controller)
- When device controller received "IN" token request from the controller, your device controller will read the EP details from the token and schedule the corresponding EP for data transfer.
- Controller DMA then reads the data from the address of the buffer which was added in step 4
This is the overall steps. You can check the controller spec for more details. These steps are more or less same for EHCI and XHCI.
Remember that all the transactions are taken care of by the device controller and the application/GadgetFS has a job to fill up the buffers pointed by EP.
Upvotes: 1