Chapter 2
32
a maximum number of data bytes the endpoint can send or receive in a transac-
tion.
Each USB transfer consists of one or more transactions that can carry data to or
from an endpoint. A USB 2.0 transaction begins when the host sends a token
packet on the bus. The token packet contains the target endpoint number and
direction. An IN token packet requests a data packet from the endpoint. An
OUT token packet precedes a data packet from the host. In addition to data,
each data packet contains error-checking bits and a Packet ID (PID) with a
data-sequencing value. Many transactions also have a handshake packet where
the receiver of the data reports success or failure of the transaction. For USB 3.0
transactions, the packet types and protocols differ, but the transactions contain
similar addressing, error-checking, and data-sequencing values along with the
data.
USB supports four transfer types: control, bulk, interrupt, and isochronous. In
a control transfer, the host sends a defined request to the device. On device
attachment, the host uses control transfers to request a series of data structures
called descriptors from the device. The descriptors provide information about
the device’s capabilities and help the host decide what driver to assign to the
device. A class specification or vendor can also define requests.
Control transfers have up to three stages: Setup, Data (optional), and Status.
The Setup stage contains the request. When present, the Data stage contains
data from the host or device, depending on the request. The Status stage con-
tains information about the success of the transfer. In a control read transfer,
the device sends data in the Data stage. In a control write transfer, the host
sends data in the Data stage, or the Data stage is absent.
The other transfer types don’t have defined stages. Instead, higher-level software
defines how to interpret the raw data. Bulk transfers are the fastest on an other-
wise idle bus but have no guaranteed timing. Printers and USB virtual
COM-port data use bulk transfers. Interrupt transfers have guaranteed maxi-
mum latency, or time between transaction attempts. Mice and keyboards use
interrupt transfers. Isochronous transfers have guaranteed timing but no error
correcting. Streaming audio and video use isochronous transfers.
2WTRQUGUHQT%QOOWPKECVKQP
USB communications fall into two general categories: communications that
help to identify and configure the device and communications that carry out
the device’s purpose. During enumeration, the host learns about the device and