📄 usbs-devtab.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>Devtab Entries</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="Starting up a USB Device"HREF="usbs-start.html"><LINKREL="NEXT"TITLE="Receiving Data from the Host"HREF="usbs-start-rx.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="usbs-start.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="usbs-start-rx.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="USBS-DEVTAB">Devtab Entries</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN16237"></A><H2>Name</H2>Devtab Entries -- Data endpoint data structure</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN16240"><H2>Synopsis</H2><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SYNOPSIS">/dev/usb0c/dev/usb1r/dev/usb2w</PRE></TD></TR></TABLE></DIV><DIVCLASS="REFSECT1"><ANAME="AEN16242"></A><H2>Devtab Entries</H2><P>USB device drivers provide two ways of transferring data between hostand peripheral. The first involves USB-specific functionality such as<AHREF="usbs-start-rx.html"><TTCLASS="FUNCTION">usbs_start_rx_buffer</TT></A>.This provides non-blocking I/O: a transfer is started, and some timelater the device driver will call a supplied completion function. Thesecond uses the conventional I/O model: there are entries in thedevice table corresponding to the various endpoints. Standard callssuch as <TTCLASS="FUNCTION">open</TT> can then be used to get a suitablehandle. Actual I/O happens via blocking <TTCLASS="FUNCTION">read</TT> and<TTCLASS="FUNCTION">write</TT> calls. In practice the blocking operationsare simply implemented using the underlying non-blockingfunctionality.</P><P>Each endpoint will have its own devtab entry. The exact names arecontrolled by the device driver package, but typically the root willbe <TTCLASS="LITERAL">/dev/usb</TT>. This is followed by one or moredecimal digits giving the endpoint number, followed by<TTCLASS="LITERAL">c</TT> for a control endpoint, <TTCLASS="LITERAL">r</TT> fora receive endpoint (host to peripheral), and <TTCLASS="LITERAL">w</TT> fora transmit endpoint (peripheral to host). If the target hardwareinvolves more than one USB device then different roots should be used,for example <TTCLASS="LITERAL">/dev/usb0c</TT> and<TTCLASS="LITERAL">/dev/usb1_0c</TT>. This may require explicitmanipulation of device driver configuration options by the applicationdeveloper.</P><P>At present the devtab entry for a control endpoint does not supportany I/O operations. </P><DIVCLASS="REFSECT2"><ANAME="AEN16258"></A><H3><TTCLASS="FUNCTION">write</TT> operations</H3><P><TTCLASS="FUNCTION">cyg_io_write</TT> and similar functions inhigher-level packages can be used to perform a transfer fromperipheral to host. Successive write operations will not be coalesced.For example, when doing a 1000 byte write to an endpoint that uses thebulk transfer protocol this will involve 15 full-size 64-byte packetsand a terminating 40-byte packet. USB device drivers are not expectedto do any locking, and if higher-level code performs multipleconcurrent write operations on a single endpoint then the resultingbehaviour is undefined.</P><P>A USB <TTCLASS="FUNCTION">write</TT> operation will never transfer lessdata than specified. It is the responsibility of higher-level code toensure that the amount of data being transferred is acceptable to thehost-side code. Usually this will be defined by a higher-levelprotocol. If an attempt is made to transfer more data than the hostexpects then the resulting behaviour is undefined.</P><P>There are two likely error conditions. <TTCLASS="LITERAL">EPIPE</TT>indicates that the connection between host and target has been broken.<TTCLASS="LITERAL">EAGAIN</TT> indicates that the endpoint has beenstalled, either at the request of the host or by other activityinside the peripheral.</P></DIV><DIVCLASS="REFSECT2"><ANAME="AEN16268"></A><H3><TTCLASS="FUNCTION">read</TT> operations</H3><P><TTCLASS="FUNCTION">cyg_io_read</TT> and similar functions in higher-levelpackages can be used to perform a transfer from host to peripheral.This should be a complete transfer: higher-level protocols shoulddefine an upper bound on the amount of data being transferred, and the<TTCLASS="FUNCTION">read</TT> operation should involve at least thisamount of data. The return value will indicate the actual transfersize, which may be less than requested.</P><P>Some device drivers may support partial reads, but USB device driversare not expected to perform any buffering because that involves bothmemory and code overheads. One technique that may work for bulktransfers is to exploit the fact that such transfers happen in 64-bytepackets. It is possible to <TTCLASS="FUNCTION">read</TT> an initial 64bytes, corresponding to the first packet in the transfer. These 64bytes can then be examined to determine the total transfer size, andthe remaining data can be transferred in another<TTCLASS="FUNCTION">read</TT> operation. This technique is not guaranteedto work with all USB hardware. Also, if the delay between acceptingthe first packet and the remainder of the transfer is excessive thenthis could cause timeout problems for the host-side software. Forthese reasons the use of partial reads should be avoided.</P><P>There are two likely error conditions. <TTCLASS="LITERAL">EPIPE</TT>indicates that the connection between host and target has been broken.<TTCLASS="LITERAL">EAGAIN</TT> indicates that the endpoint has beenstalled, either at the request of the host or by other activityinside the peripheral.</P><P>USB device drivers are not expected to do any locking. If higher-levelcode performs multiple concurrent read operations on a single endpointthen the resulting behaviour is undefined.</P></DIV><DIVCLASS="REFSECT2"><ANAME="AEN16281"></A><H3><TTCLASS="FUNCTION">select</TT> operations</H3><P>Typical USB device drivers will not provide any support for<TTCLASS="FUNCTION">select</TT>. Consider bulk transfers from the host tothe peripheral. At the USB device driver level there is no way ofknowing in advance how large a transfer will be, so it is not feasiblefor the device driver to buffer the entire transfer. It may bepossible to buffer part of the transfer, for example the first 64-bytepacket, and copy this into application space at the start of a<TTCLASS="FUNCTION">read</TT>, but this adds code and memory overheads.Worse, it means that there is an unknown but potentially long delaybetween a peripheral accepting the first packet of a transfer and theremaining packets, which could confuse or upset the host-sidesoftware.</P><P>With some USB hardware it may be possible for the device driver todetect OUT tokens from the host without actually accepting the data,and this would indicate that a <TTCLASS="FUNCTION">read</TT> is likely tosucceed. However, it would not be reliable since the host-side I/Ooperation could time out. A similar mechanism could be used toimplement <TTCLASS="FUNCTION">select</TT> for outgoing data, but againthis would not be reliable.</P><P>Some device drivers may provide partial support for<TTCLASS="FUNCTION">select</TT> anyway, possibly under the control of aconfiguration option. The device driver's documentation should beconsulted for further information. It is also worth noting that theUSB-specific non-blocking API can often be used as an alternative to<TTCLASS="FUNCTION">select</TT>.</P></DIV><DIVCLASS="REFSECT2"><ANAME="AEN16293"></A><H3><TTCLASS="FUNCTION">get_config</TT> and<TTCLASS="FUNCTION">set_config</TT> operations</H3><P>There are no <TTCLASS="FUNCTION">set_config</TT> or<TTCLASS="FUNCTION">get_config</TT> (also known as<TTCLASS="FUNCTION">ioctl</TT>) operations defined for USB devices.Some device drivers may provide hardware-specific facilities this way. </P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>Currently the USB-specific functions related to <AHREF="usbs-halt.html">halted endpoints</A> cannot be accessed readilyvia devtab entries. This functionality should probably be madeavailable via <TTCLASS="FUNCTION">set_config</TT> and<TTCLASS="FUNCTION">get_config</TT>. It may also prove useful to providea <TTCLASS="FUNCTION">get_config</TT> operation that maps from thedevtab entries to the underlying endpoint data structures.</P></BLOCKQUOTE></DIV></DIV><DIVCLASS="REFSECT2"><ANAME="AEN16307"></A><H3>Presence</H3><P>The devtab entries are optional. If the USB device is accessedprimarily by class-specific code such as the USB-ethernet package andthat package uses the USB-specific API directly, the devtab entriesare redundant. Even if application code does need to access the USBdevice, the non-blocking API may be more convenient than the blockingI/O provided via the devtab entries. In these cases the devtab entriesserve no useful purpose, but they still impose a memory overhead. Itis possible to suppress the presence of these entries by disabling theconfiguration option<TTCLASS="LITERAL">CYGGLO_IO_USB_SLAVE_PROVIDE_DEVTAB_ENTRIES</TT>.</P></DIV></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="usbs-start.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-start-rx.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Starting up a USB Device</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-usb-slave.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Receiving Data from the Host</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -