<!-- Copyright (C) 2001 Red Hat, Inc. -->
|
<!-- Copyright (C) 2001 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 substantively modified versions of this -->
|
<!-- Distribution of substantively modified versions of this -->
|
<!-- document is prohibited without the explicit permission of the -->
|
<!-- document is prohibited without the explicit permission of the -->
|
<!-- copyright holder. -->
|
<!-- copyright holder. -->
|
<!-- 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
|
>Initializing the USB-ethernet Package</TITLE
|
>Initializing the USB-ethernet Package</TITLE
|
><META
|
><META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.64
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
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="Introduction"
|
TITLE="Introduction"
|
HREF="usbseth-intro.html"><LINK
|
HREF="usbseth-intro.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="USB-ethernet Data Transfers"
|
TITLE="USB-ethernet Data Transfers"
|
HREF="usbseth-data.html"></HEAD
|
HREF="usbseth-data.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
|
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 Support for Developing USB-ethernet Peripherals</TH
|
>eCos Support for Developing USB-ethernet Peripherals</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="usbseth-intro.html"
|
HREF="usbseth-intro.html"
|
>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-data.html"
|
HREF="usbseth-data.html"
|
>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-INIT"
|
NAME="USBSETH-INIT"
|
>Initializing the USB-ethernet Package</A
|
>Initializing the USB-ethernet Package</A
|
></H1
|
></H1
|
><DIV
|
><DIV
|
CLASS="REFNAMEDIV"
|
CLASS="REFNAMEDIV"
|
><A
|
><A
|
NAME="AEN47"
|
NAME="AEN47"
|
></A
|
></A
|
><H2
|
><H2
|
>Name</H2
|
>Name</H2
|
><TT
|
><TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_eth_init</TT
|
>usbs_eth_init</TT
|
> -- Initializing the USB-ethernet Package</DIV
|
> -- Initializing the USB-ethernet Package</DIV
|
><DIV
|
><DIV
|
CLASS="REFSYNOPSISDIV"
|
CLASS="REFSYNOPSISDIV"
|
><A
|
><A
|
NAME="AEN51"
|
NAME="AEN51"
|
></A
|
></A
|
><H2
|
><H2
|
>Synopsis</H2
|
>Synopsis</H2
|
><DIV
|
><DIV
|
CLASS="FUNCSYNOPSIS"
|
CLASS="FUNCSYNOPSIS"
|
><A
|
><A
|
NAME="AEN52"
|
NAME="AEN52"
|
></A
|
></A
|
><P
|
><P
|
></P
|
></P
|
><TABLE
|
><TABLE
|
BORDER="0"
|
BORDER="0"
|
BGCOLOR="#E0E0E0"
|
BGCOLOR="#E0E0E0"
|
WIDTH="100%"
|
WIDTH="100%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="FUNCSYNOPSISINFO"
|
CLASS="FUNCSYNOPSISINFO"
|
>#include <cyg/io/usb/usbs_eth.h></PRE
|
>#include <cyg/io/usb/usbs_eth.h></PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><P
|
><P
|
><CODE
|
><CODE
|
><CODE
|
><CODE
|
CLASS="FUNCDEF"
|
CLASS="FUNCDEF"
|
>void usbs_eth_init</CODE
|
>void usbs_eth_init</CODE
|
>(usbs_eth* usbeth, usbs_control_endpoint* ep0, usbs_rx_endpoint* ep1, usbs_tx_endpoint* ep2, unsigned char* mac_address);</CODE
|
>(usbs_eth* usbeth, usbs_control_endpoint* ep0, usbs_rx_endpoint* ep1, usbs_tx_endpoint* ep2, unsigned char* mac_address);</CODE
|
></P
|
></P
|
><P
|
><P
|
></P
|
></P
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="REFSECT1"
|
CLASS="REFSECT1"
|
><A
|
><A
|
NAME="AEN67"
|
NAME="AEN67"
|
></A
|
></A
|
><H2
|
><H2
|
>Description</H2
|
>Description</H2
|
><P
|
><P
|
>The USB-ethernet package is not tied to any specific hardware. It
|
>The USB-ethernet package is not tied to any specific hardware. It
|
requires certain functionality: there must be USB-slave hardware
|
requires certain functionality: there must be USB-slave hardware
|
supported by a device driver; there must also be two endpoints for
|
supported by a device driver; there must also be two endpoints for
|
bulk transfers between host and peripheral, one for each direction;
|
bulk transfers between host and peripheral, one for each direction;
|
there must also be a control endpoint, although of course that is
|
there must also be a control endpoint, although of course that is
|
implicit with any USB hardware.</P
|
implicit with any USB hardware.</P
|
><P
|
><P
|
>However, USB-slave hardware may well provide more endpoints than the
|
>However, USB-slave hardware may well provide more endpoints than the
|
minimum required for ethernet support. Some of those endpoints might
|
minimum required for ethernet support. Some of those endpoints might
|
be used by other packages, while other endpoints might be used
|
be used by other packages, while other endpoints might be used
|
directly by the application, or might not be needed for the peripheral
|
directly by the application, or might not be needed for the peripheral
|
being built. There is also the possibility of a USB peripheral that
|
being built. There is also the possibility of a USB peripheral that
|
supports multiple configurations, with the ethernet support active in
|
supports multiple configurations, with the ethernet support active in
|
only some of those configurations. The USB-ethernet package has no
|
only some of those configurations. The USB-ethernet package has no
|
knowledge about any of this, so it relies on higher-level code to tell
|
knowledge about any of this, so it relies on higher-level code to tell
|
it which endpoints should be used and other information. This is the
|
it which endpoints should be used and other information. This is the
|
purpose of the <TT
|
purpose of the <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_eth_init</TT
|
>usbs_eth_init</TT
|
> function.</P
|
> function.</P
|
><P
|
><P
|
>The first argument identifies the specific
|
>The first argument identifies the specific
|
<SPAN
|
<SPAN
|
CLASS="STRUCTNAME"
|
CLASS="STRUCTNAME"
|
>usbs_eth</SPAN
|
>usbs_eth</SPAN
|
> data structure that is affected. It
|
> data structure that is affected. It
|
is expected that the vast majority of affected applications will only
|
is expected that the vast majority of affected applications will only
|
provide a single USB-ethernet device to a single host, and the package
|
provide a single USB-ethernet device to a single host, and the package
|
automatically provides a suitable data structure
|
automatically provides a suitable data structure
|
<TT
|
<TT
|
CLASS="LITERAL"
|
CLASS="LITERAL"
|
>usbs_eth0</TT
|
>usbs_eth0</TT
|
> to support this. If multiple
|
> to support this. If multiple
|
<SPAN
|
<SPAN
|
CLASS="STRUCTNAME"
|
CLASS="STRUCTNAME"
|
>usbs_eth</SPAN
|
>usbs_eth</SPAN
|
> structures are needed for some
|
> structures are needed for some
|
reason then these need to be instantiated by other code, and each one
|
reason then these need to be instantiated by other code, and each one
|
needs to be initialised by a call to
|
needs to be initialised by a call to
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_eth_init()</TT
|
>usbs_eth_init()</TT
|
>. </P
|
>. </P
|
><P
|
><P
|
>The next three arguments identify the endpoints that should be used
|
>The next three arguments identify the endpoints that should be used
|
for USB communications: a control endpoint, a receive endpoint for
|
for USB communications: a control endpoint, a receive endpoint for
|
ethernet packets coming from the host to the peripheral, and a
|
ethernet packets coming from the host to the peripheral, and a
|
transmit endpoint for ethernet packets going in the other direction.
|
transmit endpoint for ethernet packets going in the other direction.
|
Obviously all three endpoints should be provided by the same USB
|
Obviously all three endpoints should be provided by the same USB
|
hardware. The USB-ethernet package assumes that it has sole access to
|
hardware. The USB-ethernet package assumes that it has sole access to
|
the receive and transmit endpoints, subject to the use of
|
the receive and transmit endpoints, subject to the use of
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_eth_disable</TT
|
>usbs_eth_disable</TT
|
> and
|
> and
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_eth_enable</TT
|
>usbs_eth_enable</TT
|
> control functions. The package
|
> control functions. The package
|
also assumes that no other code is interested in USB state changes or
|
also assumes that no other code is interested in USB state changes or
|
class control messages: it installs handlers
|
class control messages: it installs handlers
|
<A
|
<A
|
HREF="usbseth-control.html"
|
HREF="usbseth-control.html"
|
><TT
|
><TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_eth_state_change_handler</TT
|
>usbs_eth_state_change_handler</TT
|
></A
|
></A
|
>
|
>
|
and
|
and
|
<A
|
<A
|
HREF="usbseth-control.html"
|
HREF="usbseth-control.html"
|
><TT
|
><TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_eth_class_control_handler</TT
|
>usbs_eth_class_control_handler</TT
|
></A
|
></A
|
>
|
>
|
in the control endpoint. If any other code does need to handle USB
|
in the control endpoint. If any other code does need to handle USB
|
state changes or class control messages then replacement handlers
|
state changes or class control messages then replacement handlers
|
should be installed after the call to
|
should be installed after the call to
|
<TT
|
<TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_eth_init</TT
|
>usbs_eth_init</TT
|
>, and those replacements should
|
>, and those replacements should
|
invoke the USB-ethernet ones when appropriate.</P
|
invoke the USB-ethernet ones when appropriate.</P
|
><P
|
><P
|
>The final argument to <TT
|
>The final argument to <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_eth_init</TT
|
>usbs_eth_init</TT
|
> specifies
|
> specifies
|
the MAC address (or Ethernet Station Address) that should be provided
|
the MAC address (or Ethernet Station Address) that should be provided
|
to the host-side device driver. Since the USB-ethernet package does not
|
to the host-side device driver. Since the USB-ethernet package does not
|
interact directly with a real ethernet device it cannot obtain the MAC
|
interact directly with a real ethernet device it cannot obtain the MAC
|
address from any hardware. Instead, it must be supplied by higher-level
|
address from any hardware. Instead, it must be supplied by higher-level
|
code. The details depend on the <A
|
code. The details depend on the <A
|
HREF="usbseth-intro.html#AEN22"
|
HREF="usbseth-intro.html#AEN22"
|
>scenario</A
|
>scenario</A
|
> in which the
|
> in which the
|
USB-ethernet package is being used.</P
|
USB-ethernet package is being used.</P
|
><P
|
><P
|
>The call to <TT
|
>The call to <TT
|
CLASS="FUNCTION"
|
CLASS="FUNCTION"
|
>usbs_eth_init</TT
|
>usbs_eth_init</TT
|
> should normally happen
|
> should normally happen
|
after the enumeration data has been provided but before the underlying
|
after the enumeration data has been provided but before the underlying
|
USB device driver has been started. If the USB device were to be
|
USB device driver has been started. If the USB device were to be
|
started first then a connection between host and peripheral could be
|
started first then a connection between host and peripheral could be
|
established immediately, and the host-side device driver would attempt
|
established immediately, and the host-side device driver would attempt
|
to contact the USB-ethernet package for information such as the MAC
|
to contact the USB-ethernet package for information such as the MAC
|
address. </P
|
address. </P
|
><TABLE
|
><TABLE
|
BORDER="0"
|
BORDER="0"
|
BGCOLOR="#E0E0E0"
|
BGCOLOR="#E0E0E0"
|
WIDTH="100%"
|
WIDTH="100%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="PROGRAMLISTING"
|
CLASS="PROGRAMLISTING"
|
>int
|
>int
|
main(int argc, char** argv)
|
main(int argc, char** argv)
|
{
|
{
|
unsigned char host_MAC[6] = { 0x40, 0x5d, 0x90, 0xa9, 0xbc, 0x02 };
|
unsigned char host_MAC[6] = { 0x40, 0x5d, 0x90, 0xa9, 0xbc, 0x02 };
|
|
|
usbs_sa11x0_ep0.enumeration_data = &usb_enum_data;
|
usbs_sa11x0_ep0.enumeration_data = &usb_enum_data;
|
…
|
…
|
usbs_eth_init(&usbs_eth0, &usbs_sa11x0_ep0, &usbs_sa11x0_ep1, &usbs_sa11x0_ep2, host_MAC);
|
usbs_eth_init(&usbs_eth0, &usbs_sa11x0_ep0, &usbs_sa11x0_ep1, &usbs_sa11x0_ep2, host_MAC);
|
…
|
…
|
usbs_start(&usbs_sa11x0_ep0);
|
usbs_start(&usbs_sa11x0_ep0);
|
…
|
…
|
}</PRE
|
}</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><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-intro.html"
|
HREF="usbseth-intro.html"
|
>Prev</A
|
>Prev</A
|
></TD
|
></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"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="usbseth-data.html"
|
HREF="usbseth-data.html"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>Introduction</TD
|
>Introduction</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
> </TD
|
> </TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>USB-ethernet Data Transfers</TD
|
>USB-ethernet Data Transfers</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|