- 注册时间
- 2012-6-21
- 最后登录
- 2023-2-3
- 阅读权限
- 200
- 积分
- 1163
- 精华
- 0
- 帖子
- 152
|
最近在写一些关于驱动的文章,下面是一段国外关于winusb的原文以及我翻译的文字,参考一下:
Every USB data transfer is between a PC or other USB host computer and a device endpoint. A device endpoint is a buffer that stores received data or data to transmit. Every device must support endpoint zero, which is bidirectional. Additional, optional endpoint addresses each have a number (1-15) and a direction (IN or OUT).
Even though endpoints reside on devices, the USB specification defines endpoint direction from the view of the host PC. An IN endpoint sends data to the PC, and an OUT endpoint receives data from the PC. This naming convention can be confusing when writing code for the device side!
One reason why USB is so versatile is its support for four transfer types, each with different strengths. WinUSB supports control, bulk, and interrupt transfers. Control transfers use endpoint zero. The other transfer types can use endpoints one and higher.
Control transfers provide a structured way to send requests and data and receive responses. Control transfers are the only type that can pass information in both directions in a single transfer. After device attachment, in a process called enumeration, the host computer uses control transfers to learn about the device.
A control transfer has two or three stages. To learn about a newly attached device, the host computer uses control transfers to request data structures called descriptors from the device. In the Setup stage, the host sends the request. In the Data stage, the device sends the requested descriptor. In the Status stage, the host acknowledges receiving the descriptor. A host can also use control transfers to send information to a device in the Data stage, with the device acknowledging in the Status stage. Some requests have no Data stage.
A USB host reserves a portion of the bus bandwidth for control transfers: 10% for low- and full-speed endpoints and 20% for high-speed endpoints. If the bus isn’t busy, control transfers can use more than the reserved bandwidth. But all devices must share the bus, so on a busy bus, a control transfer may have to wait.
The other transfer types don’t have multiple stages and can transfer data for any purpose. On an otherwise idle bus, bulk transfers are the fastest. But bulk transfers have no guaranteed bandwidth, so on a busy bus, bulk transfers must wait. Common uses for bulk transfers are printers and scanners, where quick transfers are nice but not essential.
每个USB传输发生在PC或其它USB主机与设备端点(endjpoint)之间,设备端点是一个收发数据的缓冲区,每个设备必须支持端点零(endpoint 0),端点零是双向的,设备还可以拥有端点1-15,它们是单向的(IN或OUT)。
即使从设备里的端点来看,USB协议还定义了端点的方向(针对PC和其它USB主机来说),输入端点(IN endpoint)是设备向PC(或主机)发数据的端点,输出端点(OUT endpoint)是PC向设备发数据的端点,在写设备端代码的时候很容易引起混淆,一定要注意。
USB是如此有用,一个理由是因为它支持四种传输模式,不同模式支持不同数据长度。WinUSB支持控制传输、批量传输和中断传输。控制传输用端点零,其它类型的传输使用1及1以上的端点。
控制传输提供了一个结构化的方法来发送请求和数据,接收应答和数据,只有控制传输是双向的。当USB设备插入主机后,主机通过控制端点来取得设备相关信息,这一过程叫做枚举。
控制传输有二到三个阶段。为了用于取得最新插入的USB设备设备,主机用控制传输请求设备标准描述符。在Setup阶段,主机发送请求,在Data阶段,设备向主机发送被请求的描述符,在Status阶段,主机分析收到的描述符。在Data阶段,主机也可以用控制传输向设备发送一些信息,接着设备在Status阶段分析这些信息。
USB主机为控制传输保留了一部分总线带宽,全速设备最低10%,高速设备最低20%。如果总线不是很忙,控制传输和以取得更多保留带宽,但是所有设备必须共享总线带宽 ,所以在一个繁忙的总线上,控制传输可能需要等待。
其它类型传输可传输任何目的的数据,传输过程也没有被划分成这么多的阶段。.... |
|