Universal Serial Bus: Difference between revisions

Jump to navigation Jump to search
add ping transaction protocol, fixed other minor things I noticed, and removed redundant/less-detailed information from the original wiki contents
[unchecked revision][unchecked revision]
(added handshake info)
(add ping transaction protocol, fixed other minor things I noticed, and removed redundant/less-detailed information from the original wiki contents)
Line 397:
|align="center" |NYET
|align="center" |0110b
|The receiver has not yet responded, or the host should begin sending PING packets.
|-
|rowspan="5" align="center" |Special
Line 550:
|-
|align="center" style="border-right: 1px solid #000000; border-top: 1px solid #000000;" |Function
|align="center" style="border-top: 1px solid #000000;" |PINGOUT
|}
===== NYET =====
Line 667:
A function must always accept data in a SETUP transaction, and must never issue a STALL or NAK handshake in response. All non-control endpoints must simply ignore any SETUP transaction addressed to that endpoint. This allows SETUP transactions to function as a (re)synchronization mechanism between the host and a function's control endpoint.
 
==== PING Transaction =Protocol ===
Consider a USB mass storage device. During a transfer from the host to the function, the function's buffer fills up with data that is pending being committed to the physical media. When the function's buffer is full, the function cannot accept new data until some of the buffer is committed, so if the host continues sending OUT transactions, the function must [[#NAK|NAK]] them.
 
The problem with this OUT/NAK model is that a function must wait for the handshake stage of the OUT transaction before responding with a NAK. Since the handshake stage occurs after the data stage, this can waste a significant amount of bandwidth. Low- and full-speed buses suffer from this problem, but the USB 2.0 specification introduced the PING transaction protocol for high-speed buses.
 
The PING transaction protocol is very straightforward. Rather than an OUT transaction, the host issues a PING transaction to the function when the host wishes to send data. The function responds with either NAK to indicate that it is not ready to receive data (specifically, the function's buffer cannot accommodate the endpoint's maximum data payload amount of data), or ACK to indicate that the host may start sending data.
 
The USB 2.0 framework allows endpoints to specify an interval, in terms of microframes, which is the amount of micorframes that the host should wait before issuing another PING packet to the endpoint. However, the host is not required to wait this interval before issuing the next PING packet.
 
During a high-speed control or bulk transfer from the host to function, when an OUT transactions causes a function's free buffer space to drop below the endpoint's maximum data payload, the function responds with a NYET handshake packet. This indicates that the host should start issuing PING packets rather than additional OUT transactions.
 
== TODO ==
Line 679 ⟶ 689:
 
== Original USB Wiki Content ==
Until the above sections are complete, the original content of this wiki entry that has not been covered in more depth is placed here.
 
=== USB keyboards/mice ===
Line 694 ⟶ 704:
 
As a first step, you'll need to provide a driver for the USB Host Controller, which appears in most cases as a [[PCI]] device and will allow you to enumerate devices on the USB [[:Category:Buses|bus]] and send packets to the identified devices. Documentation about the [http://www.o3one.org/hwdocs/usb/hcir1_0a.pdf Open Host Controller Interface], [http://developer.intel.com/design/USB/UHCI11D.htm Universal Host Controller Interface] and [http://www.intel.com/technology/usb/download/ehci-r10.pdf Extended Host Controller Interface] are available freely. Your USB-aware chipset should support one of these three.
 
Some computer may have support for more than one of these standards (there are computer with UHCI or OHCI for USB 1.1 and EHCI for high-speed USB 2.0 using the same USB ports)
 
Once you know what devices are present, you'll have to identify a device-specific driver that will match that hardware. For some devices (webcams, scanners, etc), this may require a vendor-specific driver while other devices (USB keychains, HID etc) have to adhere to _class_ standards. This means that one can write a generic USB storage driver that will work with all possible keychains, embedded mp3 players, flash card readers, etc.
 
USB uses a tree topology, with non-leaf devices in the tree providing _hub_ class services. The tree can be up to 16 levels deep, with each hub theoretically providing up to 16 devices. The "root" of the tree is not considered a hub for some reason. Before you can start talking to devices on the USB, you will want to be able to enumerate all devices. Fortunately, the USB standard requires that all devices, including hubs, are self-describing.
 
Don't forget that USB devices are hot-pluggable, that is they can be added and removed at any time while the system is running.
Line 736 ⟶ 742:
Inquiry, Get_Capacity and Read_10 or Write_10
 
=== Functioning ===
 
USB looks much more like a network protocol than like RS232 (good old serial cables). Data transmissions follow formatted packets rather than being made of plain characters. However, unlike network protocols like Ethernet, Token Ring, etc. all communications are directed by the host (i.e. your computer), and even 'interrupts' are actually polled by the host.
 
More information about this section can be found on [http://www.beyondlogic.org/usbnutshell/usb3.htm Usb In A Nutshell (ch. 3)]
 
==== Packets ====
These are the smallest formatted things that may transfer on the USB cable. Each USB packet at least have a <tt>SYNC</tt> header and a <tt>EOP</tt> trailer that carry no information but help in identifying packets boundaries. Each USB must also have a <tt>PID</tt> field (Packet IDentifier) that tells the role of the packet in a transfer or a transaction.
 
==== Transaction ====
A transaction is a "single sentence" between the host and a device. Transactions may be used to send/read data from the device, initiate transfers, set up parameters, get information, etc. Each transaction is typically made of 3 packets:
 
# a token packet that always comes from the host and carries the address of the device/endpoint concerned in the transaction. USB defines 4 types of tokens: <tt>SETUP</tt> (initiates a control transaction), <tt>IN</tt> (initiates a device->host data transaction) and <tt>OUT</tt> (initiates a host->device data transaction). Tokens are typically have a small fixed size.
# a data packet which carries the transaction payload. Depending on the USB version, transfer speed and type of data packet used (DATA0, DATA1, DATA2 or MDATA), the maximum payload may be 8, 64 or 1024.
# a handshake packet which informs the data emitter of the reception status. Handshake may be <tt>ACK</tt> (data received correctly), <tt>NAK</tt> (unable to receive/emit data right now, or no data to send) or <tt>STALL</tt> (device state invalid, host intervention required)
 
==== Transfers ====
Transactions are used to build more complex protocols like control transfer, interrupt transfer (single small sized status poll), isochronous transfer (periodic non-acknowledged packet transmission, like a sample to play on speakers) and bulk transfer (non-predictable large-sized transfers like a page to print)
 
More on USB transfers can be found on [http://www.beyondlogic.org/usbnutshell/usb4.htm USB in a nutshell, ch 4]
 
==== Configuration ====
Line 762 ⟶ 747:
 
A list of structures defining USB descriptors is available in [http://clicker.cvs.sourceforge.net/*checkout*/clicker/c32-lxsdk/kernel/src/mods/io/include/usbdescr.h usbdescr.h] from Clicker's CVS (LGPL)
 
===== Endpoints =====
Configuration communications are performed on endpoint 0. The USB device will usually define more endpoints used as communication channels between the device and the host, link those endpoints to interfaces which can be assigned a class, subclass and protocol codes (identifying what the device is able to do). For instance a digital camera could offer a couple of endpoints to implement the USBstorage interface (for the camera's memory card) and other endpoints for a webcam interface.
 
===== Reading descriptors =====
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu