How USB Works


This section explains how the USB bus recognizes new connections and how it moves data to and from your computer. This is probably more detail than you want or need to connect your printer and your mouse to the computer.

The simple version

When you plug a new device into a USB connector, Windows automatically recognizes the device and starts to exchange data with it. If you haven't used the device on this port before, Windows might ask you to load a device driver first. If you want to disconnect a USB device, just unplug the cable. If all the USB connectors on your computer are full, you can add more by using a hub that shares the signal among two or more connections. A hub can be a stand-alone unit with several USB connectors, or it might be built into another device, such as a keyboard or the base of a monitor. The hub normally connects to a computer's USB port through a USB cable.

That's it. That's all you need to know about the way USB works. Now you can skip to the section about cables and connectors later in this chapter. Of course, everything is not that simple. If you want to know how USB's internal plumbing works, keep reading.

The complicated version

The current USB specification (USB 2.0, introduced in 2000) has these design objectives:

  • Support for up to 127 separate devices on a single port through one or more hubs

  • Data transfer at up to 480 Mbits per second, shared among all devices connected to the same host computer

  • Plug and Play operation-Windows automatically recognizes new devices

  • Hot swapping-connect or disconnect a USB device without shutting down the computer

  • Support for three kinds of data transfer:

    • Interrupt mode for low-volume devices like a keyboard or a mouse (up to 1.5 Mbits per second)

    • Bulk mode for devices such as a printer or a scanner that transfers data in blocks and verifies the integrity of each block (up to 12 Mbits per second)

    • Isochronous mode for continuous streams of data to or from the computer in real time, such as speakers or a Webcam without taking the time for error correcting (up to 480 Mbits per second)

  • Transfer DC power from the computer to small peripheral devices

Hubs and expansion cards

A single USB host controller can support multiple client devices through one or more hubs that can share a single host connection. The most common hubs split the connection four ways, but you can also find two-way hubs and others with seven ports or more. To connect more devices than that, simply connect additional hubs in series with the first one.

Each USB host controller is supposed to support up to 127 separate devices, but that's somewhat misleading. It can be done if you connect 127 mice (or other very low-bandwidth interrupt-transfer devices) through the same host, but if you add something like a speaker or a network router to the mix, you will have trouble supporting more than six or eight other devices.

Fortunately, most new computers have more than one host controller. Your computer's chipset includes a USB controller that exchanges data with the Southbridge. Depending on the specific chipset on your motherboard, it can support six, eight, or ten USB hosts, although many motherboards have fewer physical connectors than that. Each USB host connector on the motherboard can connect to one connector on the case.

If the motherboard (or the case) doesn't have enough USB host connectors for everything you want to plug into them, either add a USB hub, or install one or more additional USB controllers on expansion cards in the computer's PCI sockets. If it's a laptop computer, use a hub or a USB controller on a PC Card.

Power distribution

In addition to data exchange, a USB host can also supply electric power to a peripheral device such as a mouse or a keyboard, as long as the maximum power drain is less than about half an amp (500 mA). Larger peripherals like printers normally have their own power supplies.

A USB port can have one of several power modes:

  • Root port: Power to a root port comes directly from the USB Host Controller. A computer that runs on external power must supply at least 500 mA to each port. A battery-powered computer may supply either 100 mA or 500 mA.

  • Bus-powered hubs: A bus-powered hub draws all of its power from the host or from a hub between this one and the computer. An external device connected to a bus-powered hub can draw a maximum of 100 mA.

  • Self-powered hubs: A self-powered hub, or simply a powered hub, gets its power from an external power supply or an internal battery rather than the USB host. A hub with external power must supply up to 500 mA to each port. A battery-powered hub may supply either 100 mA or 500 mA to each port.

