📄 usbs-intro.html
字号:
> and<TTCLASS="FUNCTION">write</TT>, or non-blocking USB-specific calls, totransfer data between host and target via a specific endpoint. Controlmessages are more complicated but are usually handled by existingcode.</P><P>When a USB peripheral is plugged into the host there is an initialenumeration and configuration process. The peripheral providesinformation such as its class of device (audio, video, etc.), avendor id, which endpoints should be used for what kind of data, andso on. The host OS uses this information to identify a suitable hostdevice driver. This could be a generic driver for a class ofperipherals, or it could be a vendor-specific driver. Assuming asuitable driver is installed the host will then activate the USBperipheral and perform additional application-specific initialisation.For example for a USB-ethernet device this would involve obtaining anethernet MAC address. Most USB peripherals will be fairly simple, butit is possible to build multifunction peripherals with multipleconfigurations, interfaces, and alternate interface settings.</P><P>It is not possible for any of the eCos packages to generate all theenumeration data automatically. Some of the required information suchas the vendor id cannot be supplied by generic packages; only by theapplication developer. Class support code such as the USB-ethernetpackage could in theory supply some of the information automatically,but there are also hardware dependencies such as which endpoints getused for incoming and outgoing ethernet frames. Instead it is theresponsibility of the application developer to provide all theenumeration data and perform some additional initialisation. Inaddition, the common USB slave package can handle all the standardcontrol messages for a simple USB peripheral, but for something like amultifunction peripheral additional application support is needed.</P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>The initial implementation of the eCos USB slave packages involvedhardware that only supported control and bulk transfers, notisochronous or interrupt. There may be future changes to the USBcode and API to allow for isochronous and interrupt transfers,especially the former. Other changes may be required to supportdifferent USB devices. At present there is no support for USB remotewakeups, since again it is not supported by the hardware.</P></BLOCKQUOTE></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN16075"></A><H2>eCos USB I/O Facilities</H2><P>For protocols other than control messages, eCos provides two ways ofperforming USB I/O. The first involves device table or devtab entries suchas <AHREF="usbs-devtab.html"><TTCLASS="LITERAL">/dev/usb1r</TT></A>,with one entry per endpoint per USB device. It is possible to<TTCLASS="FUNCTION">open</TT> these devices and use conventional blockingI/O functions such as <TTCLASS="FUNCTION">read</TT> and<TTCLASS="FUNCTION">write</TT> to exchange data between host andperipheral.</P><P>There is also a lower-level USB-specific API, consisting of functionssuch as <AHREF="usbs-start-rx.html"><TTCLASS="FUNCTION">usbs_start_rx_buffer</TT></A>.A USB device driver will supply a data structure for each endpoint,for example a <AHREF="usbs-data.html"><SPANCLASS="STRUCTNAME">usbs_rx_endpoint</SPAN></A>structure for every receive endpoint. The first argument to<TTCLASS="FUNCTION">usbs_start_rx_buffer</TT> should be a pointer to sucha data structure. The USB-specific API is non-blocking: the initialcall merely starts the transfer; some time later, once the transferhas completed or has been aborted, the device driver will invoke acompletion function.</P><P>Control messages are different. With four different categories ofcontrol messages including application and vendor specific ones, theconventional<TTCLASS="FUNCTION">open</TT>/<TTCLASS="FUNCTION">read</TT>/<TTCLASS="FUNCTION">write</TT>model of I/O cannot easily be applied. Instead, a USB device driverwill supply a <AHREF="usbs-control.html"><SPANCLASS="STRUCTNAME">usbs_control_endpoint</SPAN></A>data structure which can be manipulated appropriately. In practice thestandard control messages will usually be handled by the common USBslave package, and other control messages will be handled byclass-specific code such as the USB-ethernet package. Typically,application code remains responsible for supplying the <AHREF="usbs-enum.html">enumeration data</A> and for actually <AHREF="usbs-start.html">starting</A> up the USB device.</P></DIV><DIVCLASS="REFSECT1"><ANAME="AEN16097"></A><H2>Enabling the USB code</H2><P>If the target hardware contains a USB slave device then theappropriate USB device driver and the common packages will typicallybe loaded into the configuration automatically when that target isselected (assuming a suitable device driver exists). However, thedriver will not necessarily be active. For example a processor mighthave an on-chip USB device, but not all applications using thatprocessor will want to use USB functionality. Hence by default the USBdevice is disabled, ensuring that applications do not suffer anymemory or other penalties for functionality that is not required.</P><P>If the application developer explicitly adds a class support packagesuch as the USB-ethernet one then this implies that the USB device isactually needed, and the device will be enabled automatically.However, if no suitable class package is available and the USB devicewill instead be accessed by application code, it is necessary toenable the USB device manually. Usually the easiest way to do this isto enable the configuration option<TTCLASS="LITERAL">CYGGLO_IO_USB_SLAVE_APPLICATION</TT>, and the USB devicedriver and related packages will adjust accordingly. Alternatively,the device driver may provide some configuration options to providemore fine-grained control.</P></DIV><DIVCLASS="NAVFOOTER"><HRALIGN="LEFT"WIDTH="100%"><TABLESUMMARY="Footer navigation table"WIDTH="100%"BORDER="0"CELLPADDING="0"CELLSPACING="0"><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top"><AHREF="io-usb-slave.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="ecos-ref.html"ACCESSKEY="H">Home</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top"><AHREF="usbs-enum.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">eCos USB Slave Support</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-usb-slave.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">USB Enumeration Data</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -