Comprehensively understand the essence of USB technology (2)

xiaoxiao2021-03-06  103

This article describes the data transfer mode of the USB bus, the format of the USB packet, and the composition and structure of USB peripherals.

First, the format of USB packet

In the USB system, there are four forms of packet-tagged packets (Tata Packets), and a SOF Packets (SOF Packets), and Handshake Packets.

1. The tagged data package consists of four fields of PID, Addr, Endp, and CRC5 (Figure 1). It is divided into input Type (IN), Output Type (OUT) and Set Types (Setup) because of the different PID fields. The tag packet is in front of the DATA packet of each USB transmission to indicate the type of USB operation (PID field tag), the object (indicated in the addr, and ENDP field). The 5bit of the CRC check bit is used to ensure the correctness of the tag packet.

2. We have pointed out that the USB host will generate a SOF USB frame synchronization signal every 1 ms, and the SOF packet contains the actual content of this pulse sequence (Fig. 2), which is filed by the PID field in the SOF format, frame The quantity field and the 5bit of the CRC check code are composed. The host uses the SOF packet to synchronize data transmission and reception.

3. DATA packets used to transmit real data (Figure 3), because the difference between PID can be divided into DATA0 and DATA1. Data0 is an even packet, and DATA1 is aqi packet. Data packets The parity classification of the data package is easy to data, and the DATA packet for controlling the transmission is always transmitted in DATA0.

4. Handshake data package only contains a PID field (Figure 4), the PID in the form of the ACK indicates that the USB transmission does not have an error, and the data has been successfully transmitted; and the handshake packet in the form of NAK indicates that the USB transmission is due to this USB transmission CRC calibration error or other reasons fail, so that the host can perform data retransmission; STALL form response to the host report peripherals at this moment in the suspend state and cannot complete the transmission of data.

It should be noted that each packet has two Bit wide EOP fields as the flag ended as the packet (Fig. 5), and the EOP appears to D and D- in the difference mode signal. For high speed USB peripherals, this pulse width is between 160 and 175 ns, while the low speed device is between 1.25 to 1.50 μs. Regardless of whether there is other packets, the USB cable will follow 1bit bus space after the EOP field. USB host or peripheral uses EOP to determine the end of a packet.

Figure 1 Marking the components of the packet Figure 2 SOF Packet Format Figure 3 Data Packet Format Figure 4 Handshake Packet Figure 5 EOP field in voltage in different mode signals

Second, the data transfer mode of the USB bus

As mentioned earlier, each USB channel corresponds to a specific USB transmission mode, and USB peripherals can specify different USB transfer modes for USB channels depending on different needs. The USB bus supports four data transfer modes:

1. Controlling the transmission mode (Fig. 6), controlling the device for configuring the device when the peripheral is initially connected; real-time detection of the external state; transmission of the control command, etc., can also be used after the device configuration is completed Other purposes. The Endpoint 0 channel can only be controlled.

2. Block Transfer Mode (Figure 7), block transfer for bulk, non-real-time data transmission. A block transmission mode can be used as a USB scanner to ensure that data is continuously transmitted in real time in the hardware level. The USB bandwidth occupied by the channel of the block transfer method has the highest priority in real-time bandwidth allocation.

3. Synchronous transmission mode (Figure 8), synchronous transmission applies to applications requiring data continuously, real-time, in a fixed data transmission rate, transmission and consumption, such as digital video recorders, and the like. In order to ensure the real-time performance of data transmission, the synchronous transmission does not perform the retry of data errors, nor does it respond to a handshake packet at the hardware level, which is likely to make data errors in the data stream. To ensure that the chances of fatal errors in the synchronous transmission of data are small tolerance, the delay of data transmission does not affect the performance of peripherals, manufacturers must select a suitable bandwidth for channels that use synchronous transmission. (You must make a weighing between speeds and qualities). 4. Interrupt transmission mode (Figure 9) For those small batch, point, discontinuous data transmission applications, such as mice, keyboards, joysticks, etc. for human-computer interaction, the most suitable way to interrupt transmission is the most suitable of.

Figure 7 Block Transferring Flow Figure 8 Synchronous Transferring Flow Chart 9 Interrupting Transport

Third, the composition and structure of USB peripherals

This article is not intended to discuss USB peripherals (the USB peripherals mentioned in this section all refer to USB functional devices), and only want to introduce the general composition of USB functional devices to help readers understand USB peripherals. Basic hardware components to understand the work processes and principles of USB peripherals.

