USB Complete fourth- P15

USB Complete fourth- P15

Thể loại: Phần cứng
Lượt xem: 32,411Lượt tải: 7Số trang: 10

Mô tả tài liệu

USB Complete fourth- P15:This book focuses on Windows programming for PCs, but other computers and operating systems also have USB support, including Linux and Apple Computer’s Macintosh. Some real-time kernels also support USB.

Tóm tắt nội dung

Chapter 4 116 OS enable storing in means the is available on instead of requiring users to provide the on separate Microsoft OS string has an index of EEh and contains Windows XP SP1 and later request this string a device on first A device that doesn’t support the return STALL. On a Microsoft OS string Win- dows may request one or more Microsoft OS feature The ID feature contains IDs that can locate a driver for device functions that don’t have drivers. The extended feature can provide and other update for a USB 1.x device to USB 2.0, all except some have endpoints require just one change: in the device bcdUSB must be 0200h or greater. As Chapter 3 a USB default must request no so that wants to do transfers must have at least one setting, and the alternate interface will have at least endpoint 4-14: The device can provide that is to a or another aspect of a device or its bLength 1 length in bytes 1 DEVICE (10h) 2 1 01h = Wireless USB 02h = USB 2.0 = = CONTAINER ID 00h, 05h–FFH varies data and USB’s four transfer types, control transfers have the most complex also the only transfer type with functions defined by the USB This chapter looks in greater detail at control transfers and the defined in the transfers enable the host and a device to exchange about the device’s and other or Chapter 3 a control transfer consists of a Setup stage, a Data for some and a Status stage. Each stage consists of one or more 5 118 The below apply to USB 2.0 the same but use USB 3.0’s packet and as described in Chapter 5� The Setup stage consists of a Setup which the transfer as a control transfer and transmits the request and other that the to complete the must return ACK for every Setup received without error. An endpoint that is in the middle of another control transfer must transfer and the new Setup the receiver and the as a Setup by: the contents: the device and endpoint transmits the request and related by: the contents: eight bytes in five specifies the direction of data flow, the type of request, and the 7 names the direction of data flow for data in the Data to device (OUT) or no Data stage is zero; device to host (IN) is 1. Bits 6..5 (Request Type) specify whether the request is one of USB’s (00), a request defined for a specific USB class (01), or a by a driver for use with a product or 4..0 define whether the request is directed to the or to a specific interface (00001), endpoint (00010), or other in the Requests for Critical Data the can pass to the device. Each request the meaning of these two bytes in its own way. For example, in a request, wValue contains the device’s can pass to the device. A typical use is to pass an index or offset such as an interface or endpoint number, but can define the meaning of these two bytes in any way. When passing index, bits 3..0 specify the endpoint number, and bit 7 = 0 for a Con- trol or OUT endpoint or 1 for an IN endpoint. When passing an bits 7..0 are the interface number. All undefined bits are is two bytes that contain the number of data bytes in the Data follows. For a transfer, wLength is the exact number of bytes the host intends to transfer. For a transfer, wLength is a and the device may return this many bytes or fewer. If the field is zero, the transfer has no Data transmits the device’s by: the contents: none. The handshake packet consists of the PID If the device detects an error in the received Setup or Data device returns no The device’s hardware typically handles the error checking and sending of the ACK with no firmware support � ��� 5� The Data stage, when present, consists of one or more IN or OUT A Data stage with IN sends data to the host. An example is the Get request, where the device sends a requested to the host. A Data stage with OUT sends data to the device. An the HID-class request Set Report, where the host sends a report to a device. in the Setup equals 0000h, the transfer has no Data example, in the Set request, the host passes a to the device in the wValue field of the Setup stage’s data packet, so has no need for a Data 5 120 If all of the data can’t fit in one packet, the stage uses multiple In the device specifies the maximum number of per packet. The in the Data stage are all in the same When the Data stage is present but there is no data to transfer, the is a ZLP. The host uses split in the Data stage when the device is low or and a hub between the device and host connects upstream at high host may use the PING protocol when the device is high speed, the uses OUT and the stage has more than one data IN or OUT in the Data stage contains token, data, and the receiver and the as an IN or by: the If the request requires the device to send data to the host, the PID is IN. If the request requires the host to send data to the device, the PID is contents: the device and endpoint transfers all or a portion of the data specified in the wLength field of the Setup data by: the device if the token packet’s PID is IN or the host if the PID is The first packet is DATA1. Any packets in the Data stage contents: The host sends data or a ZLP. A device may send data, a ZLP, STALL request or halted or the data packet’s receiver returns status by: the receiver of the Data stage’s data packet. If the token packet’s PID is IN, the host sends the handshake packet. If the token packet’s PID is OUT, sends the handshake Requests for Critical Data 121 PID: A device may return ACK (data received without error), NAK or STALL request or halted A that is receiving multiple data packets may return NYET to indicate that the current data was accepted but the endpoint isn’t yet ready data packet. A host can return only contents: none. The handshake packet consists of the PID If the receiver detected an error in the token or data packet, returns no handshake ������ 5� The Status stage completes the transfer. In some cases (such as after first packet of a device during the host may begin the Status stage before the Data stage has and the device must token packet of the Status stage, abandon the Data stage, and complete the receiver and indicates the direction of the Status by: the the opposite of the direction of the previous data packet. If the Data stage’s PID was OUT or if there was no Data stage, the Status is IN. If the Data stage’s PID was IN, the Status stage’s PID is contents: the device and endpoint enables the receiver of the Data stage’s data to indicate the status of the by: the device if the Status stage’s token packet’s PID is IN or the host if the Status stage’s token packet’s PID is contents: The host sends a ZLP. A device may send a ZLP NAK (busy), or STALL request or halted 5 122 For most requests, a ZLP from the device indicates that the performed the requested action (if any). An exception is Set Address, where the device takes the requested action after the Status stage has The sender of the Data stage’s data indicates the status of the by: the receiver of the Status stage’s data packet. If the Status stage’s PID is IN, the host sends the handshake packet; if the token is OUT, the device sends the data A device may return ACK NAK (busy), or STALL request or halted The host returns ACK in response to a received without contents: none. The handshake packet consists of the PID The Status stage’s handshake packet is the final in If the receiver detected an error in the token or data packet, returns no handshake any request that’s expected to take many to carry out, the should define an alternate way to determine when the request has Doing so ensures that the host doesn’t waste a lot of time asking for that will take a long time to appear. An example is the Set Port request sent to a hub. The reset signal lasts at least 10 ms. Rather than making the host wait this long for the device to the request, the hub receiving the request when the hub the port in the reset state. When the reset is complete, the hub sets a bit that the host can retrieve at its leisure via a Get Port Status device might receive a request that firmware doesn’t support. Or a device may be unable to respond because the endpoint is in the Halt the has crashed, or the device is no longer attached to the bus. A host may to end a transfer early for any example of an request is one that uses a request code that firmware doesn’t know how to respond to. Or a device may support but other in the Setup stage doesn’t match what the or supports. On these a Request Error condition exists and the device notifies the host by sending STALL. Devices must respond to Requests for Critical Data with an ACK, so the STALL transmits in the Data or When possible, the device should return STALL in the Data failing to get a response or on detecting an error in received data or a at the endpoint, the host abandons the transfer. The host then tries to with the endpoint by sending the token a new Setup If a new token packet doesn’t cause the device the host requests the device’s hub to reset the device’s port. The host may also end a transfer early by beginning the Status stage all of the Data stage’s In this case, the device to the Status stage in the same way as if all of the data had ��� USB 2.0 device firmware typically performs the steps below to support The details vary with the device and � To complete a control write request with a Data stage, the device must request in the Setup stage, accept the data in the Data stage, and send a ZLP in the Status Device hardware detects a received Setup packet, stores the contents of data packet, returns ACK, and triggers an On detecting the the device decodes the request and ensures zero is ready to accept data that arrives following an OUT The endpoint must also ACK a new Setup packet if the host decides the transfer and should return a ZLP in response to an IN which indicates that the host is ending the transfer The Data stage begins when the host sends an OUT token packet to zero. The endpoint stores the received data and returns ACK in the packet. The hardware triggers an On detecting the the device processes the received data as If the Data stage has data packets, steps 3 and 4 repeat for OUT up to the wLength value in the Setup To complete the transfer, the host sends an IN token packet, the with a ZLP, and the host returns 5 124 � To complete a control write request without a Data stage, the device the request in the Setup stage and send a ZLP in the Status The hardware detects a Setup packet, stores the contents of the packet, returns ACK, and triggers an On detecting the the device decodes the request, does what is needed to perform the requested action, and arms endpoint zero to respond to an IN token packet. The endpoint must also ACK a new Setup packet if the host decides to abandon the To complete the transfer, the host sends an IN token packet, the with a ZLP, and the host returns complete a control read request, the device must detect the request in the Setup stage, send data in the Data stage, and a received the Status The hardware detects a Setup packet, stores the contents of the packet, returns ACK, and triggers an On detecting the the device decodes the request and arms zero to send the requested data on receiving an IN token packet. must also ACK a new Setup packet if the host decides to abandon and must return a ZLP in response to an OUT packet if the host Status stage The Data stage begins when the host sends an IN token packet to The device hardware sends the data, detects the received ACK from the host, and triggers an On detecting the a device that has more data to send arms the to send the data on receiving another IN token packet, and steps 3 and On receiving an OUT token packet followed by a ZLP, the endpoint to complete the 5-1 the requests defined in the USB 2.0 and USB 3.0 Requests for Critical Data 5-1: The USB defines these requests for control )0���� )� ��" or 0000h or Clear or 0000h or or 0000h or device address 0000h none type and or language length (bytes); Set type and or language ID host length (bytes); Get 0000h 0000h device Set 0000h none 0000h interface device interface interface none 0000h endpoint device 0000h 0000h host 0006h; exit latency Delay in ns 0000h none 0000h