USB Device Architecture

USB devices are divided into three layers: a bottom layer to transmit and receive data bus interface; process intermediate layer 2 data transfer bus, and the different endpoints; the top 3 by a serial bus device.... The main intermediate layer.

USB device status, the main external research visible.

1, connected state, USB devices can be connected to or disconnected from the Host.

2, power state. The device supports the power supply capability is enabled by the configuration to reflect the description.

3, the default state. Bus should not appropriate, after the reset signal is received, the device may be addressable in the default address before the power has not been reset.

4, addressed state. After the device is assigned a unique address by the host, we keep this address.

5, configuration mode. Before using the device, the device must first be configured. From the perspective of the device, said configuration including SetConfiguration with a non-zero value () request. Be arranged such that the node associated therewith (Endpoint) is set to a default value.

6, the pending state. Undetectable device enters the suspended state when the bus transfer, and keeping the internal state of the same, including address and configuration.

==========================================================

Identification bus (Bus Enumeration)

When the USB device is connected to or removed from the USB device, the host starts a process called bus is identified, to identify and manage the device state changes.

When a charging port when a USB device is connected, the system will perform the following operations:

1, the device changes the channel reports from the USB host device connected via a state. At this USB device is powered on, invalid port it is connected.

2, the host asked the meaning of this connection.

3, the host knows the new device is connected after waiting 100ms operation is completed so that the plug and power stabilization device, and the host port enable port and reset.

4, when the reset signal is issued, the port has been enabled. At this time, the USB device is in the default state, and can be obtained from more than 100mA current VBUS. And status registers are all reset and default address response.

5, the host is assigned a unique address to the USB device and causes the device to enter the addressing mode.

6, prior to receiving a unique device address, the default control pipe still available default address addressing. Host to obtain the maximum data payload default pipe USB device may be used by reading the device descriptor.

7, from the host configuration information reading apparatus arranged to read from the configuration 0 n-1, where n is the number of the configuration.

8, based on the read configuration information to a USB device and how it is used, a host device to a configuration value. Device enters configuration mode, all this endpoint, obtained previously described characteristics. USB devices can be power required descriptor from the equipment standpoint, it has been in place.

===========================================================

General USB device operation (Generic USB Device Operation)

All USB devices support a series of operations, this section describes these operations.

1, dynamic connection and disconnection

2, address assignment

3, configuration. USB devices can be used after configuration. Host device functions determined by the read configuration information of the device.

4, the data transfer. Data may be four ways for communication between the host and the USB device endpoints. The same endpoint can transmit data in different ways in different configurations, but once the configuration selected, determines the transmission mode.

5, power management. USB device needs a power supply unit (100mA) until the following configuration. Once suspended, regardless of whether the previously configured, power needs to be reduced. After configuration, USB devices may demand five units (500mA). USB remote wake-up capability itself can be reported to the host via the device descriptor.

6, the request processing.

7, request error.

===========================================================

USB device requests

All USB devices to respond to requests by Host default control pipe. These requests are done by controlling the transmission, and the response packet is provided in response to setup parameters, Host set the value of each field in the packet. Each setup packet has eight bytes.

1, bmRequestType, 1 byte. It indicates the transmission direction of the second control stage, if wLength is set to 0, the direction bit is ignored. USB spec defines a standard USB requests a series of USB devices must support. Equipment manufacturers can also define requests supported by the device. The request may be directed to a port on the device or on the device interface or the device. When the interface is specified in a port or when, wIndex pointed out what interface or port.

2, bRequest, 1 byte. This field indicates that a special request. bmRequestType the Type-bit modify the meaning of this domain. Type bit is 0 only when the time domain is the meaning bRequest standard device request.

3,wValue,2个字节。这个域的内容取决于request,以用来传递不同参数给设备。

4,wIndex,2个字节。这个域的内容取决于request,以用来传递不同参数给设备。这个域通常用来指明一个端口或接口。

当用来指明端口时:

D15---D14---D13---D12---D11---D10---D9---D8---D7-------D6---D5---D4---D3---D2---D1---D0

|-------------保留,设置为0---------------------------|direction|保留,设置为0|---endpoint number---|

其中方向位设置为0的时候表示OUT,设置为1的时候表示IN,并且需要表明endpoint number。在控制管道的情况下,request设置方向位0但设备可以接收任意方向位的值。

当用来指明接口时:

D15---D14---D13---D12---D11---D10---D9---D8---D7-------D6---D5---D4---D3---D2---D1---D0

|-------------保留,设置为0---------------------------|---------------interface number---------------|

5,wLength,2个字节。这个域指明控制传输第二阶段的数据长度。方向由方向位指定,并且如果方向位为0则没有数据要传输。在输入请求下,设备可以返回小于等于wLength中的数据。在输出请求下,wLength总是指明要确切传输的数据。如果主机发送超过wLength的数据,则设备行为无定义。

USB设备标准请求参见另外一篇博文。

转载于:https://www.cnblogs.com/artechliu/archive/2011/01/31/1946165.html

Guess you like

Origin blog.csdn.net/weixin_33748818/article/details/93275445