Chapter 11
End user convenience is the keynote of the universal serial bus (USB). The Plug and Play (PnP) concept has simplified the process of installing certain types of hardware on existing PCs. However, configuration issues continue to plague end users with respect to legacy devices such as serial and parallel ports, keyboards, and mice. The USB specification also identifies port availability as one of the factors limiting proliferation of low-speed to medium-speed peripherals, including modems, answering machines, scanners, and personal digital assistants. USB helps solve these problems by providing a uniform method of connecting a potentially large number of self-identifying low-to-medium-speed devices—that is, devices that require less than a 1.5-megabyte-per-second data rate and that can electronically identify themselves to system software—through a single PC port.
Although this book concerns software, some of the electrical and mechanical aspects of USB are important to software developers. From the end user's point of view, USB's main feature is the use by every device of an identical 4-conductor wire with a standardized plug that fits into a socket on the back of the PC or on a hub device plugged into the PC. Furthermore, you can attach or remove USB devices at will without explicitly opening or closing the applications that use them and without worrying about electrical damage.
This chapter covers two broad topics. In the first part of the chapter, I'll describe the programming architecture of USB. This architecture encompasses several ideas, including a hierarchical method for attaching devices to a computer, a generic scheme for power management, and a standard for self-identification that relies on a hierarchy of descriptors on board the hardware. The USB architecture also employs a scheme for subdividing fixed-duration frames into packets that convey data to and from devices. Finally, USB allows for four different ways of transporting data between the host computer and endpoints on devices. One method, named isochronous, permits a fixed amount of data to be moved without error correction every millisecond (ms). The other methods, named control, bulk, and interrupt, allow relatively small amounts of data (64 bytes or less) to be moved with error correction.
In the second part of this chapter, I'll describe the additional features of a Windows Driver Model driver for a USB device over and above the features you already know about. Rather than communicate directly with hardware by using hardware abstraction layer (HAL) function calls, a USB driver relies heavily on the bus driver (USBD.SYS). To send a request to its device, the driver creates a USB request block (URB), which it submits to the bus driver. Configuring a USB device, for example, requires the driver to submit several URBs for reading descriptors and sending commands. USBD.SYS in turn schedules requests onto the bus according to demand and available bandwidth.
The ultimate source for information about USB is the official specification, which was at revision level 1.1 when this book went to press. The specification and various other documents produced by the USB committee and its working groups were available on line at http://www.usb.org/developers/. Don Anderson's Universal Serial Bus System Architecture (Addison-Wesley, 1997) recapitulates much of the specification in useful form.