⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbseth.sgml

📁 eCos操作系统源码
💻 SGML
📖 第 1 页 / 共 3 页
字号:
    usbs_sa11x0_ep0.enumeration_data    = &amp;usb_enum_data;    &hellip;    usbs_eth_init(&amp;usbs_eth0, &amp;usbs_sa11x0_ep0, &amp;usbs_sa11x0_ep1, &amp;usbs_sa11x0_ep2, host_MAC);    &hellip;    usbs_start(&amp;usbs_sa11x0_ep0);    &hellip;}</programlisting></refsect1></refentry><!-- }}} --><!-- {{{ Data Transfer                  --><refentry id="usbseth-data"><refmeta><refentrytitle>USB-ethernet Data Transfers</refentrytitle></refmeta><refnamediv><refname>USB-ethernet Data Transfers</refname><refpurpose>Exchanging ethernet packets with the USB host</refpurpose></refnamediv><refsynopsisdiv><funcsynopsis><funcsynopsisinfo>#include &lt;cyg/io/usb/usbs_eth.h&gt;</funcsynopsisinfo>	<funcprototype><funcdef>void <function>usbs_eth_start_rx</function></funcdef><paramdef>usbs_eth* <parameter>usbseth</parameter></paramdef><paramdef>unsigned char* <parameter>buffer</parameter></paramdef><paramdef>void (*)(usbs_eth*, void*, int) <parameter>complete_fn</parameter></paramdef><paramdef>void* <parameter>complete_data</parameter></paramdef></funcprototype><funcprototype><funcdef>void <function>usbs_eth_start_tx</function></funcdef><paramdef>usbs_eth* <parameter>usbseth</parameter></paramdef><paramdef>unsigned char* <parameter>buffer</parameter></paramdef><paramdef>void (*)(usbs_eth*, void*, int) <parameter>complete_fn</parameter></paramdef><paramdef>void* <parameter>complete_data</parameter></paramdef></funcprototype></funcsynopsis></refsynopsisdiv><refsect1><title>Description</title><para>The USB-ethernet package provides two main modes of operation. In thefirst mode it provides a <link linkend="usbseth-netdev">network devicedriver</link> for use by a TCP/IP stack running inside the USBperipheral. All incoming ethernet packets should be passed up theTCP/IP stack, and only the stack will generate outgoing packets. Apartfrom <link linkend="usbseth-init">initialization</link> and possiblycertain <link linkend="usbseth-control">control operations</link>,higher-level code will not interact with the USB-ethernet packagedirectly.</para><para>In the second mode there is no TCP/IP stack running inside the USBperipheral. For example, a simple USB-ethernet converter has anethernet chip and a USB port: ethernet packets received by theethernet chip need to be forwarded to the USB host, and ethernetpackets sent by the USB host need to be sent out of the ethernet chip.<function>usbs_eth_start_rx</function> and<function>usbs_eth_start_tx</function> allow for this lower-levelaccess to the USB-ethernet package.</para><para>The two modes of operation are mutually exclusive. If the networkdevice driver mode is enabled then application code should communicateat the TCP/IP level, and not by using the lower-level functions.Instead, it is the network device driver that will make use of thesefunctions, and it assumes that it has exclusive access. The packagedoes not perform any locking.</para><para>The transmit and receive functions work in much the same way. Thefirst argument identifies the <structname>usbs_eth</structname>structure that should be used. For the majority of applications thiswill be <literal>usbs_eth0</literal>. The second argument specifiesthe location of the ethernet packet; outgoing for<function>usbs_eth_start_tx</function> and incoming for<function>usbs_eth_start_rx</function>. This buffer should correspondto the <link linkend="usbseth-protocol">protocol</link>:</para><orderedlist><listitem><para>Outgoing packets can consist of up to 1516 bytes, consisting of atwo-byte header specific to USB-ethernet followed by a standardethernet frame (a header with 6-byte destination address, 6-bytesource address and a further two bytes, followed by a payload ofup to 1500 bytes). The two-byte USB-ethernet header consists simply ofthe size of the ethernet frame, i.e. the size of the rest of thepacket not including the USB-ethernet header, with the leastsignificant byte first.</para></listitem><listitem><para>For incoming packets the supplied buffer should usually be at least1516 bytes. There may be special circumstances in which a smallerbuffer might be safe; for example, if the host-side device driver ismodified to support only smaller packets. Once the packet has beenreceived the buffer will contain a two-byte header specific toUSB-ethernet, followed by a normal ethernet frame. The headergives the size of the ethernet frame, excluding the header, with theleast significant byte first.</para></listitem></orderedlist><para>Both <function>usbs_eth_start_tx</function> and<function>usbs_eth_start_rx</function> are asynchronous: the transferis started and, some time later, a completion function will be invoked.The third and fourth arguments to both<function>usbs_eth_start_tx</function> and<function>usbs_eth_start_rx</function> supply the completion functionand an argument to that function respectively. The completion functionwill be invoked with three arguments: a pointer to the<structname>usbs_eth</structname> data structure, usually<literal>usbs_eth0</literal>; the supplied completion data ; and areturn code field. A negative value indicates that an error occurred,for example <literal>-EPIPE</literal> if the connection between USBhost and peripheral has been broken, or <literal>-EAGAIN</literal> ifan endpoint has been halted. A positive value indicates the total sizeof the transfer, which should correspond to the size in theUSB-ethernet header plus an additional two bytes for the headeritself.</para><para>If the data transfer is succesful then the completion function willtypically be invoked in DSR context rather than in thread context,although this depends on the implementation of the underlying USBdevice driver. Therefore the completion function is restricted in whatit can do; in particular, it must not make any calls that will or mayblock such as locking a mutex or allocating memory. The kerneldocumentation should be consulted for more details of DSR's andinterrupt handling generally. Note that if the transfer finishesquickly then the completion function may be invoked before<function>usbs_eth_start_rx</function> or<function>usbs_eth_start_tx</function> returns. This is especiallylikely to happen if the current thread is descheduled after startingthe data transfer but before returning from these functions.</para><para>For transmit operations, it is possible for<function>usbs_eth_start_tx</function> to invoke the completionfunction immediately. If there is no current connection between hostand target then the transmit will fail immediately with<literal>-EPIPE</literal>. In addition the USB-ethernet package willcheck the destination MAC address and make sure that the ethernetframe really is intended for the host: either it must be for theaddress specified in the initialization call <linklinkend="usbseth-init"><function>usbs_eth_init</function></link>, orit must be a broadcast packet, or the host must have enabledpromiscuous mode. </para></refsect1></refentry><!-- }}} --><!-- {{{ State and Control Messages     --><refentry id="usbseth-control"><refmeta><refentrytitle>USB-ethernet State Handling</refentrytitle></refmeta><refnamediv><refname>USB-ethernet State Handling</refname><refpurpose>Maintaining the USB-ethernet connection with the host</refpurpose></refnamediv><refsynopsisdiv><funcsynopsis><funcsynopsisinfo>#include &lt;cyg/io/usb/usbs_eth.h&gt;</funcsynopsisinfo>	<funcprototype><funcdef>usbs_control_return <function>usbs_eth_class_control_handler</function></funcdef><paramdef>usbs_control_endpoint* <parameter>ep0</parameter></paramdef><paramdef>void* <parameter>callback_data</parameter></paramdef></funcprototype><funcprototype><funcdef>void <function>usbs_eth_state_change_handler</function></funcdef><paramdef>usbs_control_endpoint* <parameter>ep0</parameter></paramdef><paramdef>void* <parameter>callback_data</parameter></paramdef><paramdef>usbs_state_change <parameter>change</parameter></paramdef><paramdef>int <parameter>old_state</parameter></paramdef></funcprototype><funcprototype><funcdef>void <function>usbs_eth_disable</function></funcdef><paramdef>usbs_eth* <parameter>usbseth></parameter></paramdef></funcprototype><funcprototype><funcdef>void <function>usbs_eth_enable</function></funcdef><paramdef>usbs_eth* <parameter>usbseth></parameter></paramdef></funcprototype></funcsynopsis></refsynopsisdiv><refsect1><title>Description</title><para>When the USB-ethernet package is initialized by a call to <linklinkend="usbseth-init"><function>usbs_eth_init</function></link> itinstalls <function>usbs_eth_state_change_handler</function> to handleUSB state changes. This allows the package to detect when theconnection between the host and the peripheral is established orbroken, resulting in internal calls to<function>usbs_eth_enable</function> and<function>usbs_eth_disable</function> respectively. This isappropriate if no other code needs to access the USB device. However,if there is other code, either other USB-related packages or theapplication itself, that needs to perform I/O over the USB bus, thentypically the USB-ethernet package should not have exclusive access tostate change events. Instead, the assumption is that higher-levelcode, typically provided by the application, will install analternative state change handler in the control endpoint datastructure after the call to <function>usbs_eth_init</function>. Thisalternative handler will either chain into<function>usbs_eth_state_change_handler</function> when appropriate,or else it will invoke <function>usbs_eth_enable</function> and<function>usbs_eth_disable</function> directly. For further details ofstate change handlers and control endpoints generally, see thedocumentation for the common USB-slave package.</para><para>Similarly, <function>usbs_eth_init</function> will install<function>usbs_eth_class_control_handler</function> in the controlendpoint data structure as the appropriate handler for class-specificUSB control messages. This code will handle the ethernet-specific<link linkend="usbseth-protocol">control messages </link>, for examplerequests by the host to enable or disable promiscuous mode or toobtain the MAC address. If the USB device is not shared with any othercode then this is both necessary and sufficient. However, if other codeis involved and if that code also needs to process certain controlmessages, higher-level code should install its own handler and chainto the USB-ethernet one when appropriate. It should be noted that therequest code is encoded in just a single byte, so there is a realpossibility that exactly the same number will be used by differentprotocols for different requests. Any such problems will have to beidentified and resolved by application developers, and may involvemodifying the source code for the USB-ethernet package.</para><para>As an alternative to chaining the state change handler, higher-levelcode can instead call <function>usbs_eth_disable</function> and<function>usbs_eth_enable</function> directly. These functions mayalso be called if the USB-ethernet package should become inactive forreasons not related directly to events on the USB bus. The main effectof <function>usbs_eth_enable</function> is to restart receiveoperations and to allow transmits. The main effect of<function>usbs_eth_disable</function> is to block further transmits:any current receive operations need to be aborted at the USB level,for example by halting the appropriate endpoint.</para></refsect1></refentry><!-- }}} -->

⌨️ 快捷键说明

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