Working principle of USB OTG
The most important extension of the OTG supplemental specification for USB 2.0 is its more energy-efficient power management and the ability to allow devices to work in the form of host and peripherals. OTG has two types of devices: Dualrole device and Peripheralonly OTG device ). Dual-purpose OTG devices fully comply with USB
2.0 specifications. At the same time, he also needs to provide limited Host capabilities and a MiniAB outlet, support for Host Negotiatio n Protocol, HNP ), the transaction Request Protocol (SRP) is also supported by the peripheral OTG device ). When working as a host, the dual-purpose OTG device can provide 8
MA current, and the standard host needs to provide 100 ~ 500 mA current.
When two dual-purpose OTG devices are connected together, they can work in host and slave mode. This feature is compatible with the existing USB specification host/peripheral structure model. The OTG host initializes data communication tasks, such as resetting the bus, obtaining various USB descriptors, and Configuring devices. After these configurations are complete, the two OTG devices can transmit information in the host and slave mode respectively. The master-slave role exchange process of the two devices is defined by the host transmission protocol (HNP.
1.1 initial functions of the host (Adevice) and slave (Bdevice)
The initial function of a device is implemented by defining a connector. OTG defines a mini-Jack named MiniAB, which can be directly connected to the MiniA or MiniB plug-in. MiniAB has an ID pin that is pulled to the power supply end, the MiniA plug has an ID (R <10 Ω) that is connected to the ground, and the Mini B plug has an open circuit ID pin (R> 100 KB) that is connected to the ground ). When two OTG devices are connected together, the ID pin of the MiniA plug edge is injected with a "0" status, and the ID pin of the MiniB plug edge is "1 ", the default value of the OTG device with ID 0 is the host (Adevice), and the default value of the OTG device with ID 1 is the slave (B device ). Figure 1 illustrates the above content. 1.2 Session Request Protocol (SRP)
This protocol allows Adevice (which can be battery-powered) to reduce power consumption by disconnecting Vbus when the bus is not in use, and also provides a way for Bdevice to start bus activities. Any Adevice, including a PC or laptop, can respond to SRP; Any Bdevice, including a standard USB peripheral, can start SRP; requires a dual-functional device to enable both SRP, response to SRP. 1.3 Host circulation Protocol HNP (Host Negotiation Protocol)
HNP is a protocol used to implement Adevice and Bdevice host/slave machine conversion (in fact, the cable inversion ). The Master/Slave function exchange results are shown in the following process:
(1) Use the pull-up resistor to send signals to the slave machine.
(2) Adevice can set the "HNP Enable" feature on Bdevice.
(3) disconnect the Bdevice.
(4) ADevice is connected to the pull-up resistor, indicating that the Adevice belongs to the slave machine.
(5) Adevice powers Vbus.
(6) Bdevice detects Adevice pull-up.
(7) reset/LIST/use Adevice.
1.4 driver
Unlike PC hosts, portable devices do not have the convenient way and sufficient space to load new drivers. Therefore, the OTG specification requires that each dual-purpose OTG device has a list of supported peripheral OTG target devices, including the device type and manufacturer information.
Different from PCs, the driver stack of OTG dual-purpose devices consists of a USB Host Stack and a USB device stack to meet the needs of two working modes. The OTG driver determines whether to use the USB Host Stack or USB device Stack Based on the connector or whether NHP switching device is available.
When the OTG dual-purpose device works as a host, the USB Host Stack works. The host controller driver is responsible for data exchange between the USB Host Stack and the hardware endpoint. the USB driver enumerates and stores device information. The target peripheral host drivers support devices in the target device list. Host drivers are provided by chip manufacturers, and OTG provides generic host drivers (which can be modified to be used for non-generic devices ).
The USB device stack works when OTG dual-purpose devices work as slave devices. The device controller driver is responsible for data exchange between the USB device stack and the hardware endpoint, and the USB protocol layer is responsible for processing USB protocol specifications, the functionality of device drivers depends on the functionality of the dual-purpose device (such as digital cameras, storage devices, printers, etc ).
The OTG driver is responsible for converting the working mode of a dual-purpose OTG device. It can also return results (such as whether the device supports HNP) and handle bus errors. The Application Layer starts or ends a transmission transaction through the OTG driver and exchanges data with the hardware layer through the USB Host Stack or device stack.
1.5 data stream model
OTG hosts and devices are divided into three layers: functional layer, USB device layer, and USB interface layer, as shown in figure 2. The USB interface layer provides physical connections between the OTG host and the OTG device. The USB system software uses the host controller to manage data transmission between the host and the USB device. Compared with the host controller, the USB system software processes data transmission from the customer's perspective and the interaction between the customer and the device. The USB device layer provides an available logical device for the USB host system software. The host implements various features through customer software that matches the features.
OTG devices have two channels, data channels and message channels, just like USB devices. The data stream channel does not have a defined result, while the Message channel has a fixed structure. However, each channel has a certain bandwidth, transmission type, transmission direction, and buffer size. A default control channel is configured for a self-powered device, which provides information such as the configuration and status of the device.