USB frame Format

Source: Internet
Author: User
Tags ack

http://blog.csdn.net/myarrow/article/details/8484113

0. Basic Concepts

A "Transmission" (Control, batch, interrupt, etc.): consists of multiple "transactions";

A "Transaction" (in, Out, SETUP): consists of one or more "Packet".

The USB data is transmitted between the host software and the USB device-specific endpoint. The association between "host software" and "USB device-specific endpoint" is called "pipes". A USB device can have multiple pipelines (pipes).

1. Package (Packet)

Package (Packet) is the basic unit of information transmission in a USB system, all data is packaged and transmitted on the bus. The data is transmitted on the USB bus in package units, and the package can only be transmitted within the frame. The high-speed USB bus has a frame period of 125us, full-speed and low-speed USB bus with a frame period of 1ms. The start of the frame is represented by a specific package (SOF package) with EOF at the end of the frame. EOF is not a package, but a level state that does not allow data transfer during EOF.
Note: Although the high speed USB bus and the full speed/low speed USB bus frame period is not the same, but the SOF packet frame number increase speed is the same, because in the high-speed USB system, the SOF packet frame number is actually obtained is a high 11 bits of the counter, the lowest three bits as a micro-frame number is not used, Therefore, the frame number of the increase period is also 1mS.

What is the situation on the USB bus?

The packet is the smallest unit of data transfer on the USB bus and cannot be interrupted or interfered with, or an error will be raised. Several packets comprise a single transaction transfer, and one transaction transmission cannot be interrupted, and several packets belonging to a single transaction transfer must be contiguous and cannot be completed across frames. One transmission consists of one to multiple transaction transports, which can be done across frames.

The USB packet consists of five parts, the synchronization field (sync), the package identifier field (PID), the data field, the Cyclic redundancy check field (CRC), and the Package End field (EOP), the basic format of the package, such as:

1.1 PID type (i.e. package type)

1.2 Token Packets

This format applies to In, out, SETUP, PING.

PID Data transmission Direction

In Device->host

Out Host->device

SETUP Host->device

PING Device->host

1.3 Start-of-frame (SOF) Packets

The SOF package is sent to device by host.
1) for Full-speed bus, every 1.00 ms±0.0005 MS is sent once;
2) for high-speed bus, send once every 125μs±0.0625μs;
The SOF package is composed as shown in:

1.4 Data Packets

There are four types of packets: DATA0, DATA1, Data2,and mdata, and are differentiated by PID. DATA0 and DATA1 are defined to support data toggle synchronization.

1.5 Handshake Packets

ack: for in transactions, it will be issued by the host, and it will be issued by the device for out, setup, and ping transactions.

Nak: in the data phase, for in transactions, it will be issued by the device, and in the handshake phase, it will also be emitted by the device for out and ping transactions, and the host never sends a NAK packet.

2. Transactions (Transaction)

The processing of a single receive or send of data information on USB is called transaction processing (Transaction), namely: the delivery of service to an endpoint. A transaction consists of a system packet, which consists of which packet, depending on the specific transaction. May consist of the following packages:

• One token packet

• Optional Data Pcket

• Optional Handshake packet

• Optional Special packet

2.1 input (in) transaction processing

Input transaction processing: Represents the process by which a USB host receives a packet from a USB device on the bus.

• "Normal" input transaction processing


• Input transaction processing When "device is busy"


• Input transaction processing when "Device error" occurs

2.2. Output (out) transaction processing

Output transaction: Represents the process by which a USB host outputs a packet to a USB device on the bus.

• "Normal" output transaction processing

• Output transaction processing for "device Busy"

• Output transaction with "Device Error"

2.3 Provisioning (Setup) transaction processing

• "Normal" set-up transaction processing


• Set up transaction processing for "device Busy"


• "Device Error" setting transaction processing

3. USB Transfer Type

In the transmission of USB, 4 types of transmission are defined:

