When Intel announces the USB standard transfer rate to 480Mbps in the USB 2.0 protocol, you may still be confused for USB. This brief map introduces you to the USB interface and USB protocol in detail from a relatively popular angle.
USB is an abbreviation for UNIVERSAL SERIAL BUS. It is a cable bus that can communicate with multiple periphery with a USB interface at the same time. These are connected to the peripherals on the computer share the bandwidth of the USB. The timing process mechanism of the USB truly implemented the computer peripherals in the sense of hardware.
If you pay attention to the current peripheral of the current market, you will find that the products that use USB devices are gradually increased. Keyboard, mouse, modem, joystick, speaker, scanner, etc. The interface appears, the development momentum of the USB device is like the day.
This article will discuss USB from the perspective of technology. For a practical part of it, please refer to this article No. 5, 7 and 11 of this article.
A computer-based USB system can be divided into three parts at system level: USB host (USB Host), USB Device (USB Device) and USB connection.
The so-called USB connection actually refers to a method of communicating with a USB device and a USB host. it includes:
● Topology of the bus (from a multi-point network form): the mode of the pending and host connection;
● The relationship between the layers: The division of labor and cooperation between the components of the USB system are completed by a specific USB task;
● Data flow mode: the data transfer method of the USB bus;
● USB's "time-multiplex": Because USB provides a shared connection method, in order to perform synchronous transmission of data, the transfer and processing of the USB must use a constant processing mechanism.
First, USB bus topology
The USB bus topology is shown in Figure 1, in the Tree topology of the USB, the USB hub (HUB) is in the center position of the node. Each of the functional components and the USB host form a unique point-to-point connection, and the USB HUB is connected to the USB functionality to the host provides an extended interface. With this tree topology, USB bus supports up to 127 USB peripherals to connect to the host computer system.
Figure 1 USB bus topology
A USB system can only have a host, and a component for the USB device to connect the host system to the host interface is referred to as a USB host controller. The USB host controller is a complex consisting of hardware, software, and firmware. A motherboard with a USB interface typically integrates a component called root hub, which provides a host to a plurality of USB extensions that can connect to other USB peripherals, and we usually see the USB interface to see on the motherboard is rob Hub is provided.
The USB device can be divided into two types: USB HUB and USB functional devices (Function Device).
As the extension of the USB bus, USB HUB (Figure 2) must meet the following features:
● Provide scalable downstream and upstream ports for our own and other peripheral connections;
● Support the power management mechanism for USB bus;
● Supports the detection and recovery of the bus transmission failed;
● You can automatically detect the connection and removal of the downlink port peripheral, and report to the host;
● Support for low speed peripherals and high-speed peripherals.
From the above requirements, USB HUB consists of two parts: HUB Repeater and Hub Controller. The HUB transponder responds to the host's settings for USB peripherals, and the detection, classification of the USB function components connected to it downlink, and transmits its port information to the host, which is also responsible for The error handling of "bus transmission failed"; the HUB controller provides physical mechanisms for data transmission between hosts to HUB. As we are well known, the USB HUB has a "BIOS" system to indicate your identity to the host. This ROM on the USB HUB, which makes the host to configure this USB HUB via USB characterization, and monitors each of its ports. The USB function device can provide a USB device for the host system, such as a USB ISDN modem, or a USB interface digital camera, USB keyboard or mouse.
Figure 2 Structure of USB HUB
Figure 3 A typical USB functional device structure block diagram
The USB functional device is used as a USB Peripheral, which must be fully compatible with the USB protocol and can respond to standard USB operations. Similarly, it is essential for the "BIOS" system that indicates that you identity is also essential for USB peripheral, which is called a protocol layer on a USB peripheral. In a physical mechanism, a USB peripheral can be composed of four parts (Figure 3):
● For implementation and USB protocols are compatible with the SIE section;
● For storage device characteristics, store protocol layers (ROM) that implements peripheral special functional programs and manufacturers information;
● Sensors for implementing peripheral functions and DSP portions for data on data;
● Connect the peripheral to the interface part of the host or USB HUB.
Depending on the transmission rate, the USB device is divided into two high speeds and low speeds. The standard transmission rate of low speed peripheral is 1.5Mbps, and the standard transmission rate of high-speed peripherals is 12 Mbps. All USB HUBs are high-speed peripherals, and the functional components can be designed to different transmission rates depending on the specific situation of peripherals. For example, the peripherals of audio transmission can be used to use 12Mbps transmission rate, and like a keyboard, mouse Such a point input device is designed to be a low speed peripheral. Since the data transfer of USB uses the form of a packet, all USB peripherals connected to the host does not interfere with each other. Unfortunately, all of these USB peripherals must share the USB bandwidth specified in the USB protocol (this bandwidth is 12Mbps in the USB 1.0 protocol), although the USB time-time process mechanism can make limited USB bandwidth between each device Allocation, but if there are two or more high-speed peripherals simultaneously use such a connection method, they will not be able to enjoy the highest USB bandwidth, thereby reducing performance. This is also why Intel is the reason why the USB 2.0 protocol is launched (USB's bus bandwidth in the USB 2.0 protocol is increased to 480Mbps).
Used to implement peripheral to host or USB HUB is a USB cable (Figure 4). In terms of strict sense, the USB cable should belong to the interface part of the USB device. The USB cable consists of four lines, one of which is the power cord VBUS, one is a ground line GND, and the remaining two are data lines (D , D-) for differential signal transmission. The method of driving the data stream into a differential signal is transmitted to effectively improve the signal of the signal's anti-interference capability (EMI). The idea of setting the end resistance at the end of the data line is very clever, so that the connected peripheral is a high speed peripheral or a low speed peripheral, only the peripheral is initially connected, D or D- The signal is high or low. Because for USB protocols, low speed peripherals are required to be connected with a 7.5kΩ grounding resistor in their D-terminal, while high-speed peripherals are also the same resistance in D . At the time of powering, the HUB is easily discriminated by the type of the device according to the state of the D-line and the high-speed peripheral D line of the low speed peripheral, thereby configuring different information for the device. Figure 5 shows a typical high-speed peripheral connection condition. In order to improve the reliability of data transmission, the system's compatibility and standardization, the USB protocol puts a stricter requirement for the USB cable. If the USB cable used for high-speed transmission should not exceed 5 meters, while the cable used for low-speed transmission is two meters, and the electrical resistance of each data line should be standard 90Ω. The USB system can provide a bus power supply that is not higher than 5V, 500mA through the USB cable for its peripherals. Devices that completely rely entirely on the USB cable to provide a power source, as a bus-powered device, and a device with a power source is called a self-driving peripheral. It should be noted that when an peripheral is initially connected, the device's configuration and classification does not use a peripheral self-contained power supply, but the power supplied by the USB cable is in the PowerEd state.
Whether in software or hardware levels, the USB host is in the core of the USB system. The host system (Figure 6) not only contains a USB host controller for communicating with USB peripherals and a USB interface (SIE) for connection, more importantly, the host system is a carrier of USB system software and USB client software.
All in all, the USB host software system can be divided into three parts:
● Customer Software Section (CSW), data exchange between logically and peripheral features;
● USB system software part (ie HCDI), in logic and actual interface as an interface between HCD and USBD;
● USB Host Controller Software Section (ie HCD and USBD), configured to control and manage all USBs of external and hosts, including peripheral SIE portions, USB Data Send Receiver Parts and peripherals Agreement layer, etc.
Figure 4 USB cable Figure 5 High speed peripheral USB cable and resistance connection diagram Figure 6 The structure of the USB host system and the relationship between parts
Second, USB's "Turnover Reuse" and power management
When a USB peripherals are first access to a USB system, the host assigns a unique USB address for the USB peripheral, and as the unique identifier of the USB peripheral (USB system can allocate this address 127), This is called a bus enumeration. USB uses bus listing to dynamically detect peripheral connections and removal during operation, and dynamically assign USB addresses, thereby truly implementing "plug and play" and "hot plug" in hardware in the sense of hardware.
Dynamically distribute bandwidth between all USB channels is one of the features of the USB bus. When a USB peripheral is connected to the connection (Configuration), the host will assign USB bandwidth to the channel of the USB peripheral; and when the USB is removed from the USB system (Detached) or in hanging When the SUSPENDED is status, the USB bandwidth it occupies will be released and shared for other USB peripherals. The bandwidth allocation mechanism of this "Schaduling the USB) greatly increases the USB bandwidth utilization. As an advanced bus mode, USB provides a host-based power management system. The USB system will automatically suspend the device (SUSPEND) when a long time (this time is typically 3.0ms or more), when a USB peripheral is suspended, the USB bus passes USB The cable only provides a current of 500 μA or less, and assigns the USB bandwidth occupied by the peripheral to other USB peripherals. USB's power management mechanism allows it to support advanced features such as remote awakening. When a peripheral is suspended (SUSPENDED), you must first "wake up" (Resume) through the host before you can perform USB operations.
This intelligent power management mechanism for USB makes it particularly suitable for the application of equipment such as laptops.
Third, USB data transmission mode
Figure 7 Frame Start Packet Distribution in USB Data Transmission Figure 8 USB Communication Flow and Channel Figure 9 Synchronous Field Figure 10 PID field
We know that the USB bus is a serial bus, that is, its data is a bit to be transmitted. Although the USB bus is transmitted to packet data packets in the form of these BIT, it is essential. USB 1.0 / 1.1 protocol stipulates that USB's standard pulse clock is 12MHz, while its bus clock is 1 ms, ie 1 ms, and USB devices should generate a clock pulse sequence for a USB cable. This pulse sequence is called a frame start packet (SOF, as shown in Figure 7), the host utilizes SOF to synchronize the transmission and reception of USB data. From this, it can be seen that for a peripheter of a data transfer rate of 12 Mbps, it has a length of 12000bit; and for a low speed peripheral, its length has only 1500 bits per frame. The USB bus does not care about the peripheral data acquisition system and the rate of its processing, whether it is generated or received for what data, it is always transmitted to transmit data in advanced USB standard transmission rates. This requires peripheral manufacturers to set the size of the data to cache data between the data acquisition or receiving system and the USB protocol system (SIE).
In the USB system, the data is transmitted from the host to the peripheral from the host through the USB cable. In the USB protocol, the data transmission mode between the peripheral data source and the host-based data receiving software (or direction) is called a channel (PIPE). The channel is divided into streaming channels (stream pipes) and message PIPEs. The data bandwidth, data transfer mode, and the characteristics of the functional components of the peripheral (such as the direction of the cache size, data transfer, etc.) are related to the data defined. As long as one USB is connected to a connection, a channel will be established between the host and peripherals. For any USB peripheral, it is connected to a USB system and is powered by a USB host by a USB cable, which is built between the USB host and the protocol layer (ROM) of the USB host and peripheral. A message channel called EndPoint 0, this channel is also called a control channel, mainly used for the configuration of the peripheral, and the detection and control command of the external state. The structure of the channel mode allows the USB system to support a peripheral with multiple features (identified by EndPoint 0, EndPoint 1 ... EndPoint N), which can be simultaneously, in different data transfer directions Data transfer on a USB cable does not affect each other (Figure 8). For example, a USB ISDN MODEM, you can have an uploaded channel and a downloaded channel, and work at the same time. To achieve multi-external, multi-channel simultaneously, the USB bus uses the data packet to transmit data and control information.
Each packet in the USB data transfer begins with a synchronization field (Figure 9), and its last two bits start in the PID field. A 8bit pulse sequence immediately after the synchronization field is called PID (packet identification field, as shown in Figure 10), the first four bits of the PID field are used to mark the type of the data package, and the last four digits are pair Four-digit checks. The PID field is divided into tag PID (four types of IN, OUT, SETUP, or SOF), data PID (DATA0 or DATA1), handshake PID (ACK, NAK or STALL) and special PID, etc. The host determines the data type included in a packet based on the type of PID field and performs the corresponding operation.
When a USB peripheral is initially connected, the USB system assigns unique USB addresses for this peripheral, which tagged through the address register (AddR) to ensure that the packet does not transfer to other USB peripherals. 7bit ADDR enables the USB system to address the maximum address of 127 devices (shown in Figure 11). Since a USB peripherals may have multiple channels, there is an additional endpoint field (EndPoint Field, the ENDP) to mark different channels (Fig. 12) after the addr field. All USB peripherals must support the EndPoint 0 channel, tagged with 0000. For high speed devices, you can support 16 channels, while low speed devices can only have one channel outside EndPoint 0.
The data field can contain 0 to 1203Byte data in a USB packet as a central purpose of a USB data transfer (Figure 13). The frame quantity field is included in the frame start packet, and some applications can be used as the synchronization signal of the data.
In order to ensure the correctness of the data packet in the control, block transfer, and interrupt transmission, the CRC check field is referenced in a packet such as tag, data, and frame start (SOF). CRC check (data redundancy check) can give data to 100% correctness.
Figure 11 Addr field of the data package Figure 12 Endpoint field Figure 13 USB data field
↓ Comprehensive understanding of the essence of USB technology (2)