USB笔记 USB2.0 包格式Packet Formats 令牌包Token Packets
说明
介绍的是USB 2.0协议中包格式(Packet Formats)的令牌包(Token Packets)。
介绍
令牌(Token)由一个指定IN、OUT或SETUP包类型的PID字段,ADDR字段和ENDP字段组成。PING特殊令牌包的字段也与令牌包相同。对于OUT和SETUP事务(transactions),地址(address)和端点(endpoint)字段用于标识将接收后续数据包(Data packet)的端点(endpoint)。对于IN事务,这些字段标识了哪个端点应该传输数据包(Data packet)。对于PING事务,这些字段标识了哪个端点将以握手包(handshake packet)进行响应。只有主机(host)可以发出令牌包。IN PID定义了一个从设备到主机的数据事务(Data transaction)。OUT 和 SETUP PID 定义了从主机到设备的数据事务。PING PID定义了从设备到主机的握手事务(handshake transaction)。
令牌包(token packet)的包格式(Packet Formats)如图所示:
令牌包有一个5bit的CRC,它覆盖了地址和端点字段,如上图所示。CRC不包括PID,PID有自己的校验字段。令牌和SOF包由EOP在3个字节的包字段之后进行分隔。如果一个包解码为其他有效的令牌或SOF,但在3个字节后没有以EOP结束,则必须认为它是无效的,并被接收器忽略。
下面进行介绍。
OUT
OUT事务(OUT transaction)的地址和端点号,OUT事务是从主机到设备的事务。
Type | Value |
---|---|
PID Type | Token |
PID Name | OUT |
PID<3:0> | 0001B |
PID value<7:0> | 0xE1 |
Transfer types used in | control, bulk, interrupt, isochronous |
Transaction Type | OUT |
Source | host |
Bus Speed | high, full, low |
Description | Address + endpoint number in host-to-function transaction |
OUT在事务中的位置
下面看下OUT在事务Transaction中的位置
-
Bulk 和Control Transfer的OUT Transaction
-
Interrupt Transfer的OUT Transaction
-
Isochronous Transfer的OUT Transaction
OUT示例
- OUT ACK
- OUT NAK
- OUT NYET
IN
IN事务(IN transaction)的地址和端点号,IN事务是从设备到主机的事务。
Type | Value |
---|---|
PID Type | Token |
PID Name | IN |
PID<3:0> | 1001B |
PID value<7:0> | 0x69 |
Transfer types used in | control, bulk, interrupt, isochronous |
Transaction Type | IN |
Source | host |
Bus Speed | high, full, low |
Description | Address + endpoint number in function-to-host transaction |
IN在事务中的位置
下面看下IN在各种事务Transaction中的位置
-
Bulk, Control和Interrupt Transfer的IN Transaction
-
Isochronous Transfer的IN Transaction
IN示例
- IN ACK
- IN NAK
- IN STALL
SETUP
SETUP事务(SETUP transaction)的地址和端点号,SETUP 事务是从主机到设备的事务,用于控制管道(control pipe)。
Type | Value |
---|---|
PID Type | Token |
PID Name | SETUP |
PID<3:0> | 1101B |
PID value<7:0> | 0x2D |
Transfer types used in | control |
Transaction Type | SETUP |
Source | host |
Bus Speed | high, full, low |
Description | Address + endpoint number in host-to-function transaction for SETUP to a control pipe |
SETUP在事务中的位置
下面看下SETUP在各种事务Transaction中的位置
- Control Transfer的SETUP Transaction
SETUP示例
SOF
帧开始包Start-of-Frame (SOF) packets用于SOF标记和帧号。
Type | Value |
---|---|
PID Type | Token |
PID Name | SOF |
PID<3:0> | 0101B |
PID value<7:0> | 0xA5 |
Transfer types used in | Start of Frame |
Transaction Type | all |
Source | host |
Bus Speed | high, full, low |
Description | Start-of-Frame marker and frame number |
帧开始包Start-of-Frame (SOF) packets由主机(host)发出,对于全速总线(full-speed bus),标称速率为1.00 ms±0.0005 ms,对于高速总线(high-speed bus),标称速率为125 µs±0.0625 µs。具体参见USB 2.0 帧开始包Start-of-Frame Packets。
PING
bulk/control端点的高速(High-speed)流控制(flow control)探测。只有High-speed OUT才支持。
Type | Value |
---|---|
PID Type | Special Token |
PID Name | PING |
PID<3:0> | 0100B |
PID value<7:0> | 0xB4 |
Transfer types used in | control, bulk |
Transaction Type | control write, bulk OUT |
Source | host |
Bus Speed | high |
Description | High-speed flow control probe for a bulk/control endpoint |
当主机认为端点可能已准备就绪时,主机可以发送PING令牌包(PING token packet),如果端点已经准备好接收下一个数据包,那么端点将返回ACK,或者如果端点未准备就绪,则返回NAK或STALL。
PING在事务中的位置
下面看下PING在各种事务Transaction中的位置
- Bulk和Control Transfer的PING Transaction
PING示例
- PING ACK
- PING NAK
附录
Universal Serial Bus Specification Revision 2.0
- Bulk Transactions
2. Control SETUP Transaction
- Interrupt Transaction
- Isochronous Transaction
参考资料
Universal Serial Bus Specification Revision 2.0
USB Complete, 5th Edition
本文链接:https://blog.csdn.net/u012028275/article/details/115045877