IntroductiontoUSB As its name suggests, Universal Serial Bus (USB) is an external bus architecture for connecting USB-capable peripheral devices to a host computer. USB was not designed to be used as the internal bus for connecting CPUs to main memory and other motherboard-resident devices. Instead, USB is a communication protocol that supports serial data transfers between a host system and USB-capable peripherals. USB technology was developed as a solution to the increasing end-user demands on computers and the need for flexible and easy-to-use peripherals. A number of standard PC peripherals such as keyboards, mice, joysticks, digital cameras, CTI (computer telephone integration) and video conferencing products benefit directly from USB. USB offers a number of benefits to system designers: • USB provides a single, well-defined, standard connector type for all USB devices. This simplifies the design of USB devices as well as simplifying the end user's task of figuring out which plugs go into which sockets. • Reduced hardware complexity—no need for separate keyboard, mouse, modem, and printer ports. • Hot-Pluggable support—USB devices can be safely connected and disconnected without requiring that the host be shut off. Other generic peripheral connection standards, such as the Small Computer Systems Interface (SCSI), do not offer this feature. Hot-pluggable support is a key feature behind USB. • Plug-and-Play support so the host computer can identify USB devices when they are plugged in and configure them by loading the appropriate driver. This is another key feature for the inception of USB technology. • USB devices can be powered by drawing current directly from the USB cable (known as "bus power"), use external power, or a combination of both. • USB supports power saving suspend/resume modes. • USB offers high speed (12 megabits/second) and low speed (1.5 megabits/second) modes that can support a variety of peripherals. • USB can guarantee certain amounts of bandwidth for devices that cannot tolerate "bursty" transmission, such as streaming audio and video devices. • The USB protocol offers four different transfer types, suited to the needs of various types of peripherals. • Multiple peripherals can communicate with the host simultaneously. Note The official Universal Serial Bus Specification uses the term "function" to refer to USB-capable peripheral devices. To avoid any confusion with the term "function" as it refers to callable units of C/C++ code, the Windows CE documentation set will use the term "USB device" instead. USB System Architecture This section provides a brief overview of the organization of the Universal Serial Bus itself and of the software that must be present on the host computer. A USB system is composed of a host side, a device side, and the physical bus represented by the USB cable. The main responsibility of the host is to provide a control interface for data transfers, whereas the device side provides the end user with various functions. The host side itself consists of a USB adapter or USB host controller hardware layer and an upper-level System Software layer. The host controller is responsible for transferring streams of data between the host and the USB devices. Bus Topology USB is a tree-structured bus, which, in the vocabulary of the USB developers' organization, is called a "Star-Tier topology." The host computer contains the root node of the bus, which is called a "hub." Any node within a USB bus that is an intermediary between peripheral devices and the host computer is a hub. A hub has exactly one connection to higher levels in the USB bus than itself (an "upstream port," and can have up to 7 ports for connecting peripheral devices and other hubs. Up to 127 devices can be connected in this manner. Peripheral devices are always leaf nodes within a USB bus. However, as a matter of practical implementation, many USB peripheral devices have a hub integrated into them so that users do not often have to purchase separate USB hubs. The following illustration shows a typical USB bus with several common peripherals connected. This illustration is modeled after the diagram of a typical USB bus configuration in the Universal Serial Bus Specification, Revision 1.0, but with the hubs and peripheral devices represented more explicitly: Figure 1. A typical USB bus Note that the association of the mouse with the keyboard's internal hub and the speakers with the monitor's internal hub is entirely arbitrary. For example, a user could instead connect the mouse to the monitor's internal hub, the modem to the keyboard's internal hub, and the speakers to the standalone hub in tier 1 without impacting the system's functionality and without having to make any changes to the configuration of software on the host computer. System Software As illustrated in the diagram below, a USB system consists of a host side, a device side, and the physical bus represented by the USB cable. The main responsibility of the host is to provide control interface for data transfers, whereas the client provides the end user with various functions. The host side itself consists of a USB adapter or USB Host Controller hardware layer and an upper-level System Software layer. The host controller is responsible for transferring streams of data between the host and the USB devices. The host controller provides services based on parameters provided by the host software when the configuration request is made. The system software for USB consists of two layers. The top layer consists of USB device drivers. Such drivers establish a connection to the device they control and use the USB system software functions to configure and communicate with the device. The bottom layer consists of the USB system software. This software performs several tasks: • Manage all communication between USB device drivers and the host computer's built-in USB root hub. • Load and unload USB device drivers at the appropriate times. • Translate data to and from the USB protocol's frame and packet formats. • Establish communication with the generic endpoint on all USB devices connected to the bus in order to perform generic configuration and status- related tasks. The USB system software is itself composed of two major parts, the upper Universal Serial Bus Driver (USBD) module, and the lower Host Controller Driver (HCD) module. The USBD module implements the high-level USB functions that USB device drivers use in terms of the functionality provided by the HCD module. The HCD module interfaces between the particular USB host controller hardware (such as OHCI or UHCI adapters) and the USBD module. IHVs and manufacturers of USB devices will be concerned with the top layer, since they will need to provide device drivers for their USB devices for any operating systems that their USB devices will be used with. OEMs will be primarily concerned with the bottom layer, since they will need to ensure that their Windows CE platform's hardware properly interfaces with the USBD module. The following illustration shows these two layers of software in the context of the host's USB hardware and a peripheral device: Figure 2. USB layers The flow of operation is typically: 1 A USB device driver initiates transfers by using USBDI APIs to issue requests to the USBD module. 2 The USBD module divides requests into individual transactions based on its knowledge of the bus and characteristics of the USB devices connected to the bus. 3 The HCD module schedules these transactions over the bus. 4 The host controller hardware actually performs or completes the transactions Note that all transactions on the bus originate from the host side; the peripherals perform only as slaves in this master-slave environment. USB Devices USB devices consist of one or more "interfaces," which are the physical components of the peripheral that implement the device's abilities. Associated with each interface is a set of endpoints; endpoints are the ultimate producers or consumers of data that travels across the bus. In addition, all USB devices have a special endpoint, known as "endpoint 0," which supports the generic USB status and configuration protocol. Every device known to the HCD module has a unique USB address assigned to it when it is attached. USB device drivers establish logical communication channels, called "pipes," to the various endpoints on a USB device. The characteristics of a pipe (for example, direction of communication, required bandwidth, and so on) are determined by the endpoint characteristics, which are indicated in the endpoint descriptor structure. A pipe is a software association between an endpoint and a USB device driver. At implementation level, pipes can be thought of as software channels using function calls within the USB system software in order to communicate with their associated endpoints. The bus interface hardware on a USB device is responsible for transmission and reception of USB structured data. A logical USB device consists of the USB abstraction entities such as the device endpoints and their corresponding pipes. An "interface" is a higher level entity that consists of one or more pipes and corresponds to some useful unit of functionality for the host computer. For example, a haptic input device, such as a force-feedback joystick, could have separate pipes for the position information that the joystick sends to the host computer and the force- feedback information that the host computer sends to the joystick. Taken together, that collection of pipes is known as an "interface" because it corresponds to the joystick as a whole. An interface can be controlled by exactly one USB device driver. USB Serial Host Driver To enable USB connectivity, the desktop computer running Microsoft Windows 98 or Windows 2000 also needs a USB driver that enables communication with the Windows CE device through a USB connection. Such a driver is available in Microsoft Windows CE Platform Builder, and is called USB Serial Host driver, WCEUSBSH.SYS. Note that this driver is not for use on Windows CE-based platforms; it is the desktop software required to enable USB connectivity between desktop PCs and Windows CE-based platforms. Microsoft ActiveSync 3.1 installs this driver on desktop computers. The main task of the USB Serial Host driver is to expose the standard Win32 serial interface to the upper-level application—such as ActiveSync—so that the application can use the USB connection as if it were a standard serial port connection. If an OEMs Windows CE-based platform uses ActiveSync to connect to desktop PCs, the OEM does not need to do anything else to enable USB connectivity. However, if the OEM’s platform does not use ActiveSync, but requires USB connectivity, then the OEM must provide the USB Serial Host Driver to their customers. Typically, an OEM would provide a setup application to customers which installs the necessary desktop connectivity components, including this driver and an appropriate .INF file. Installing this device driver is no different than any other device driver for Windows 98 or Windows 2000: 1. Copy the driver’s .SYS and .INF files to the desktop computer; for example, to the C:\Temp directory. 2. Have the user connect the Windows CE-based platform to the desktop computer’s USB port. This will invoke the Microsoft Windows “Found New Hardware” Wizard. 3. Enter the directory from step 1 into the wizard to complete the installation. Built on Wednesday, October 04, 2000 . files to the desktop computer; for example, to the C:Temp directory. 2. Have the user connect the Windows CE-based platform to the desktop computer’s USB. directly from USB. USB offers a number of benefits to system designers: • USB provides a single, well-defined, standard connector type for all USB devices.