Basic knowledge about USB (I)

Source: Internet
Author: User

Key USB keywords: 1. endpoint: a data buffer located on a USB device or host. It is used to store and send various USB data. Each endpoint has a unique fixed address, has different transmission characteristics (such as the input endpoint, output endpoint, configuration endpoint, batch transmission endpoint) 2. Frame: time concept. In USB, one frame is 1 ms, it is an independent unit that contains a series of bus actions. USB divides one frame into several parts, each of which is a USB transmission action. 3. uplink and downlink: The device goes upstream to the host, and the host goes downstream to the device. Question 1: What is the structure of the USB transmission line?Answer 1: a usb transmission line consists of four lines: Ground Wire, power cord, D +, and D-. d + and D-are differential input lines, it uses a voltage of 3.3v (note that it is different from the 5 V level of CMOS), and the power cord and ground wire can provide 5 V voltage to the device, the maximum current is 500mA (you can set it in programming. As for the hardware implementation mechanism, do not care about it ). Question 2: How data is transmitted in the USB transmission lineAnswer 2: data is transmitted in USB cables from low to high. Question 3: What is the USB encoding scheme?Answer 3: USB adopts non-return-to-zero inversion to transmit data. When the differential data input on the transmission line is 0, the reverse is obtained. When the input is 1, the original value is kept. In order to ensure the accuracy of the signal sending, when a packet is sent on the USB bus, the transmission device needs to insert a bit (that is, insert a 0 value for every six consecutive 1 values in the data stream), thus forcing the nrzi code to change. This is enough. These are processed by dedicated hardware. Question 4: What is the USB data format?Answer 4: Like others, USB data is composed of binary numeric strings. First, a numeric string forms a domain (with seven types), and a domain forms a package, the packet then forms a transaction (In, out, setup), and the transaction finally forms a transmission (Interrupt transmission, parallel transmission, batch transmission, and control transmission ). The following describes the domain, packet, transaction, and transmission. Pay attention to the relationship between them. (1) domain: the smallest unit of USB data, which consists of several digits (the number of digits is determined by the specific domain). The domain can be divided into seven types: 1. Synchronization domain (Sync), eight bits, with a fixed value of 0000 0001, used for synchronization between local clock and input 2. Identification domain (PID ), it consists of four-digit identifiers and four-digit identifiers, indicating the package type and format. This is a very important part. It can be calculated that there are 16 USB identifiers, for details about the category, see question 5. 3. Address domain (ADDR): a seven-bit address represents the address of the device on the host. Address 000 0000 is named as zero. This is the first time a device connects to the host, the default address before being configured and enumerated by the host, so that you can know why a USB host can only connect 127 devices. 4. endp allows up to 16 endpoints of a USB device. 5. the frame number domain (FRAM) has 11 bits. Each frame has a specific frame number. The maximum capacity of the frame number domain is 0x800, it is of great significance for synchronous transmission (synchronous transmission is one of the four transmission types, please refer to the following ). 6. Data field: the length is 0 ~ 1023 bytes. In different transmission types, the data domain length varies, but must be the length of an integer. 7. check domain (CRC ): A non-pid Verification Method for token packets and data packets (see the following for Packet Classification). CRC verification is widely used in communication, it is a good verification method. As for the specific verification method, we will not talk about it here. Please refer to the relevant information, only note that the division of the CRC code is a modulo 2 operation, it is different from division in decimal system. (2) packages: There are four types of packages composed of domains: token package, data packet, handshake package, and special package. The first three are important packages, the domain structures of different packages are different. 1. The token package is described as follows: it can be divided into the input package, output package, setting package, and frame start package (note that the input package is used to set the input command, and the output package is used to set the output command, the format of the input package, output package, and set package is the same: Sync + PID + ADDR + endp + crc5 (five-digit verification code) (For the abbreviations and explanations above, see the introduction of the above domain. For the specific definition of the PID code, see question 5) Format of the frame start package: sync + PID + 11-bit fram + crc5 (five-bit verification code) 2. Data Packets: data packets are divided into the data0 package and data1 package. When the USB sends data, when the length of data sent at a time is greater than the capacity of the corresponding endpoint, data packets must be divided into several packages and sent in batches. data packets 0 and data1 are sent in turn, that is, if the first data packet is data0, the second data packet is data1. However, there are exceptions. In synchronous transmission (one of the four transmission types), all data packets are data0 in the following format: Sync + PID + 0 ~ 1023 bytes + crc16 3. Handshake package: the simplest package, in the following format: Sync + PID (note that each package has a different type, USB defines ten packages, for details, see question 5) (3) Transactions: There are three major transactions: in transactions, out transactions, and setup transactions, each transaction is composed of three phases: the token packet, the data packet, and the handshake packet. Here, the stages are used because the packets are sent in a certain time sequence, the three phases of a transaction are as follows: 1. the token package phase starts an input, output, or set transaction. 2. The packet phase: send the corresponding data by Input and Output. 3. Handshake package stage: return the data receipt status. This stage is not found in the in and out transactions of synchronous transmission. This is quite special. Three types of transactions are as follows (one transaction is described in three phases): 1. In transaction: token package phase-the host sends an input packet whose PID is in to the device, the notification device sends data to the host. In the data packet phase, the device will respond to the situation in three ways (Note: The data packet phase does not always send data, the device enters the handshake packet phase in advance based on Transmission Conditions.) 1) the device endpoint is normal, and the device sends data packets to the host (data exchange between data0 and data1); 2) the device is busy, an invalid Nak packet cannot be sent to the host. The in transaction ends before the next in transaction continues. 3) the corresponding device endpoint is forbidden and the Error Packet stall is sent, the transaction ends early, and the bus enters the idle state. Handshake package phase-the host sends an ACK packet to the device after correctly receiving the data. 2. Out transaction: In the token package phase, the host sends an output packet whose PID is out to the device, notifying the device to receive data. In the data packet phase, the host sends data to the device, in the alternate handshake package phase between data0 and data1, the device responds to the following three actions: 1) the device endpoint receives the correct message, and the device returns an ACK to the incoming host, notifying the host that new data can be sent, if a CRC check error occurs in the data packet, no handshake information is returned. 2) if the device is busy, the system cannot send an invalid Nak packet to the host, notifying the host to send data again. 3) the corresponding device endpoint is forbidden. When an error packet stall is sent, the transaction is terminated before the bus enters the idle state. 3. Setup transaction: In the token package phase, the host sends an output packet whose PID is setup to the device, notifying the device to receive data. In the data package phase, the host sends data to the device, note that there is only one fixed 8-byte data0 package, and the content of these 8 bytes is the standard USB device Request command (a total of 11, please refer to question 7) handshake package stage-after the device receives the command information from the host, it returns ack and the bus enters idle status, prepare the next transmission (usually an in or out transaction after the setup transaction) (4) transmission: Transmission consists of the transactions in the out, in, and setup transactions, there are four transmission types: interrupted transmission, batch transmission, synchronous transmission, and control transmission. The structure of interrupted transmission is the same as that of batch transmission, and synchronous transmission has the simplest structure, control transmission is the most important and complex transmission. 1. interrupted transmission: it consists of an out transaction and an in transaction. It is used for data transmission between the keyboard, mouse, and other hid devices. 2. batch transmission: it consists of an out transaction and an in transaction. It is used for large data transmission with no fixed transmission rate and no bandwidth occupation. When the bus is busy, USB preferentially transmits data of other types, and temporarily stops Batch Transfer. 3. synchronous transmission: it consists of an out transaction and an in transaction. There are two special points: first, there is no returned packet stage in the in and out transactions of synchronous transmission; second, in the data packet phase, all data packets are data0. 4. control transmission: the most important thing is the most complex transmission. Control Transmission consists of three stages (initial setup stage, optional data stage, and status information step ), each stage can be regarded as a transmission, that is to say, the control transmission is actually composed of three transmissions. It is used to exchange information through control transmission after the USB device is first added to the host, the device address and the device descriptor are read to enable the host to identify the device and install the corresponding driver. This is a concern for every USB developer. 1. Initial setup step: it refers to the transmission of a SET transaction. 2. optional data step: it refers to the transmission of an in or out transaction. This step is optional, check whether the initial setup step requires reading/writing data (determined by the standard request Command sent by the data packet phase of the set transaction) 3. Status information step: as the name suggests, this step is to obtain status information, transmission composed of in or out transactions, but note that the in and out transactions are different from the previous int and out transactions. 1) the transmission direction is the opposite, generally, in indicates that the device sends data to the host, and out indicates that the host sends data to the device. Here, in indicates that the host sends data to the device, and out indicates that the device sends data to the host, this is to be combined with the optional data step; 2) in this step, the data packet in the data packet phase is of 0 length, that is, Sync + PID + crc16 except for the above two differences, the rest is the same.

 

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.