usbintro.sgml

来自「usb develop guide」· SGML 代码 · 共 325 行

SGML
325
字号
<chapter><title>USB Introduction</><para>This chapter provides a brief introduction into the Universal Serial Bus(USB) in general, and may be skipped if you are already familiar with thebus, and its software and hardware architecture.</><Sect1><title>The Universal Serial Bus</title><para>In 1994 an alliance of four industrial partners (Compaq, Intel, Microsoftand NEC) started to specify the Universal Serial Bus (USB). The bus wasoriginally designed with these intentions:<itemizedlist><listitem><para>Connection of the PC to the telephone</para></listitem><listitem><para>Ease-of-use</para></listitem><listitem><para>Port expansion</para></listitem></itemizedlist></para><para>The specification (version 1.0) was first released inJanuary 1996 and the latest official version 1.1 was released in September 1998The document is still under development and a version 2.0 wasannounced in 1999. The USB is strictly hierarchical and it is controlled by onehost. The host uses a master / slave protocol to communicate with attached USBdevices. This means that every kind of communication is initiated by the hostand devices cannot establish any direct connection to other devices. This seemsto be a drawback in comparison to other bus architectures but it is notbecause the USB was designed as a compromise of costs and performance.The master / slave protocol solves implicitly problems like collisionavoidance or distributed bus arbitration. The current implementation of theUSB allows 127 devices to be connected at the same time and the totalcommunication bandwidth is limited to 12Mbit/s. Howewer use of low speeddevices, management of USB "interrupts" and other overheads mean that actualthroughput cannot exceed about 8.5Mbit/s under near ideal conditions, andtypical performance may be around 2Mbit/s.</para></Sect1><Sect1><title>Host Controllers</title><para>Most modern motherboard chipsets provide a USB host controller. Older machineswhich are not equipped with a USB host controller can be upgraded using a PCIcards with a host controller built in. </><para>USB host controllers arecompatible with either the Open Host Controller Interface (OHCI, by Compaq) orthe Universal Host Controller Interface (UHCI, by Intel) standard. Both typeshave the same capabilities and USB devices work with both host controllertypes. Basically the hardware of UHCI is simpler and therefore it ischeaper, but needs a more complex device driver, which could cause slightlymore CPU load. </para></Sect1><Sect1><title>USB Devices and Transfer Characteristics</title><para>There are a wide range of USB devices intended for a wide range ofpurposes, and this means that implementation details can vary widely. </para><para>A device can be self powered,  bus powered or both. The USB can providea power supply up to 500mA for its devices. If there are only bus powereddevices on the bus the maximum power dissipation could be exceeded andtherefore self powered devices exist. They need to have their own powersupply. Devices that support both power types can switch to self powered modewhen attaching an external power supply. </para><para>Even the maximum communication speed can differ for particular USB devices.The USB specification differentiates between low speed and  full speed devices.Low speed devices (such as mice, keyboards, joysticks etc.) communicateat 1.5MBit/s and have only limited capabilities. Full speed devices (suchas audio and video systems) can use up to 90% of the 12Mbit/s which is about10Mbit/s including the protocol overhead.</para><figure id="FigTopology"><title>USB Topology</title><graphic srccredit="Deti Fliegl" fileref="topo"></graphic></figure><para>Version 2.0 of the USB specification is being developed, and is expected todeliver up to 480Mbit/s raw throughput.</para><Sect2><title>Hubs</title><para>Physically there exist one, two or four USB ports at the rear panel of acomputer. These ports can be used to attach normal devices or a hub. Ahub is a USB device which extends the number of ports toconnect other USB devices. The maximum number of user devices is reducedby the number of hubs on the bus (i.e. if you attach 50 hubs, then at most 77 (=127-50) additional devices can be attached. Hubs are always full speeddevices. If the hub is self powered, then any device can be attached to it.However if the hub is bus powered, then only low power (100mA max) devicescan be attached to it. A bus powered hub should not be connected to anotherbus powered hub - you should alternate between bus powered and self poweredhubs.</para><para>Normally the physical ports of the host controller are handled by avirtual root hub. This hub is simulated by the hostcontrollers device driver and helps to unify the bus topology. So every port canbe handled in the same way by the USB subsystem's hub driver (see<xref linkend="FigTopology">).</para></Sect2><Sect2><title>Data Flow Types</title><para>The communication on the USB is done in two directions and uses four differenttransfer types. Data directed from the host to a device is calleddownstream or OUT transfer. The other direction is calledupstream or IN transfer. Depending on the device type differenttransfer variants are used:<itemizedlist><listitem><para><Emphasis>Control transfers</emphasis> are used to request andsend reliable short data packets. It is used to configure devices and every oneis required to support a minimum set of control commands. The standard commands are:<simplelist><member>GET_STATUS</member><member>CLEAR_FEATURE</member><member>SET_FEATURE</member><member>SET_ADDRESS</><member>GET_DESCRIPTOR</><member>SET_DESCRIPTOR</><member>GET_CONFIGURATION</><member>SET_CONFIGURATION</><member>GET_INTERFACE</><member>SET_INTERFACE</><member>SYNCH_FRAME</></simplelist>Further control commands can be used to transfer vendor specific data.</para></listitem><listitem><para><emphasis>Bulk transfers</emphasis> are used to request or sendreliable data packets up to the full bus bandwidth. Devices like scanners orscsi adapters use this transfer type.</para></listitem><listitem><para><emphasis>Interrupt transfers</emphasis> are similar to bulktransfers which are polled periodically. If an interrupt transfer was submittedthe host controller driver will automatically repeat this request in a specifiedinterval (1ms - 127ms).</para></listitem><listitem><para><emphasis>Isochronous transfers</emphasis> send or receivedata streams in realtime with guaranteed bus bandwidth but without anyreliability. In general these transfer types are used for audio and videodevices.</para></listitem></itemizedlist></para></Sect2></Sect1><Sect1><title>Enumeration and Device Descriptors</title><para>Whenever a USB device is attached to the bus it will be enumerated by the USBsubsystem -  i.e an unique device number (1-127) is assigned and then thedevice descriptor is read. The desciptor is a data structure whichcontains information about the device and its properties. The USB standarddefines a hierarchy of descriptors (see <xref linkend="FigDescriptor">).</para><figure id="FigDescriptor"><title>USB Descriptor</title><graphic srccredit="Deti Fliegl" fileref="descr"></graphic></figure><Sect2><title>Standard Descriptors</title><para><itemizedlist><listitem><para>A <emphasis>Device Descriptor</emphasis> describes generalinformation about a USB device. It includes information that applies globally tothe device and all of the device s configurations. A USB device has only onedevice descriptor.</para></listitem><listitem><para>The <emphasis>Configuration Descriptor</emphasis>  givesinformation about a specific device configuration. A USB device has one or moreconfiguration descriptors. Each configuration has one or more interfaces andeach interface has zero or more endpoints. An endpoint is not shared amongdifferent interfaces within a single configuration, although a singleinterface can have several <emphasis>alternate settings</emphasis>which may use the same endpoint. Endpoints may be shared amonginterfaces that are part of different configurations without this restriction.Configurations can only be activated by the standard control transfer<systemitem>set_configuration</systemitem>.Different configurations can be used to change global device settings, such aspower consumption.</para></listitem><listitem><para>An <emphasis>Interface Descriptor</emphasis>  describes aspecific interface within a configuration. A configuration provides one or moreinterfaces, each with zero or more endpoint descriptors describing a unique setof endpoints within the configuration. An interface may include alternatesettings that allow the endpoints and/or their characteristics to be variedafter the device has been configured. The default setting for an interface isalways alternate setting zero. Alternate settings can be selected exclusively bythe standard control transfer <systemitem>set_interface</systemitem>. For example amultifunctional device like a video camera with internal microphone could havethree alternate settings to change the bandwidth allocation on the bus.<Simplelist><member>Camera activated</member><member>Microphone activated</member><member>Camera and microphone activated</member></simplelist></para></listitem><listitem><para>An <emphasis>Endpoint Descriptor</emphasis>  containsinformation required by the host to determine the bandwidth requirements of eachendpoint. An endpoint represents a logical data source or sink of a USB device.The endpoint zero is used for all control transfers and there is never adescriptor for this endpoint. The USB specification uses theterms pipe and endpoint interchangably.</para></listitem><listitem><para><emphasis>String Descriptors</emphasis>  are optional andprovide additional information in human readable unicode format. They can beused for vendor and device names or serial numbers.</para></listitem></Itemizedlist></para></Sect2><Sect2><title>Device Classes</title><para>The standard device and interface descriptors contain fields that are relatedto classification: class, sub-class and protocol. These fields may be used bya host system to associate a device or interface to a driver, depending on howthey are specified by the class specification. Valid valuesfor the class fields of the device and interface descriptors are defined bythe USB Device Working Group.</><para>Grouping devices or interfaces together in classes and thenspecifying the characteristics in a Class Specification allows the developmentof host software which can manage multiple implementations based on thatclass. Such host software adapts its operation to a specific device orinterface using descriptive information presented by the device. A classspecification serves as a framework defining the minimum operation of alldevices or interfaces which identify themselves as members of the class.</para></Sect2><Sect2><title>Human Interface Devices (HID)</title><para>The HID class consists primarily of devices that are used by humans tocontrol the operation of computer systems. Typical examples of HID class devicesinclude:<simplelist><member>Keyboards and pointing devices for example, standard mouse devices,trackballs, and joysticks.</><member>Front-panel controls for example: knobs, switches, buttons, and sliders.</><member>Controls that might be found on devices such as telephones, VCR remotecontrols, games or simulation devices for example: data gloves, throttles,steering wheels, and rudder pedals.</></simplelist></para></Sect2></Sect1><Sect1><title>USB Device Drivers</title><para>Finding device drivers for USB devices presents someinteresting situations. In some cases the whole USB device is handled by asingle device driver. In other cases, each interface of the device has aseparate device driver.</para></Sect1></Chapter>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?