The sensing device and DSP constituting peripherals are different because the specific applications of peripherals are different. For example, for a CMOS digital camera (such as Creative Webcam), its CMOS photocoupler and its DSP part do not change because of what kind of interface mode (such as early computer eyes use ECP's parallel enhancement mode To perform transmission of image data, almost all USB interfaces now). Therefore, the focus of this article is to explain the portion of the USB peripheral interface, that is, USB Device MicroController (USB device microcontroller). Figure 10 shows a detailed composition block diagram of a USB peripheral bus interface.

The USB bus is transmitted in a different mode driving, but the USB protocol must be encoded using NRZi coding before the packet transmission. Of course, in USB peripherals, it is essential for decoding devices. NRZi's code protocol is actually very simple. It uses the principle of "1", and the principle of "0" hop (Figure 11), and NRZi decoding uses the opposite operation. In order to ensure that there is enough signal change in the data stream, the USB protocol specifies the principle of Bit Stuffing (filling), that is, if the six-digit data "1" continuously appears in the signal stream, one must be inserted every six digits. "0", then enter NRZI code. Figure 12 is a string of raw data and its filling and filled with the NRZI encoded data format comparison.

Figure 10 Detailed composition block of the USB peripheral bus interface Figure 11 NRZI Data Encoding Figure 12 Raw data and filling and filled with data format after NRZI encoding

SIE (Serial Interface Engine) is one of the most important hardware components of USB peripherals, which consists mainly of four parts:

1. Hardware is used to complete NRZI / decoding and plus / decoding operation, NRZI / bit buffing, and nrzo / bit unstuffing parts;

2. CRC check code generated on the hardware and the CRC Check & Generator section of the CRC check for the packet;

3. Used to convert parallel data into a USB serial data, a Packet ENCode, which transforms the USB packet sent by the host into a string / and conversion section (Packet Decode) that can be identified;

4. Detect and produce some of the SOP (the synchronization field of each packet) and the EOP signal.

USB peripherals use a ROM to store some important information about the peripheral work, which is called USB's protocol layer (which stores such as manufacturer identification numbers, but the type belonging to this peripheral (is HUB or FUNCTION, is a low speed or high-speed device), and the power management and other conventional information, but more importantly, the device type, device configuration information, description of the device configuration information, functional components, interface information, etc. are also stored. "Descriptors )The way. The USB host uses control transmission to access this information by establishing an EndPoint 0 channel between the protocol layer and the host between the peripherals. The feature word uses the structure and code arrangement specified by the USB protocol (see the USB protocol standard for details on the feature word). Manufacturers can also store specific programs or information in the remaining space of the ROM to help peripherals complete specific work. The protocol layer is a USB peripheral to be properly identified and configured by the host, and the premise of working properly. It can be said that the protocol layer is a firmware center of a USB peripheral. We know that data sampling rate is different from different applications of sampling accuracy and use, such as for audio applications, you can use a sample rate of 22.05 kHz or 44.1 kHz, and this clock is not corresponding to the USB standard clock. Thus in practical applications, in order to ensure that the collected data is unable to packed and transmit, the FIFOS must be established between SIE and data acquisition components (for peripherals such as speakers or printers), to perform data Cache. For peripherals with block transfer and synchronous transmission, the role of FIFOS is particularly important. For example, a USB digital camera (now there are many types of products on the market), we assume that its CCD is 400 × 300 pixels, so in order to ensure proper compression, transmission, and receipt, until the later solution Compression and processing, in dynamic acquisition, FIFOS should store at least one frame image, that is, the FIFOS is required to have a capacity of 400 × 300 = 12 kb.

In USB peripherals, it is essential for implementing the USB transmission receiving part of the USB cable seamlessly, it is not only necessary to connect to the USB cable not only on the electrical and physical level, but also to complete Differential motion or separation of the data packet. The above is a brief description of the hardware composition of the USB peripheral interface, so how these hardware works with work and interacting with the host's hardware and software during the completion of USB data transmission, to complete data transmission?

As mentioned earlier, the USB bus uses a bus to mark and manage the state where the peripherals is located. When a USB peripheral is initially connected to the USB system, the initialization is completed by 8 steps:

1. OSB Peripheral Connected HUB (Root Hub or Extended HUB) detects the connected USB peripherals and automatically notifies the host, and changes in its port status, which is still disabled (DISABLED) status;

2. The host confirms the connection of the peripheral by querying the HUB;

3. Now, the host already knows that a new USB peripheral is connected to the USB system, then it activates the port of this HUB and sends a reset to the HUB.

4.Hub keeps the reset signal 10ms, providing 100mA bus current for the peripheral connected to this port, which is in the Powered state, and all of its registers are empty and point to the default address;

5. Before the peripheral assignment to the unique USB address, his default channel uses the host's default address. The host then understands the actual maximum data payload width used by the peripheral default channel by reading the feature word of the peripheral protocol layer (the length of the data field defined in the DATA0 packet in the feature word in the feature word. ).

6. The host assigns a unique USB address to the external setting and makes it in the Addressed status;

7. The host starts using the EndPoint 0 channel reads the device configuration features stored in the ROM, which may spend a few frames; 8. Based on the device configuration characteristic word, the host specifies a configuration value for the peripheral, At this time, the peripheral is in the configure state, and all of its endpoints are also described in the configuration value. From the perspective of peripherals, the peripheral is already in the preparation.

It must be configured before one peripheral can be used. "Configuration", that is, the host defines the configuration register of the device based on the configuration characteristic word of the peripheral to specify all EndPoint's work environments. If a data transmission mode is used, the device belongs to the device "Bastrics", "Subclass" and C , etc., thus controlling the external USB system software or customer software . When a USB peripheral is configured, it will enter the suspend state until it starts to be used.

It must be pointed out that once a USB peripheral is configured, each particular channel can only use a data transfer mode. The EndPoint 0 channel can only use the control transmission, the host transmits the standard USB command via EndPoint 0 to complete tasks such as reading device configuration character, control peripheral pairs of data, and can pass Endpoint 0 To detect and change the status of peripherals (such as woke up, hang and recovery, etc.).

For a digital video camera using synchronous transmission, the process of data transmission is as follows:

1. Application Software (CSW) opens up the data buffer in memory, and issues a data request (IRPS) through the standard USB command word;

2. The host USB system software sent to the peripheral by forming the Token packet by the translation of the IRPS, then the host enters the waiting state;

3. Peripherals perform NRZI decoding and bit unstruffing operations and CRC checks for packets, confirming that the commands contained in the host PID field are received and start collecting data.

4. The collected parallel data first enters the FIFOS and forms a serial pulse through the and / string conversion member;

5. Configure the PID field of the data to form the original packet according to the requirements of the device configuration register.

6. Generate a CRC check code field for each packet via the CRC check generator, and the SOP & EOP signal generator adds the synchronization field head and packet end of the packet;

7. NRZI coding and bit stuffing operations for packets;

8. Use the transceiver to drive the data stream to the USB cable.

9. The host controller converts the USB data into a normal "pure" image data to send to the data buffer to perform further processing of data; if it is controlling transmission, block transmission, or interrupt transmission mode, the host is also successfully transmitted, the host is also A handshake packet that sends an ACK to the peripherals as a response. Figure 13 briefly depicts a request and transfer process of an asynchronous data transfer (there is no Handshake section in the synchronous transfer).

Figure 13 Request and transfer process for non-synchronous data transmission

Fourth, conclude

At this point, we have introduced the software and hardware composition of the USB system and the data transfer protocol of the USB system from several aspects. USB can be said to have opened up a new era of computer peripheral interface. It liberates people from a complicated connection, different interface standards and annoying interruptions;

Make "PNP" and "hot plug" such that the characteristics of "hot swap" are no longer only slogans; it greatly expands the number of peripherals that the computer can connect; its intelligent power management effectively reduces the power loss of the handheld computer ... USB is becoming a market Hotspots, more and more peripheral manufacturers turn their products to the USB interface. The launch of USB 2.0 protocols undoubtedly played the role of promoting the development of USB technology.

In applications such as mouse, keyboard, handwriting, or a game rod and other human-computer interaction; such as scanners, digital cameras, mobile storage devices, digital cameras, etc., USB is undoubtedly the most important The best interface, which makes the advantage of USB have gone full. But is USB true for occasions such as video or audio output? We know, like a Sound Blaster Live! Such a sound card is exactly because it implements advanced features such as wavefringing synthesis and EAX environment sound effects on the hardware, so that we can hear "the sound of the sound" at almost less than 1% of the resource usage, at the same time A beautiful 3D environment in the 3D environment. However, USB is not universal, for example, we see the "USB speaker" in the market "USB speaker" can "save a sound card!". However, since the USB interface does not process the data, the task of data processing is completely handed over to the CPU and software, so that this speaker has caused an amazing resource usage, and the sound card is also seen from the sound card. . Therefore, USB is not "packaged to cure all diseases". ↑ Comprehensive understanding of the essence of USB technology (1)

转载请注明原文地址:https://www.9cbs.com/read-100398.html

New Post(0)