<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>Example Host-side Device Driver</TITLE
|
>Example Host-side Device Driver</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos Reference Manual"
|
TITLE="eCos Reference Manual"
|
HREF="ecos-ref.html"><LINK
|
HREF="ecos-ref.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="eCos Support for Developing USB-ethernet Peripherals"
|
TITLE="eCos Support for Developing USB-ethernet Peripherals"
|
HREF="io-usb-slave-eth.html"><LINK
|
HREF="io-usb-slave-eth.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="Network Device for the eCos TCP/IP Stack"
|
TITLE="Network Device for the eCos TCP/IP Stack"
|
HREF="usbseth-netdev.html"><LINK
|
HREF="usbseth-netdev.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="Communication Protocol"
|
TITLE="Communication Protocol"
|
HREF="usbseth-protocol.html"></HEAD
|
HREF="usbseth-protocol.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="REFENTRY"
|
CLASS="REFENTRY"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos Reference Manual</TH
|
>eCos Reference Manual</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="usbseth-netdev.html"
|
HREF="usbseth-netdev.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="usbseth-protocol.html"
|
HREF="usbseth-protocol.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><H1
|
><H1
|
><A
|
><A
|
NAME="USBSETH-HOST">Example Host-side Device Driver</H1
|
NAME="USBSETH-HOST">Example Host-side Device Driver</H1
|
><DIV
|
><DIV
|
CLASS="REFNAMEDIV"
|
CLASS="REFNAMEDIV"
|
><A
|
><A
|
NAME="AEN17593"
|
NAME="AEN17593"
|
></A
|
></A
|
><H2
|
><H2
|
>Name</H2
|
>Name</H2
|
>Example Host-side Device Driver -- Provide host-side support for the eCos USB-ethernet package</DIV
|
>Example Host-side Device Driver -- Provide host-side support for the eCos USB-ethernet package</DIV
|
><DIV
|
><DIV
|
CLASS="REFSECT1"
|
CLASS="REFSECT1"
|
><A
|
><A
|
NAME="AEN17596"
|
NAME="AEN17596"
|
></A
|
></A
|
><H2
|
><H2
|
>Description</H2
|
>Description</H2
|
><P
|
><P
|
>The USB-ethernet package is supplied with a single host-side device
|
>The USB-ethernet package is supplied with a single host-side device
|
driver. This driver has been developed against the Linux kernel
|
driver. This driver has been developed against the Linux kernel
|
2.2.16-22, as shipped with Red Hat 7. The driver is provided as is and
|
2.2.16-22, as shipped with Red Hat 7. The driver is provided as is and
|
should not be considered production quality: for example it only
|
should not be considered production quality: for example it only
|
checks for a bogus vendor id <TT
|
checks for a bogus vendor id <TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>0x4242</TT
|
>0x4242</TT
|
> rather than an
|
> rather than an
|
official vendor id supplied by the <A
|
official vendor id supplied by the <A
|
HREF="http://www.usb.org/"
|
HREF="http://www.usb.org/"
|
TARGET="_top"
|
TARGET="_top"
|
>USB Implementers Forum</A
|
>USB Implementers Forum</A
|
>. Also, if the
|
>. Also, if the
|
peripheral involves multiple configurations or multiple interfaces, it
|
peripheral involves multiple configurations or multiple interfaces, it
|
will fail to detect this. However, the driver can be used for simple
|
will fail to detect this. However, the driver can be used for simple
|
testing and as the basis of a full device driver. Details of the
|
testing and as the basis of a full device driver. Details of the
|
protocol used between host and peripheral can be found in the <A
|
protocol used between host and peripheral can be found in the <A
|
HREF="usbseth-protocol.html"
|
HREF="usbseth-protocol.html"
|
>Communication Protocol</A
|
>Communication Protocol</A
|
> section.</P
|
> section.</P
|
><P
|
><P
|
>The host-side device driver can be found in the <TT
|
>The host-side device driver can be found in the <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>host</TT
|
>host</TT
|
> subdirectory of the USB-ethernet
|
> subdirectory of the USB-ethernet
|
package, specifically the file <TT
|
package, specifically the file <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>ecos_usbeth.c</TT
|
>ecos_usbeth.c</TT
|
>, and
|
>, and
|
comes with a <TT
|
comes with a <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>Makefile</TT
|
>Makefile</TT
|
>. Both files may need
|
>. Both files may need
|
to be modified for specific applications. For example, the vendor id
|
to be modified for specific applications. For example, the vendor id
|
table <TT
|
table <TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>ecos_usbeth_implementations</TT
|
>ecos_usbeth_implementations</TT
|
> may need to be
|
> may need to be
|
updated for the specific USB peripheral being built. The
|
updated for the specific USB peripheral being built. The
|
<TT
|
<TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>Makefile</TT
|
>Makefile</TT
|
> assumes that the Linux kernel sources
|
> assumes that the Linux kernel sources
|
reside in <TT
|
reside in <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>/usr/src/linux</TT
|
>/usr/src/linux</TT
|
>, and
|
>, and
|
that the kernel has already been configured and built. Assuming this
|
that the kernel has already been configured and built. Assuming this
|
is the case, the device driver can be built simply by invoking
|
is the case, the device driver can be built simply by invoking
|
<B
|
<B
|
CLASS="COMMAND"
|
CLASS="COMMAND"
|
>make</B
|
>make</B
|
> with no additional arguments. This will result
|
> with no additional arguments. This will result
|
in a dynamically loadable kernel module,
|
in a dynamically loadable kernel module,
|
<TT
|
<TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>ecos_usbeth.o</TT
|
>ecos_usbeth.o</TT
|
>, in the current directory.</P
|
>, in the current directory.</P
|
><DIV
|
><DIV
|
CLASS="NOTE"
|
CLASS="NOTE"
|
><BLOCKQUOTE
|
><BLOCKQUOTE
|
CLASS="NOTE"
|
CLASS="NOTE"
|
><P
|
><P
|
><B
|
><B
|
>Note: </B
|
>Note: </B
|
>As normal for Linux kernel builds, the generated files such as
|
>As normal for Linux kernel builds, the generated files such as
|
<TT
|
<TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>ecos_usbeth.o</TT
|
>ecos_usbeth.o</TT
|
> live in the same directory as the
|
> live in the same directory as the
|
source tree. This is very different from eCos where the source tree
|
source tree. This is very different from eCos where the source tree
|
(or component repository) is kept separate from any builds. There may
|
(or component repository) is kept separate from any builds. There may
|
be problems if the component repository is kept read-only or if it is
|
be problems if the component repository is kept read-only or if it is
|
put under source code control. Any such problems can be avoided by
|
put under source code control. Any such problems can be avoided by
|
making a copy of the <TT
|
making a copy of the <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>host</TT
|
>host</TT
|
>
|
>
|
subdirectory and building that copy.</P
|
subdirectory and building that copy.</P
|
></BLOCKQUOTE
|
></BLOCKQUOTE
|
></DIV
|
></DIV
|
><P
|
><P
|
>Loading the kernel module into the current system requires root
|
>Loading the kernel module into the current system requires root
|
privileges. If the generic USB support is also a loadable module and
|
privileges. If the generic USB support is also a loadable module and
|
has not been loaded already, this must happen first:</P
|
has not been loaded already, this must happen first:</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
># insmod usb-uhci
|
># insmod usb-uhci
|
Using /lib/modules/2.2.16-22/usb/usb-uhci.o</PRE
|
Using /lib/modules/2.2.16-22/usb/usb-uhci.o</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>Depending on the host hardware, the <TT
|
>Depending on the host hardware, the <TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>uhci</TT
|
>uhci</TT
|
> or
|
> or
|
<TT
|
<TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>usb-ohci</TT
|
>usb-ohci</TT
|
> modules may be more appropriate. Loading
|
> modules may be more appropriate. Loading
|
the generic USB module will typically result in a number of messages
|
the generic USB module will typically result in a number of messages
|
to the logfile <TT
|
to the logfile <TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>/var/log/messages</TT
|
>/var/log/messages</TT
|
>, giving details
|
>, giving details
|
of the specific host-side hardware that has been detected plus any
|
of the specific host-side hardware that has been detected plus any
|
hubs. The next step is to load the USB-ethernet module:</P
|
hubs. The next step is to load the USB-ethernet module:</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
># insmod ecos_usbeth.o</PRE
|
># insmod ecos_usbeth.o</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>This should result in a number of additional diagnostics in the
|
>This should result in a number of additional diagnostics in the
|
logfile:</P
|
logfile:</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
>Apr 1 18:01:08 grumpy kernel: eCos USB-ethernet device driver
|
>Apr 1 18:01:08 grumpy kernel: eCos USB-ethernet device driver
|
Apr 1 18:01:08 grumpy kernel: usb.c: registered new driver ecos_usbeth</PRE
|
Apr 1 18:01:08 grumpy kernel: usb.c: registered new driver ecos_usbeth</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>If a suitable USB peripheral is now connected the host will detect
|
>If a suitable USB peripheral is now connected the host will detect
|
this, assign an address in the local USB network, obtain enumeration
|
this, assign an address in the local USB network, obtain enumeration
|
data, and find a suitable device driver. Assuming the peripheral and
|
data, and find a suitable device driver. Assuming the peripheral and
|
device driver agree on the supported vendor ids, the
|
device driver agree on the supported vendor ids, the
|
<TT
|
<TT
|
CLASS="FILENAME"
|
CLASS="FILENAME"
|
>ecos_usbeth.o</TT
|
>ecos_usbeth.o</TT
|
> module will be selected and this
|
> module will be selected and this
|
will be reported in the system log:</P
|
will be reported in the system log:</P
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
>Apr 1 18:04:12 grumpy kernel: usb.c: USB new device connect, assigned device number 3
|
>Apr 1 18:04:12 grumpy kernel: usb.c: USB new device connect, assigned device number 3
|
Apr 1 18:04:12 grumpy kernel: eCos-based USB ethernet peripheral active at eth1</PRE
|
Apr 1 18:04:12 grumpy kernel: eCos-based USB ethernet peripheral active at eth1</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
>What can happen next depends very much on the software that is running
|
>What can happen next depends very much on the software that is running
|
on top of the USB-ethernet package inside the peripheral. For example,
|
on 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 a
|
if there is a TCP/IP stack then it should be possible to bring up a
|
network connection between host and peripheral using
|
network connection between host and peripheral using
|
<B
|
<B
|
CLASS="COMMAND"
|
CLASS="COMMAND"
|
>ifconfig</B
|
>ifconfig</B
|
>.</P
|
>.</P
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="usbseth-netdev.html"
|
HREF="usbseth-netdev.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-ref.html"
|
HREF="ecos-ref.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="usbseth-protocol.html"
|
HREF="usbseth-protocol.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>Network Device for the eCos TCP/IP Stack</TD
|
>Network Device for the eCos TCP/IP Stack</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="io-usb-slave-eth.html"
|
HREF="io-usb-slave-eth.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>Communication Protocol</TD
|
>Communication Protocol</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|