How does the USB interface communicate?
We already know that traditional serial ports and parallel ports communicate through handshaking signals, which are usually communicated to the host and peripherals through a handshake signal. We also know that the communication between the two sides can be synchronous or asynchronous communication, the biggest difference is that the synchronous communication interface has a clock signal line.
USB interface is widely used. However, there is no handshake signal and no clock signal in the USB interface, how does it establish a connection between the host and the peripherals? How to Exchange data? In order to understand the communication process of USB interface, the hardware and software structure of USB are introduced first.
1. From the physical structure, the USB system is a star-shaped structure. The USB system consists of three types of hardware devices: A USB host, USB devices (USB device), and a USB hub (USB hub). The physical connection on the USB bus is a layered star topology, in the center of each star topology is the hub hub, between the host and the hub, between the hub and the hub, the hub and the device are point-to-point connections.
USB host manages the USB system, generates a frame of data per millisecond, sends configuration requests to configure, manage, and recover errors on the bus for the USB device. The USB hub is used for device expansion connections, and all USB devices are connected to ports on the USB hub. USB device to receive all packets on the USB bus, through the address domain of the packet to determine whether it is sent to its own packet: if the address does not match, then simply discard the packet; If the address matches, data is transmitted by responding to the USB host's packet.
2. From a logical structure, each USB logical device directly transmits data to the USB host. The USB interface uses a "soft handshake" approach, unlike the traditional interface, which implements a handshake by means of hardware.
The soft handshake mechanism of USB is implemented through three levels of driver, in which the key role is the device driver, which establishes at least one pipeline between the host and the device. There are two types of pipelines: streaming pipes and message pipelines. One of the most important message pipelines is the "default control Pipe", which exists when the device is added to power, providing information about the configuration and status of the device. The communication between the host and the device is achieved through the message pipeline.
The main purpose of the protocol stack driver is to connect the device to the appropriate device driver. Because USB supports a lot of devices, and each specific device has its own corresponding device driver. For a specific device, which driver is used to manage, the protocol stack driver is selected by reading the device descriptor. After selecting the driver, the protocol stack driver also assigns an address to the USB device.
After the pipeline is established, the data transfer control is done by the USB interface driver. Here, the host occupies absolute dominance, and the device can only be "obey orders". When the device events are reported to the host through the message pipeline, the host is waiting to send commands to the device, opening the flow pipeline, sending or receiving packets. The host and the device are transmitted in the form of data packets, which is obviously the same as the way of data transmission on the network, which is an asynchronous data transfer mode.