📄 usbseth-host.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>Example Host-side Device Driver</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 Support for Developing USB-ethernet Peripherals"HREF="io-usb-slave-eth.html"><LINKREL="PREVIOUS"TITLE="Network Device for the eCos TCP/IP Stack"HREF="usbseth-netdev.html"><LINKREL="NEXT"TITLE="Communication Protocol"HREF="usbseth-protocol.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="usbseth-netdev.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="usbseth-protocol.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="USBSETH-HOST">Example Host-side Device Driver</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN17593"></A><H2>Name</H2>Example Host-side Device Driver -- Provide host-side support for the eCos USB-ethernet package</DIV><DIVCLASS="REFSECT1"><ANAME="AEN17596"></A><H2>Description</H2><P>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 <TTCLASS="LITERAL">0x4242</TT> rather than anofficial vendor id supplied by the <AHREF="http://www.usb.org/"TARGET="_top">USB Implementers Forum</A>. 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 <AHREF="usbseth-protocol.html">Communication Protocol</A> section.</P><P>The host-side device driver can be found in the <TTCLASS="FILENAME">host</TT> subdirectory of the USB-ethernetpackage, specifically the file <TTCLASS="FILENAME">ecos_usbeth.c</TT>, andcomes with a <TTCLASS="FILENAME">Makefile</TT>. Both files may needto be modified for specific applications. For example, the vendor idtable <TTCLASS="LITERAL">ecos_usbeth_implementations</TT> may need to beupdated for the specific USB peripheral being built. The<TTCLASS="FILENAME">Makefile</TT> assumes that the Linux kernel sourcesreside in <TTCLASS="FILENAME">/usr/src/linux</TT>, andthat the kernel has already been configured and built. Assuming thisis the case, the device driver can be built simply by invoking<BCLASS="COMMAND">make</B> with no additional arguments. This will resultin a dynamically loadable kernel module,<TTCLASS="FILENAME">ecos_usbeth.o</TT>, in the current directory.</P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>As normal for Linux kernel builds, the generated files such as<TTCLASS="FILENAME">ecos_usbeth.o</TT> 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 <TTCLASS="FILENAME">host</TT>subdirectory and building that copy.</P></BLOCKQUOTE></DIV><P>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:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN"># insmod usb-uhciUsing /lib/modules/2.2.16-22/usb/usb-uhci.o</PRE></TD></TR></TABLE><P>Depending on the host hardware, the <TTCLASS="LITERAL">uhci</TT> or<TTCLASS="LITERAL">usb-ohci</TT> modules may be more appropriate. Loadingthe generic USB module will typically result in a number of messagesto the logfile <TTCLASS="FILENAME">/var/log/messages</TT>, giving detailsof the specific host-side hardware that has been detected plus anyhubs. The next step is to load the USB-ethernet module:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN"># insmod ecos_usbeth.o</PRE></TD></TR></TABLE><P>This should result in a number of additional diagnostics in thelogfile:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN">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</PRE></TD></TR></TABLE><P>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<TTCLASS="FILENAME">ecos_usbeth.o</TT> module will be selected and thiswill be reported in the system log:</P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="SCREEN">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</PRE></TD></TR></TABLE><P>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<BCLASS="COMMAND">ifconfig</B>.</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="usbseth-netdev.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="usbseth-protocol.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Network Device for the eCos TCP/IP Stack</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-usb-slave-eth.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Communication Protocol</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -