Linux USB Driver Development (i)--USB Equipment basic Concept

Source: Internet
Author: User

In the end user's view, USB device provides a variety of additional functions, such as file transfer, sound playback, etc., but it is consistent with the interface of all USB devices for USB host. A USB device consists of 3 function modules:USB bus interface ,USB logic device and functional unit:

A--the USB bus interface here refers to the USB device in the serial Interface Engine (SIE);

B--USB logic device is regarded as a collection of endpoints by USB system software;

C--The functional unit is considered by the client software as a collection of interfaces . The SIE, the endpoint and the interface are all components of the USB device;


To better describe the characteristics of USB devices, USB presents the concept of device architecture . From this point of view, the USB device can be considered to consist of a number of configuration , interface and endpoint , that is, a USB device can contain one or more configurations, in each configuration can contain one or more interfaces, in each interface can contain a number of endpoints. The configuration and interface is the abstraction of the USB device function , and the actual data transfer is done by the endpoint . Before using a USB device, you must indicate the configuration and interface in which it is used. This step is typically done when the device is enumerated when the device is connected to the host.

The relationships between these units are as follows:



The device usually has one or more configurations;

Configuration usually has one or more interfaces;

An interface usually has one or more settings;

The interface has 0 or more endpoints.


Such a concept is too abstract to look like this:

There is a device, such as a player that supports video and audio. So, for each of the 4 descriptors mentioned above, what descriptor are they for when setting them?

From what I now understand, such a device corresponds to a device descriptor , the function of supporting video corresponds to an interface descriptor, which supports an interface descriptor for the audio function. in order to support video, there are multiple ports at the lower level that work together to provide support for video data transmission, so there are multiple endpoint descriptors .



USB devices use a variety of descriptors to describe their device architecture, including device descriptors, configuration descriptors, interface descriptors, endpoint descriptors, and string descriptors, which are usually stored in the firmware program of the USB device .

1. Device Descriptor

The device represents a USB device, which consists of one or more configurations. Device descriptors are used to describe the overall information of the device and indicate the number of configurations it contains. A USB device can have only one device descriptor .

struct usb_device_descriptor{u8 blength;//Descriptor length U8 bDescriptorType;//Descriptor type number LE16 BCDUSB;//USB version number U8 Bdeviceclass;// USB-Assigned device class CODEU8 bdevicesubclass;//USB-assigned subclass CODEU8 Bdeviceprotocol; USB-assigned protocol codeu8 BMAXPACKETSIZE0; Endpoint0 Maximum packet size LE16 Idvendor; Vendor number Le16 idproduct; Product Code LE16 Bcddevice; Equipment Factory number U8 Imanufacturer; Describes the index of the vendor string U8 iproduct; The index describing the product string U8 Iserialnumber; The index that describes the device serial number string U8 bnumconfigurations; Possible number of Configurations} _ _attribute_ _ ((packed));


2. Configuration Descriptor

A USB device can contain one or more configurations, such as a USB device's low-power mode and a high-power mode that can be configured separately. Before using a USB device, you must select an appropriate configuration for it. Configuration descriptors are used to describe the characteristics of each configuration in a USB device, such as the number of interfaces included in the configuration. Each configuration of a USB device must have a configuration descriptor.

struct usb_config_descriptor{u8 blength;//Descriptor length U8 bDescriptorType;//Descriptor type number LE16 wtotallength;//configuration The size of all data returned U8 Bnuminterfaces; Configure the number of supported interfaces U8 Bconfigurationvalue; Set_configuration command required parameter value U8 iconfiguration; The index value of the string describing the configuration U8 bmattributes; The choice of power supply mode U8 Bmaxpower; The maximum current that the device extracts from the bus} _ _attribute_ _ ((packed));


3. Interface Descriptor

A configuration can contain one or more interfaces, for example, for an optical drive that uses its mass storage interface when used for file transfers, and when used to play a CD, uses its audio interface. An interface is a collection of endpoints that can contain one or more replaceable settings that enable the user to change the number and characteristics of the current interface when USB is in the configured state. Interface descriptors are used to describe the characteristics of each interface in a device, such as the device class to which the interface belongs and its subclasses. Each interface of a USB device must have an interface descriptor

struct USB_INTERFACE_DESCRIPTOR{U8 blength;           Descriptor length U8 bDescriptorType; Descriptor type U8 Binterfacenumber;   The number of the interface U8 balternatesetting; The alternate interface descriptor number U8 bnumendpoints;      The number of end points used by the interface, not including the endpoint 0u8 Binterfaceclass;    interface type U8 Binterfacesubclass; Socket type U8 Binterfaceprotocol; The protocol followed by the interface U8 IInterface; A string index value describing the interface} _ _attribute_ _ ((packed));

4. Endpoint Descriptor

The endpoint is the actual physical unit in the USB device, and theUSB data transfer is done between the host and the USB device endpoints . The endpoints are typically provided by USB interface chips, such as the Freescale Company's Mc68hc908jb8 and MC9S12UF32. Each endpoint in a USB device has a unique endpoint number, and the direction of data transmission supported by each endpoint is generally deterministic: either input (in), or output (out). There are also some chip-provided endpoints where the data direction is configurable, for example MC68HC908JB8 contains two endpoints for data sending and receiving: Endpoint 1 and Endpoint 2. Where endpoint 1 can only be used for data sending, that is, the input (in) operation is supported, and endpoint 2 can be used for both data sending and data reception, i.e. support input (in) and output (out) operations. The MC9S12UF32 has 6 endpoints.

You can specify an endpoint and communicate with it using the device address, endpoint number, and transport direction. The transport nature of the endpoint also determines the type of transport that it uses to communicate with the host, such as control endpoints that can only use control transmissions. Depending on the purpose of the endpoint, you can divide your endpoints into two categories: endpoint No. 0 and non-No. 0.

The No. 0 endpoint is special, it has the data input in and the data output out two physical units, and can only support control transmission. All USB devices must contain a NO. 0 endpoint, which is used as the default control pipe. The USB system software is used to configure communication with the USB logical device. The endpoint No. 0 will be available on the USB device and not the NO. 0 endpoint must be configured for use later.

Depending on the needs of the application, the USB device can also contain multiple endpoints other than the terminal No. 0 endpoint. For low-speed devices, the number of additional endpoints is up to 2, and for full speed/high speed devices, the maximum number of additional endpoints is 15.

struct usb_endpoint_descriptor{u8 blength;//Descriptor length U8 bDescriptorType;//descriptor type U8 bendpointaddress;//Endpoint address: 0~3 bit is the endpoint number, The 7th place is the direction (0-out,1-in) U8 bmattributes; Endpoint properties: Bit[0:1] has a value of 00 for control, 01 for synchronization, 02 for batch, 03 for interrupt Le16 wmaxpacketsize; The size of the maximum packet received or sent by this endpoint U8 binterval;//polling the data transfer endpoint//For the end of the bulk transfer, and for the endpoint that                     controls the transfer, this domain                    must be 1                   //For the end of the synchronous transfer. For interrupted delivery endpoints, the range of this field value is 1~255_ _u8 brefresh;_ _u8 bsynchaddress;} _ _attribute_ _ ((packed));


5. String Descriptor

A string descriptor is usually included in a USB device to describe some proprietary information, such as the name of the manufacturer, the serial number of the device, and so on. Its contents are given in Unicode and can be read by the client software. String descriptors are optional for USB devices.


6. Pipeline

In the structure of the USB system, it can be considered that the data transfer occurs directly between the USB host software and the various endpoints of the USB device, and the connection between them is called the pipeline. The pipeline is built during the configuration of the USB device. Pipeline is the abstraction of the communication flow between USB host and USB device, which indicates that there is logical data transfer between the USB host and the endpoint of the USB device, and the actual data transmission is done by the USB bus interface layer.

The pipeline corresponds to endpoint one by one in the USB device. The number of endpoints that a USB device contains, how many pipelines it can use to communicate with the USB host, and the type of the endpoint determines the type of transport in the data in the pipeline, such as the interrupt endpoint corresponding to the interrupt pipeline, and the pipeline can only interrupt transmission. No matter how many pipelines exist, the data transfer in each pipeline is independent.



Linux USB Driver Development (i)--USB Equipment basic Concept

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.