USB Architecture
A USB-enabled computer has one or more USB controllers . The controller is attached to the root hub. Devices, including other hubs, are also attached to the root hub. Additional devices and hubs can be attached to these hubs in a tree topology. The devices can be quite diverse and typically include mice, keyboards, digital cameras, CD burners, microphones, speakers, iPods, and more. Devices are divided into separately addressable functions . Most devices have only one function, but some may have more than one. For instance, the Epson Stylus CX5200 is both a printer and a scanner.
Functions are connected to the host controller through unidirectional pipes. Each function can support up to 32 pipes, 16 going into the host controller and 16 coming out of the host controller. The pipes in each direction are numbered from 0 to 15. However, most functions don use all their pipes. The zero pipe in both directions is reserved for the controller to manage the bus topology. You can often ignore this pipe and just use pipes 1 to 15. Data is transferred across the pipes in packets sized as powers of two: 8 bytes, 16 bytes, 32 bytes, 64 bytes, and so on. The number of pipes and the sizes of the packets vary from one device to another.
There are four kinds of transfers:
Control
Commands that control and configure the USB device and bus.
Isochronous
Fast data transfers at a guaranteed speed that may lose data.
Interrupt
Requests from the device to the host. The host periodically polls each device to see if it has any of these ready to go.
Bulk
Reliable transfers that guarantee all bytes are transferred but do not guarantee the speed.
The type of transfer used depends on the needs of the device. For instance, mice and keyboards mostly use interrupt transfers, microphones and speakers mostly use isochronous transfers, and CD burners and PDAs mostly use bulk transfers.
USB has special device classes for certain common device types, including:
- Human interface devices, such as keyboards and mice
- Mass storage devices, such as hard drives, iPods, and PDAs
- Communications devices, such as telephones, modems, and network adapters
- Printer devices
More often than not, these devices are exposed to Java through some other abstraction. For example, a USB hard drive can be accessed through the FileInputStream, FileOutputStream, and File classes like any other hard drive. Most of the time you don know or care that the files are on a USB hard drive instead of an IDE or ATA hard drive. The USB APIs are for talking to the weird devices that don have standard classes, such as uninterruptible power supplies (UPSs) or laboratory data acquisition hardware. Later in this chapter, well demonstrate communicating with a USB-enabled temperature probe.
Категории |