Therefore, when you shop for a hub, you must choose either a bus-powered hub or a self-powered hub, depending on the type of peripheral devices you plan to use with it. For general use, a self-powered hub is the better choice because it can support more than one bus-powered USB device at the same time. A bus-powered hub may not provide enough power for multiple bus-powered devices, especially with a laptop or other system that uses batteries instead of external power.

Enumeration

When a USB host starts, it detects all of the devices connected to it. This process (called enumeration) in which the computer assigns an address to each device includes these steps:

  1. The USB host detects one or more devices and sends a reset command.

  2. The host requests a series of descriptors from each device. These descriptors identify the type of device-interrupt, isochronous, or bulk, terms defined later in this chapter-along with the amount of bandwidth each device requires, and other configuration information.

  3. After the host controller receives the descriptors, it assigns an address to each device.

  4. Windows asks for a device driver.

  5. Reserving 10 percent of the total bandwidth for bulk transfers and control packets, it continues to accept and enumerate additional devices until the entire maximum bandwidth (480 Mb per second) has been claimed.

If the host detects a new interrupt device or isochronous device (because a user has plugged another device into a hub), it adds that device to the enumeration, unless the host is already supporting its maximum bandwidth. When a user unplugs a device (or turns it off), the host removes that device's load from the enumeration.

The purpose of enumeration is to identify each device and to allow the USB host to keep track of the maximum bandwidth that all the devices connected to it can use. When the demand exceeds that maximum, the host won't accept any more connections.

Data transfer

Remember that a USB host can handle three different kinds of data: interrupt, isochronous, and bulk. During enumeration, the USB host notes the address and data transfer mode for each connected device. When more than one device connected to the same host wants to transfer data at the same time, the host uses a combination of priorities and shared bandwidth to fulfill the demands it receives from each device.

Note 

USB data transfers take place at different speeds, depending on the requirements of each device and each type of data. Just because one transfer is considered slow compared with another, it's still zipping along; we're talking about the difference between tenths of a second and milliseconds.

Interrupt transfers

Almost all messages that move between interrupt devices and the USB are extremely short: things such as a single scan code from a keyboard or an instruction to light an indicator on the device. Because they don't use much bandwidth, the USB controller can move interrupt transfers without interfering with more time-sensitive isochronous transfers.

When one or more interrupt devices are connected to the USB host, the host conducts a periodic poll of each device to learn if a device has placed an interrupt request in its (the device's) buffer. When the host detects an interrupt request, it transfers the request from the buffer to the CPU and sends an acknowledgement back to the originating device. If the host does not receive the data successfully, it returns a failure message and the originating device tries a resend.

When the host originates a transfer to an interrupt device, it begins by sending the device an "attention" message, followed immediately by the message.

Isochronous transfers

Isochronous transfers are continuous streams of digital data that often require transfers at relatively high speed, such as audio or video. The host or originating device initiates the transfer with a series of control messages; but because it's more important to maintain the ongoing stream of bits to or from the computer, the USB host doesn't bother to take up bandwidth with acknowledgements or other handshaking data after the transfer begins.

Bulk transfers

Bulk transfers are used for bursty data which moves in occasional spurts rather than continuous streams, such as a page of data to a printer or an image from a scanner or a digital camera. Because accuracy is more important than speed, the device and the USB host apply extensive error correction to every data packet.

Both interrupt transfers and isochronous transfers have priority over bulk transfers, so a bulk transfer might be slower than normal when it shares a USB port with an active isochronous transfer. A bulk job uses the spare bandwidth left over after the host controller has allocated bandwidth to other transfers. It also uses that 10 percent of the total bandwidth that the host reserved during enumeration. In other words, a print job might take longer than usual if you try to print while you're listening to music through USB speakers.

Therefore, it's often possible to optimize the performance of all the USB devices connected to your computer by connecting devices that use bulk transfers and isochronous transfers to separate USB connectors on the computer, rather than connecting them through the same hub.




PC User's Bible
PC Users Bible
ISBN: 0470088974
EAN: 2147483647
Year: 2007
Pages: 372

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net