• Controlled transmission (control Transfer)

• Interrupt transmission (Interrupt Transfer)

• Bulk Transfer (Bulk Transfer)

• Synchronous transmission (isochronous)

3.1 Controlled transmission (control Transfer)

The control transmission consists of two or three phases:

1) Establishment phase (Setup)

2) Data phase (no data control without this stage)

3) State stage (status)

• Each phase consists of one or more (data phase) transactional transmissions (Transaction).

Control data is used by USB system software to configure the device (at enumeration time), other driver software can choose to use control transfer to achieve specific functions, data transmission is not lost.

3.1.1 Establishment phase

The host obtains configuration information from the USB device and sets the device's configuration values. The data exchange during the setup phase includes the Setup token packet, the DATA0 data packet immediately following it, and the ACK handshake packet. Its role is to perform a set (ambiguous) data exchange and define the content of this control transmission (i.e., the number of data packets in or out of data stage, and the direction of transmission, which have been set at the setup stage).

3.1.2 Data phase

According to the direction of data transmission, the control transmission can be divided into 3 kinds:

1) control read (read USB descriptor)

2) control write (configure USB device)

3) No Data control

Data transfer phase: Used to transfer the information between the host and the device.

• Control Read

is the data USB device descriptor that reads data from the device to the host. This process is shown in "Control Read". For each data packet, first, the primary opportunity is to send an in token packet, indicating that the data is to be read in. The device then passes the data back to the host through the DATA1/DATA0 data packet. Finally, the host responds in the following way: When the data is received correctly, the host sends an ACK token packet, and when the host is busy, the Nak handshake packet is issued, and when an error occurs, the host issues a stall handshake message packet.

• Control Write

is to upload data from the host to the device, the data transmitted is the configuration information for the USB device, the process is shown in the figure "Control Wirte" below. For each data packet, the host sends out an out token packet indicating that the data is to be sent out. The host then passes the data through the DATA1/DATA0 data packet to the device. Finally, the device responds in the following way: When the data is received correctly, the device sends an ACK token packet, and when the device is busy, the device issues a NAK handshake packet, and when an error occurs, the device issues a stall handshake message packet.

3.1.3 State phase

State phase: The process used to represent the entire transmission has completely ended.
The direction of the state phase transmission must be the opposite of the data phase, that is, the in token packet, which should be an out token packet, whereas the original is an out token packet, and this phase should be an in token packet.

For control read, the host sends out token packets, followed by a 0-length DATA1 packet. At this point, the device will also make corresponding actions, send ACK handshake packets, NAK handshake packets or stall handshake packets.

Relative to the "control write" transport, the host sends an in token packet, then the device sends out a 0-length DATA1 packet that represents the completion status stage, and the host then makes the corresponding action: Send ACK handshake packet, Nak handshake packet, or stall handshake packet.

3.2 Bulk Transfer (Bulk Transfer)

• Used to transfer large amounts of data, requiring no error in transmission, but no time requirement for printers, storage devices, etc.

• Bulk transfer is a reliable transmission that requires a handshake packet to indicate the result of the transmission. If the data volume is large, the transmission of all data will be carried out using multiple batches of transactions, and the PID of the packet in the transmission process is DATA0-DATA1-DATA0-... To ensure the synchronization of the sending and receiving sides.
The • USB allows transmission errors of up to 3 consecutive times, retries the transmission, and, if successful, zeros the error count counter, or accumulates the counter. After more than three times, HOST considers the endpoint to function incorrectly (STALL), discarding the transfer task for that endpoint.
• One-time bulk transfer (Transfer) consists of 1 times to multiple bulk transaction transfers (Transaction).
• Flip Sync: Send end according to DATA0-DATA1-DATA0-... The sequence of packets sent, only a successful transaction transfer will result in PID rollover, that is, the sending side will only reverse the PID after receiving an ACK, send the next packet, or retry the transaction transfer. Similarly, if the received packets are found not to be flipped in this order, such as two consecutive DATA0 received, the receiver considers the second DATA0 to be the retransmission of the previous DATA0.

