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

📄 usbseth.sgml

📁 eCos操作系统源码
💻 SGML
📖 第 1 页 / 共 3 页
字号:
<!-- {{{ netdev device                  --><refentry id="usbseth-netdev"><refmeta><refentrytitle>Network Device for the eCos TCP/IP Stack</refentrytitle></refmeta><refnamediv><refname>Network Device</refname><refpurpose>USB-ethernet support for the eCos TCP/IP Stack</refpurpose></refnamediv><refsect1><title>Description</title><para>If the USB peripheral involves running the eCos TCP/IP stack and thatstack needs to use USB-ethernet as a transport layer (or as one of thetransports), then the USB-ethernet package can provide a suitablenetwork device driver. It is still necessary for higher-level code toperform appropriate initialization by calling <linklinkend="usbseth-init"><function>usbs_eth_init</function></link>, butafter that it will be the TCP/IP stack rather than application codethat transmits or receives ethernet frames.</para><para>Not all peripherals involving the USB-ethernet package will require aTCP/IP stack. Hence the provision of the network device is controlledby a configuration option <literal>CYGPKG_USBS_ETHDRV</literal>. Bydefault this will be enabled if the TCP/IP package<literal>CYGPKG_NET</literal> is loaded, and disabled otherwise. </para><para>There are a number of other configuration options related to thenetwork device. <literal>CYGFUN_USBS_ETHDRV_STATISTICS</literal>determines whether or not the package will maintain statistics, mainlyintended for SNMP: by default this will be enabled if the SNMP supportpackage <literal>CYGPKG_SNMPAGENT</literal> is loaded, and disabledotherwise. The name of the ethernet device is controlled by<literal>CYGDATA_USBS_ETHDRV_NAME</literal>, and has a default valueof either <literal>eth0</literal> or <literal>eth1</literal>depending on whether or not there is another network device driverpresent in the configuration.</para><para>Usually eCos network device drivers default to using DHCP forobtaining necessary information such as IP addresses. This is notappropriate for USB-ethernet devices. On the host-side theUSB-ethernet network device will not exist until the USB peripheralhas been plugged in and communication has been established. Thereforeany DHCP daemon on the host would not be listening on that networkdevice at the point that eCos requests its IP and other information. Arelated issue is that the use of DHCP would imply the presence of aDHCP daemon on every affected host machine, as opposed to a singledaemon (plus backups) for the network as a whole. For these reasonsthe USB-ethernet package precludes the use of DHCP as a way of settingthe IP address, instead requiring alternatives such as manualconfiguration.</para></refsect1></refentry><!-- }}} --><!-- {{{ ecos_usbeth                    --><refentry id="usbseth-host"><refmeta><refentrytitle>Example Host-side Device Driver</refentrytitle></refmeta><refnamediv><refname>Example Host-side Device Driver</refname><refpurpose>Provide host-side support for the eCos USB-ethernet package</refpurpose></refnamediv><refsect1><title>Description</title><para>The USB-ethernet package is supplied with a single host-side devicedriver. This driver has been developed against the Linux kernel2.2.16-22, as shipped with Red Hat 7. The driver is provided as is andshould not be considered production quality: for example it onlychecks for a bogus vendor id <literal>0x4242</literal> rather than anofficial vendor id supplied by the <ulinkurl="http://www.usb.org/">USB Implementers Forum</ulink>. Also, if theperipheral involves multiple configurations or multiple interfaces, itwill fail to detect this. However, the driver can be used for simpletesting and as the basis of a full device driver. Details of theprotocol used between host and peripheral can be found in the <linklinkend="usbseth-protocol">Communication Protocol</link> section.</para><para>The host-side device driver can be found in the <filenameclass="directory">host</filename> subdirectory of the USB-ethernetpackage, specifically the file <filename>ecos_usbeth.c</filename>, andcomes with a <filename>Makefile</filename>. Both files may needto be modified for specific applications. For example, the vendor idtable <literal>ecos_usbeth_implementations</literal> may need to beupdated for the specific USB peripheral being built. The<filename>Makefile</filename> assumes that the Linux kernel sourcesreside in <filename class="directory">/usr/src/linux</filename>, andthat the kernel has already been configured and built. Assuming thisis the case, the device driver can be built simply by invoking<command>make</command> with no additional arguments. This will resultin a dynamically loadable kernel module,<filename>ecos_usbeth.o</filename>, in the current directory.</para><note><para>As normal for Linux kernel builds, the generated files such as<filename>ecos_usbeth.o</filename> live in the same directory as thesource tree. This is very different from eCos where the source tree(or component repository) is kept separate from any builds. There maybe problems if the component repository is kept read-only or if it isput under source code control. Any such problems can be avoided bymaking a copy of the <filename class="directory">host</filename>subdirectory and building that copy.</para></note><para>Loading the kernel module into the current system requires rootprivileges. If the generic USB support is also a loadable module andhas not been loaded already, this must happen first:</para><screen width=72 format=linespecific># insmod usb-uhciUsing /lib/modules/2.2.16-22/usb/usb-uhci.o</screen><para>Depending on the host hardware, the <literal>uhci</literal> or<literal>usb-ohci</literal> modules may be more appropriate. Loadingthe generic USB module will typically result in a number of messagesto the logfile <filename>/var/log/messages</filename>, giving detailsof the specific host-side hardware that has been detected plus anyhubs. The next step is to load the USB-ethernet module:</para><screen width=72 format=linespecific># insmod ecos_usbeth.o</screen><para>This should result in a number of additional diagnostics in thelogfile:</para><screen width=72 format=linespecific>Apr 1 18:01:08 grumpy kernel: eCos USB-ethernet device driverApr 1 18:01:08 grumpy kernel: usb.c: registered new driver ecos_usbeth</screen><para>If a suitable USB peripheral is now connected the host will detectthis, assign an address in the local USB network, obtain enumerationdata, and find a suitable device driver. Assuming the peripheral anddevice driver agree on the supported vendor ids, the<filename>ecos_usbeth.o</filename> module will be selected and thiswill be reported in the system log:</para><screen width=86 format=linespecific>Apr 1 18:04:12 grumpy kernel: usb.c: USB new device connect, assigned device number 3Apr 1 18:04:12 grumpy kernel: eCos-based USB ethernet peripheral active at eth1</screen><para>What can happen next depends very much on the software that is runningon top of the USB-ethernet package inside the peripheral. For example,if there is a TCP/IP stack then it should be possible to bring up anetwork connection between host and peripheral using<command>ifconfig</command>.</para></refsect1></refentry><!-- }}} --><!-- {{{ Protocol                       --><refentry id="usbseth-protocol"><refmeta><refentrytitle>Communication Protocol</refentrytitle></refmeta><refnamediv><refname>Communication Protocol</refname><refpurpose>Protocol used between the host-side device driver and the eCosUSB-ethernet package </refpurpose></refnamediv><refsect1><title>Description</title><para>There is a USB standard for the protocol to be used between the hostand a class of communication devices, including ethernet. However, theeCos USB-ethernet package does not implement this protocol: the targethardware for which the package was first developed had certainlimitations, and could not implement the standard. Instead, the packageimplements a simple new protocol.</para><para>A USB-ethernet peripheral involves bulk transfers on two endpoints:one endpoint will be used for packets from host to peripheral and theother will be used for the opposite direction. Transfers in bothdirections are variable length, with a lower limit of 16 bytes and anupper limit of 1516 bytes. The first two bytes of each transferconstitute a header specific to USB-ethernet. The next 14 bytes formthe normal header for an ethernet frame: destination MAC address,source MAC address, and a protocol field. The remaining data, up to1500 bytes, are the payload. The first two bytes give the size of theethernet frame, least significant byte first, with a value between 14and 1514.</para><para>For example an ARP request from host to peripheral involves anethernet frame of 42 bytes (0x002A), with the usual 14-byte header anda 28-byte payload. The destination is the broadcast address0xFFFFFFFFFFFF. The source depends on the MAC address specified forthe host in the call to <linklinkend="usbseth-init"><function>usbs_eth_init</function></link>, e.g.0x405D90A9BC02. The remaining data is as specified by the appropriate<ulink url="http://www.ietf.org">IETF RFC's</ulink>. The actual bulkUSB transfer involves the following sequence of 44 bytes:</para><screen width=72 format=linespecific>2a 00 ff ff ff ff ff ff 40 5d 90 a9 bc 02 08 0600 01 08 00 06 04 00 01 40 5d 90 a9 bc 02 0a 0000 01 00 00 00 00 00 00 0a 00 00 02</screen><para>In addition there are two control messages. These will be sent by thehost to endpoint 0, the control endpoint, and by default they willbe handled by <link linkend="usbseth-control"><function>usbs_eth_class_control_handler</function></link>. If class-specificcontrol messages are intercepted by other code then it is theresponsibility of that code to invoke the USB-ethernet handler whenappropriate.</para><para>The first control message can be used by the host to obtain a MACaddress:</para><programlisting width=72>#define ECOS_USBETH_CONTROL_GET_MAC_ADDRESS         0x01</programlisting><para>The control message's type field should specify IN as the direction.The request field should be <literal>0x01</literal>. The length fieldsshould specify a size of 6 bytes. The remaining fields of the controlmessage will be ignored by the USB-ethernet package. The responseconsists of the 6-byte MAC address supplied by the initialization call<linklinkend="usbseth-init"><function>usbs_eth_init</function></link>.</para><para>The second control message can be used by the host to enable ordisable promiscuous mode.</para><programlisting width=72>#define ECOS_USBETH_CONTROL_SET_PROMISCUOUS_MODE    0x02</programlisting><para>This control message involves no further data so the length fieldshould be set to 0. The value field should be non-zero to enablepromiscuous mode, zero to disable it. The request field should be<literal>0x02</literal>. The remaining fields in the control messagewill be ignored. It is the responsibility of the host-side devicedriver to keep track of whether or not promiscuous mode is currentlyenabled. It will be disabled when the peripheral changes toConfigured state, typically at the point where the host-side devicedriver has been activated.</para></refsect1></refentry><!-- }}} --></part><!-- /reference -->

⌨️ 快捷键说明

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