📄 usbs-intro.html
字号:
<!-- Copyright (C) 2003 Red Hat, Inc. --><!-- This material may be distributed only subject to the terms --><!-- and conditions set forth in the Open Publication License, v1.0 --><!-- or later (the latest version is presently available at --><!-- http://www.opencontent.org/openpub/). --><!-- Distribution of the work or derivative of the work in any --><!-- standard (paper) book form is prohibited unless prior --><!-- permission is obtained from the copyright holder. --><HTML><HEAD><TITLE>Introduction</TITLE><meta name="MSSmartTagsPreventParsing" content="TRUE"><METANAME="GENERATOR"CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+"><LINKREL="HOME"TITLE="eCos Reference Manual"HREF="ecos-ref.html"><LINKREL="UP"TITLE="eCos USB Slave Support"HREF="io-usb-slave.html"><LINKREL="PREVIOUS"TITLE="eCos USB Slave Support"HREF="io-usb-slave.html"><LINKREL="NEXT"TITLE="USB Enumeration Data"HREF="usbs-enum.html"></HEAD><BODYCLASS="REFENTRY"BGCOLOR="#FFFFFF"TEXT="#000000"LINK="#0000FF"VLINK="#840084"ALINK="#0000FF"><DIVCLASS="NAVHEADER"><TABLESUMMARY="Header navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><THCOLSPAN="3"ALIGN="center">eCos Reference Manual</TH></TR><TR><TDWIDTH="10%"ALIGN="left"VALIGN="bottom"><AHREF="io-usb-slave.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="usbs-enum.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="USBS-INTRO">Introduction</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN16043"></A><H2>Name</H2>Introduction -- eCos support for USB slave devices</DIV><DIVCLASS="REFSECT1"><ANAME="AEN16046"></A><H2>Introduction</H2><P>The eCos USB slave support allows developers to produce USBperipherals. It consists of a number of different eCos packages:</P><P></P><OLTYPE="1"><LI><P>Device drivers for specific implementations of USB slave hardware, forexample the on-chip USB Device Controller provided by the Intel SA1110processor. A typical USB peripheral will only provide one USB slaveport and therefore only one such device driver package will be needed.Usually the device driver package will be loaded automatically whenyou create an eCos configuration for target hardware that has a USBslave device. If you select a target which does have a USB slavedevice but no USB device driver is loaded, this implies that no suchdevice driver is currently available.</P></LI><LI><P>The common USB slave package. This serves two purposes. It defines theAPI that specific device drivers should implement. It also providesvarious utilities that will be needed by most USB device drivers andapplications, such as handlers for standard control messages.Usually this package will be loaded automatically at the same time asthe USB device driver.</P></LI><LI><P>The common USB package. This merely provides some information commonto both the host and slave sides of USB, such as details of thecontrol protocol. It is also used to place the other USB-relatedpackages appropriately in the overall configuration hierarchy. Usuallythis package will be loaded at the same time as the USB device driver.</P></LI><LI><P>Class-specific USB support packages. These make it easier to developspecific classes of USB peripheral, such as a USB-ethernet device. Ifno suitable package is available for a given class of peripheral thenthe USB device driver can instead be accessed directly fromapplication code. Such packages will never be loaded automaticallysince the configuration system has no way of knowing what class of USBperipheral is being developed. Instead developers have to add theappropriate package or packages explicitly.</P></LI></OL><P>These packages only provide support for developing USB peripherals,not USB hosts.</P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN16059"></A><H2>USB Concepts</H2><P>Information about USB can be obtained from a number of sourcesincluding the <AHREF="http://www.usb.org/"TARGET="_top">USB Implementers Forumweb site</A>. Only a brief summary is provided here.</P><P>A USB network is asymmetrical: it consists of a single host, one ormore slave devices, and possibly some number of intermediate hubs. Thehost side is significantly more complicated than the slave side.Essentially, all operations are initiated by the host. For example, ifthe host needs to receive some data from a particular USB peripheralthen it will send an IN token to that peripheral; the latter shouldrespond with either a NAK or with appropriate data. Similarly, whenthe host wants to transmit data to a peripheral it will send an OUTtoken followed by the data; the peripheral will return a NAK if it iscurrently unable to receive more data or if there was corruption,otherwise it will return an ACK. All transfers are check-summed andthere is a clearly-defined error recovery process. USB peripherals canonly interact with the host, not with each other.</P><P>USB supports four different types of communication: control messages,interrupt transfers, isochronous transfers, and bulk transfers.Control messages are further subdivided into four categories:standard, class, vendor and a reserved category. All USB peripheralsmust respond to certain standard control messages, and usually thiswill be handled by the common USB slave package (for complicatedperipherals, application support will be needed). Class and vendorcontrol messages may be handled by an class-specific USB supportpackage, for example the USB-ethernet package will handle controlmessages such as getting the MAC address or enabling/disablingpromiscuous mode. Alternatively, some or all of these messages willhave to be handled by application code.</P><P>Interrupt transfers are used for devices which need to be polledregularly. For example, a USB keyboard might be polled once everymillisecond. The host will not poll the device more frequently thanthis, so interrupt transfers are best suited to peripherals thatinvolve a relatively small amount of data. Isochronous transfers areintended for multimedia-related peripherals where typically a largeamount of video or audio data needs to be exchanged continuously.Given appropriate host support a USB peripheral can reserve some ofthe available bandwidth. Isochronous transfers are not reliable; if aparticular packet is corrupted then it will just be discarded andsoftware is expected to recover from this. Bulk transfers are used foreverything else: after taking care of any pending control, isochronousand interrupt transfers the host will use whatever bandwidth remainsfor bulk transfers. Bulk transfers are reliable.</P><P>Transfers are organized into USB packets, with the details dependingon the transfer type. Control messages always involve an initial8-byte packet from host to peripheral, optionally followed by someadditional packets; in theory these additional packets can be up to 64bytes, but hardware may limit it to 8 bytes. Interrupt transfersinvolve a single packet of up to 64 bytes. Isochronous transfersinvolve a single packet of up to 1024 bytes. Bulk transfers involvemultiple packets. There will be some number, possibly zero, of 64-bytepackets. The transfer is terminated by a single packet of less than 64bytes. If the transfer involves an exact multiple of 64 bytes than thefinal packet will be 0 bytes, consisting of just a header and checksumwhich typically will be generated by the hardware. There is nopre-defined limit on the size of a bulk transfer. Instead higher-levelprotocols are expected to handle this, so for a USB-ethernetperipheral the protocol could impose a limit of 1514 bytes of dataplus maybe some additional protocol overhead.</P><P>Transfers from the host to a peripheral are addressed not just to thatperipheral but to a specific endpoint within that peripheral.Similarly, the host requests incoming data from a specific endpointrather than from the peripheral as a whole. For example, a combinedkeyboard/touchpad device could provide the keyboard events on endpoint1 and the mouse events on endpoint 2. A given USB peripheral can haveup to 16 endpoints for incoming data and another 16 for outgoing data.However, given the comparatively high speed of USB I/O this endpointaddressing is typically implemented in hardware rather than software,and the hardware will only implement a small number of endpoints.Endpoint 0 is generally used only for control messages.</P><P>In practice, many of these details are irrelevant to application codeor to class packages. Instead, such higher-level code usually justperforms blocking <TTCLASS="FUNCTION">read</TT
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -