usb gadget 如何知道主机期望 IN 传输?
How does usb gadget knows the host expects IN transfer?
我正在使用gadgetfs开发简单的环回,但我有点
对 gadgefs 如何知道主机启动了 IN 传输感到困惑。
Gadgetfs 在端点上使用 read/write,以我的理解,它只能:
在 OUT 端点文件描述符上使用 "read" 时 - 接受来自主机的新传输
到设备。
在 IN 端点文件描述符上使用 "write" 时 - 开始从设备到主机的传输。
(1)上面看似简单易懂,但是我有
对(2)的误解:
难道只有当
主机发起交易(根据 USB 标准)?
如果是这样,那么小工具如何知道主机发起了一个
IN 端点中的事务,并期望此时进行传输?
小工具将有一个 USB 设备控制器,用于处理来自 USB 主机控制器的所有请求。所以 GadgetFS 的工作是在设备控制器驱动程序的帮助下填充端点缓冲区。以下是事件的顺序 -
- 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
这是整体步骤。您可以查看控制器规格以了解更多详细信息。
EHCI 和 XHCI 的这些步骤大致相同。
请记住,所有事务都由设备控制器处理,application/GadgetFS 有一项工作来填充 EP 指向的缓冲区。
我正在使用gadgetfs开发简单的环回,但我有点 对 gadgefs 如何知道主机启动了 IN 传输感到困惑。
Gadgetfs 在端点上使用 read/write,以我的理解,它只能:
在 OUT 端点文件描述符上使用 "read" 时 - 接受来自主机的新传输 到设备。
在 IN 端点文件描述符上使用 "write" 时 - 开始从设备到主机的传输。
(1)上面看似简单易懂,但是我有 对(2)的误解:
难道只有当 主机发起交易(根据 USB 标准)?
如果是这样,那么小工具如何知道主机发起了一个 IN 端点中的事务,并期望此时进行传输?
小工具将有一个 USB 设备控制器,用于处理来自 USB 主机控制器的所有请求。所以 GadgetFS 的工作是在设备控制器驱动程序的帮助下填充端点缓冲区。以下是事件的顺序 -
- 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
这是整体步骤。您可以查看控制器规格以了解更多详细信息。 EHCI 和 XHCI 的这些步骤大致相同。
请记住,所有事务都由设备控制器处理,application/GadgetFS 有一项工作来填充 EP 指向的缓冲区。