Fully understand the essence of USB technology (2)

Source: Internet
Author: User
This article introduces the data transmission mode of USB bus, the format of USB data packets, and the composition and structure of USB peripherals.

I. Format of USB data packets

In a USB system, there are four types of data packets: token packets, data packets, and SOF packets) and handshake packets ).

1. The labeled data packet consists of four fields: PID, ADDR, endp, and crc5 (figure 1 ). The PID field is divided into three types: input type (in), output type (out), and setup type (Setup. Mark the data packet before each data packet transmitted by USB to indicate the type of the USB operation (PID field mark), The operated object (specified in the ADDR and endp fields), and other information. The CRC check bit of 5bit is used to ensure the correctness of the labeled data packets.

2. we have pointed out that the USB Host generates a sof USB frame synchronization signal on the USB bus every 1 ms. The sof packet contains the actual content of this pulse sequence (Figure 2 ), it consists of the PID field in SOF format, the number of frames field, and the CRC verification code of 5bit. The host uses sof data packets to synchronize data transmission and receiving.

3. data packets used to transmit real data (figure 3), because different PIDs can be divided into data0 and data1. Data0 is an even data packet, and data1 is an odd data packet. The parity classification of data packets is easy to handle the dual-flow water of data, while data packets used to control transmission are always transmitted using data0.

4. the handshake packet only contains one PID field (Figure 4). The ack PID indicates that the USB transmission has not encountered an error and the data has been successfully transmitted; the handshake packet in the form of NaK indicates to the host that the USB transmission failed due to CRC verification error or other reasons, so that the host can re-transmit data; stall-form response reports to the host that the peripherals are currently suspended and data transmission cannot be completed.

It should be noted that each packet ends with two bit-wide EOP fields as the mark of packet end (figure 5 ), in the differential mode signal, the EOP is in the "0" status, where both the D + and D-are in the "0" status. For high-speed USB peripherals, the pulse width is between 160 and ~ Between 175ns, and between 1.25 and for low-speed Devices ~ Between 1.50 μs. No matter whether there are other data packets afterwards, the USB cable follows the EOP field followed by the 1-bit idle bus bit. The USB host or peripherals use EOP to determine the end of a data packet.

Figure 1 mark the composition of a data packet
Figure 2 sof packet format

Figure 3 data packet format
Figure 4 handshake packet

Figure 5 voltage performance of the EOP field in the differential mode signal

Ii. Data Transmission Mode of USB Bus

As mentioned above, each USB channel corresponds to a specific USB transmission mode. According to different needs, USB peripherals can specify different USB transmission modes for the USB channel. The USB Bus supports four data transmission modes:

1. control Transmission Mode (figure 6): control transmission is used to configure the device during the first connection of the peripheral, detect the status of the peripheral in real time, and transmit control commands; it can also be used by customer software for other purposes after device configuration is complete. The endpoint 0 channel can only adopt the control transmission mode.

2. Block Transfer Mode (Figure 7). Block transfer is used for batch and non-real-time data transmission. For example, a USB scanner can adopt the block transmission mode to ensure continuous and real-time data error correction transmission at the hardware level. The USB bandwidth occupied by a channel using block transfer mode has the highest priority in real-time bandwidth allocation.

3. synchronous transmission mode (figure 8): synchronous transmission is applicable to scenarios that require continuous and real-time data generation, transmission, and consumption at a fixed data transmission rate, such as digital recorders. To ensure real-time data transmission, synchronous transmission does not retry data errors or respond to a handshake packet at the hardware level, which may cause data errors in the data stream. In order to ensure that the probability of fatal errors in synchronous transmission data streams is small to tolerable, and the delay of data transmission will not have a great impact on the performance of peripherals, the vendor must select an appropriate bandwidth for the channel using synchronous transmission (that is, a balance must be made between speed and quality ).

4. the interrupted transmission mode (figure 9) is applicable to small-batch, point-type, and non-continuous data transmission applications, such as the mouse, keyboard, and game Pole Used for human-computer interaction, the method of interrupted transmission is the most suitable.


Figure 7 Transfer Process

Figure 8 synchronization procedure
Figure 9 interrupted transmission process

Iii. Composition and Structure of USB peripherals

This article does not intend to discuss in detail the design details of USB peripherals (USB peripherals mentioned in this section refer to USB functional devices without special instructions), but only want to introduce the general components of USB functional devices, this helps readers understand the basic hardware and software components of USB peripherals, so as to understand the working process and principles of USB peripherals.

The sensors that make up peripherals are different from the DSP because the specific applications of peripherals vary. For example, for a CMOS digital camera (such as the creative webcam ), its CMOS photocoupler and Its DSP do not change because of the interface method used (for example, early computer eyes all use the parallel port enhancement mode of ECP for image data transmission, and now almost all USB interfaces ). Therefore, this article focuses on the USB peripheral interface, that is, USB device Microcontroller (USB device microcontroller ). Figure 10 shows a detailed diagram of a USB Peripheral Bus Interface.

The USB Bus transmits data in a differential mode drive. However, before data packets are sent, the USB Protocol requires that data must be encoded using nrzi. Of course, in USB peripherals, devices used for decoding are also essential for peripherals. The nrzi encoding protocol is actually very simple. It adopts the principle of "1" persistence and "0" Jump (figure 11), while nrzi decoding adopts the opposite operation.
To ensure that there are sufficient signal changes in the data stream, the USB Protocol sets the bit stuffing principle, that is, if the signal stream contains more than six consecutive data "1 ", A "0" must be inserted at every six bits before entering the nrzi encoding. Figure 12 shows a string of raw data and its data format after filling and nrzi encoding.


Figure 10 detailed structure of USB Peripheral Bus Interface

Figure 11 nrzi Data Encoding

Figure 12 comparison of the original data and the data format after the plus-fill bit and nrzi Encoding

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

1. The parts of the nrzi/bit buffing and nrzo/bit unstuffing that are used on the hardware to complete nrzi encoding, decoding, and addition/de-filling operations;

2. CRC Check and generator for CRC verification of data packets generated on the hardware;

3. packet encode ), converts a USB packet sent from the host into a recognizable parallel data string/packet decode );

4. Detect and generate the SOP (that is, the synchronization field of each data packet) and EOP signal.

USB peripherals use a ROM to store some important information about the work of the peripherals. This is called the USB protocol layer ), it not only stores general information such as the manufacturer identification number, the type of the peripheral (HUB or function, low-speed or high-speed device), and power management, more importantly, it also stores peripheral device types, device configuration information, feature descriptions, and interface information. The storage method uses descriptors. The USB Host establishes an endpoint 0 channel between the peripheral protocol layer and the host, and uses control transmission to access the information. Feature Words are arranged in the structure and code specified by the USB protocol (for more information about feature words, see USB protocol standards ). 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 the premise that a USB Peripheral can be correctly identified and configured by the host and work properly. The protocol layer is the firmware center of a USB peripheral.

We know that the data sampling rate varies depending on the sampling accuracy and usage. For audio applications, the sampling rate of 22.05khz or 44.1khz can be used, and this clock does not correspond to the USB standard clock. Therefore, in practical applications, to ensure that the collected data is packaged and transmitted without loss, The SIE and data collection components must be used (for peripherals such as speakers or printers, data consumption components are used) to Cache data. For peripherals that adopt block transfer and synchronous transmission, the role of fifos is particularly important. For example, a USB Digital Camera with synchronous transmission (there are many such products on the market), we assume that its CCD is 400x300 pixels, to ensure correct data compression, transmission, and receipt, until subsequent decompression and processing, the Yunos must store at least one frame of image in dynamic collection, that is, fifos must have a capacity of 400x300 = 12 kb.

In USB peripherals, The Transcoder used to achieve seamless connection with the USB cable is essential, not only must it be connected to the USB cable on the electrical and physical layers, in addition, the differential mode drive or separation of data packets must be completed.
The above describes the hardware components of USB peripheral interfaces. How can these hardware work together and interact with the hardware and software on the host during the completion of USB data transmission, to complete data transmission?

As mentioned above, the USB Bus uses the methods listed in the bus to mark and manage the status of peripherals. When a USB Peripheral is first connected to the USB system, perform the following eight steps to complete initialization:

1. the Hub (root hub or extended hub) connected to the USB Peripheral detects the connected USB peripheral and automatically notifies the host and changes its port status, at this time, the peripherals are still in the disabled status;

2. The host checks the hub to confirm the peripheral connection;

3. now the host knows that a new USB Peripheral is connected to the USB system. Then, it activates the hub port and sends a reset (reset) to the hub) command for this port;

4. the Hub maintains the reset signal for 10 ms and provides 100mA bus current to the peripherals connected to the port. When the peripheral is in the powered state, all its registers are cleared and directed to the default address;

5. Before the peripheral is assigned a unique USB address, its default channel uses the default address of the host. Then, the Host reads the feature characters of the peripheral protocol layer to understand the actual maximum data payload width used by the default channel of the peripheral (that is, the peripherals defined in the feature word in the data0 packet ). the length of the data field ).

6. The host allocates a unique USB address to the peripheral and puts it in the addressed State;

7. The host starts to use the endpoint 0 channel to read the device configuration features stored in the peripheral Rom, which may take several frames;

8. based on the device configuration feature word, the host specifies a configuration value for the peripheral. In this case, the peripheral is in the CONFIGURED state, and all its endpoints (endpoints) it is also in the State described by the configuration value. From the perspective of peripherals, the peripherals are ready for use.

It must be configured before a peripheral can be used. "Configuration" means that the host defines the configuration registers of the device based on the configuration features of the peripheral to define the operating environment of all the endpoints of the peripheral. For example, the data transmission method adopted by a channel, the devices of the peripheral, such as "base class", "derived class (subclass)", and C ++, this allows you to control peripherals through host-based USB system software or customer software.
After a USB Peripheral is configured, it enters the suspended state until it is used.

It must be noted that once a USB Peripheral is configured, only one data transmission mode can be used for each specific channel. The endpoint 0 channel can only adopt the control transmission mode. The host uses the endpoint 0 to transmit standard USB commands, complete tasks such as reading device configuration feature words, controlling peripheral data collection, processing, and transmission, you can also use endpoint 0 to detect and change the status of peripherals (such as remote wake-up, suspension, and recovery of peripherals ).

For a digital camera with synchronous transmission, the data transmission process is as follows:

1. The application software (CSW) opens a data buffer in the memory and sends data requests (IRPs) to the peripherals using standard USB commands );

2. The host USB system software sends a token packet to the peripherals by translating the IRPs, and the host enters the waiting state;

3. the peripherals perform nrzi decoding, bit unstuffing, and CRC verification on the data packets. After confirmation, the peripherals receive the commands contained in the host PID field and start to collect data.

4. The collected parallel data first enters the parallel OS, and a serial pulse is formed through the parallel/String Conversion component;

5. Split the data according to the requirements of the device configuration register, and configure the PID field of the data packet to form the original data packet.

6. The CRC verification code field is generated for each data packet through the CRC verification generator. The SOP & EOP signal generator adds a synchronization field header and a data packet terminator to the data packet;

7. Data Packet nrzi encoding and bit stuffing operations;

8. Use a Transcoder to drive data streams to a USB cable.

9. the host controller converts USB data into "pure" image data and sends it to the data buffer for further processing. If the transmission is controlled, block transmission, or interrupted, after the data is successfully transmitted, the host sends an ACK handshake packet to the peripherals as a response.
Figure 13 briefly depicts the request and transfer process for non-synchronous data transmission (no handshake part in synchronous transmission ).


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

Iv. Conclusion

So far, we have introduced in detail the hardware and software components of the USB system and the data transmission protocol of USB. USB can be said to have opened up a new era of computer peripheral interfaces. It frees people from complicated connections, different interface standards, and annoying interruptions;

Making "PNP" and "Hot swapping" is no longer just a slogan; it greatly extends the number of peripherals that a computer can connect; its smart power management effectively reduces the power loss of handheld computers ...... USB is becoming a hot spot in the market. More and more peripheral manufacturers are turning their products to USB interfaces. The launch of the USB 2.0 protocol has undoubtedly contributed to the development of USB technology.

In applications such as mouse, keyboard, tablet, or game pole interactions, such as scanners, digital cameras, mobile storage devices, digital cameras, and other data input applications, USB is undoubtedly the best interface method to replace the traditional serial/parallel port, which gives full play to the advantages of USB. But does USB also apply to scenarios such as video or audio output? We know, like sound blaster live! This sound card is precisely because it implements advanced features such as wave table synthesis and eax environment sound effects on the hardware, so that we can hear "tianyao" at a resource usage of almost less than 1% ", at the same time, it can be used in the beautiful 3D environment. However, USB is not omnipotent. For example, we can see that the popular "USB speaker" on the market can save a sound card! ". However, since the USB interface does not process any data, the data processing task is completely handed over to the CPU and software, which leads to an astonishing resource usage, the sound performance is also quite different from the sound card. Therefore, USB is not "treating all diseases.

✓ Fully understand the essence of USB technology (I)

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.