It performs "error detection" and "retransmission" at the hardware level to ensure "accurate" transmission of data between host and device, i.e. reliable transmission. It consists of three packages (i.e. in transaction or out transaction):

1) Token

2) data

3) handshake

1) for in Token (ie: in Transaction)

ACK: Indicates that host received the data correctly

Nak: Indicates that the device is temporarily unable to return or receive data (e.g., device busy)

stall: Indicates that the device is permanently stopped and requires host software intervention (e.g., device error)

2) for Out Token (ie: Out Transaction)

If the received packet is incorrect, such as a CRC error, device does not send any handshake packets

Ack:device has received the packet correctly and notifies host that it can send the next packet sequentially

Nak:device has received the packet correctly and notifies the host to retransmit the data due to Device temp status (such as buffer full)

stall: Indicates that device endpoint has stopped and notifies host that it is no longer re-transmitted

3) Bulk read-write sequence

That consists of a system in transaction or out transaction.

3.3 Interrupt Transmission (Interrupt Transfer)

The interrupt transport consists of an in or out transaction.

Interrupt transfer is the same as bulk transfer, except that Ping is not supported on the process. The difference between them is that the end point of the transaction is different, the maximum supported packet length is different, the priority is different, and so on, something that is transparent to the user.
When a host schedules an interrupt transfer task, it initiates an interrupt transfer based on the query interval specified in the corresponding interrupt endpoint descriptor. Interrupt transmission has a higher priority, after synchronous transmission.
The same interrupt transmission also adopts the mechanism of PID rollover to ensure the synchronization of the receiving data. Flowchart for interruption of transmission.

The interrupt transfer method is always used to query the device to determine whether there is data that needs to be transmitted. The direction of the interrupt transmission is therefore always from the USB device to the host.

The DATA0 or DATA1 contains the interrupt information, not the interrupt data.

3.4 Synchronous Transmission (isochronous Transfer)

1) It consists of two packages:

1) Token

2) data

Synchronous transmissions do not support "handshake" and "retransmission capabilities", so it is unreliable.

Synchronous transmissions are unreliable transmissions, so it does not have a handshake package and does not support PID flipping. The synchronization transport has the highest priority when the host is scheduled for transaction transfers.

Synchronous transmission is suitable for data that must arrive at a fixed rate or arrive at a specified time and can tolerate occasional errors. Real-time transmission is commonly used in MAK
Air, horn, UVC camera and other equipment. Real-time transmission requires only token and data two packet stage, no handshake packet, so data transmission will not be re-transmitted.

Isochronous data is continuous and real-time in creation, delivery, and consumption. Timing-relatedinformation is implied by the steady rate at which isochronous data is received and transferred. Isochronousdata must is delivered at the rate received to maintain its timing. In addition to delivery rate, Isochronousdata may also is sensitive to delivery delays. For isochronous pipes, the bandwidth required is typicallybased upon the sampling characteristics of the associated FUNCTI On. The latency required is related to thebuffering available at each endpoint.

A Typical example of isochronous data is voice. If the delivery rate of these data streams are not maintained,drop-outs in the data stream would occur due to buffer or Fram e underruns or overruns. Even if data isdelivered at the appropriate rate by USB hardware, delivery delays introduced by software may degrade appli Cations requiring real-time turn-around, such as telephony-based audio conferencing.

The timely delivery of isochronous data is ensured at the expense of potential transient losses in the data stream. In the other words, the any error in electrical transmission are not corrected by hardware mechanisms such as retries.  In practice, the core bit error rate of the USB was expected to being small enough not to being an issue. USB isochronous data streams is allocated a dedicated portion of USB bandwidth to ensure so data can be delivered at th e desired rate. The USB is also designed for minimal delay of isochronous data transfers.

USB Frame Format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.