📄 usbseth-init.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>Initializing the USB-ethernet Package</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="Introduction"HREF="usbseth-intro.html"><LINKREL="NEXT"TITLE="USB-ethernet Data Transfers"HREF="usbseth-data.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-intro.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="usbseth-data.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="USBSETH-INIT">Initializing the USB-ethernet Package</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN17398"></A><H2>Name</H2><TTCLASS="FUNCTION">usbs_eth_init</TT> -- Initializing the USB-ethernet Package</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN17402"><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN17403"><P></P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="FUNCSYNOPSISINFO">#include <cyg/io/usb/usbs_eth.h></PRE></TD></TR></TABLE><P><CODE><CODECLASS="FUNCDEF">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></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN17418"></A><H2>Description</H2><P>The USB-ethernet package is not tied to any specific hardware. Itrequires certain functionality: there must be USB-slave hardwaresupported by a device driver; there must also be two endpoints forbulk transfers between host and peripheral, one for each direction;there must also be a control endpoint, although of course that isimplicit with any USB hardware.</P><P>However, USB-slave hardware may well provide more endpoints than theminimum required for ethernet support. Some of those endpoints mightbe used by other packages, while other endpoints might be useddirectly by the application, or might not be needed for the peripheralbeing built. There is also the possibility of a USB peripheral thatsupports multiple configurations, with the ethernet support active inonly some of those configurations. The USB-ethernet package has noknowledge about any of this, so it relies on higher-level code to tellit which endpoints should be used and other information. This is thepurpose of the <TTCLASS="FUNCTION">usbs_eth_init</TT> function.</P><P>The first argument identifies the specific<SPANCLASS="STRUCTNAME">usbs_eth</SPAN> data structure that is affected. Itis expected that the vast majority of affected applications will onlyprovide a single USB-ethernet device to a single host, and the packageautomatically provides a suitable data structure<TTCLASS="LITERAL">usbs_eth0</TT> to support this. If multiple<SPANCLASS="STRUCTNAME">usbs_eth</SPAN> structures are needed for somereason then these need to be instantiated by other code, and each oneneeds to be initialised by a call to<TTCLASS="FUNCTION">usbs_eth_init()</TT>. </P><P>The next three arguments identify the endpoints that should be usedfor USB communications: a control endpoint, a receive endpoint forethernet packets coming from the host to the peripheral, and atransmit endpoint for ethernet packets going in the other direction.Obviously all three endpoints should be provided by the same USBhardware. The USB-ethernet package assumes that it has sole access tothe receive and transmit endpoints, subject to the use of<TTCLASS="FUNCTION">usbs_eth_disable</TT> and<TTCLASS="FUNCTION">usbs_eth_enable</TT> control functions. The packagealso assumes that no other code is interested in USB state changes orclass control messages: it installs handlers<AHREF="usbseth-control.html"><TTCLASS="FUNCTION">usbs_eth_state_change_handler</TT></A>and<AHREF="usbseth-control.html"><TTCLASS="FUNCTION">usbs_eth_class_control_handler</TT></A>in the control endpoint. If any other code does need to handle USBstate changes or class control messages then replacement handlersshould be installed after the call to<TTCLASS="FUNCTION">usbs_eth_init</TT>, and those replacements shouldinvoke the USB-ethernet ones when appropriate.</P><P>The final argument to <TTCLASS="FUNCTION">usbs_eth_init</TT> specifies the MAC address (or Ethernet Station Address) that should be providedto the host-side device driver. Since the USB-ethernet package does notinteract directly with a real ethernet device it cannot obtain the MACaddress from any hardware. Instead, it must be supplied by higher-levelcode. The details depend on the <AHREF="usbseth-intro.html#AEN17377">scenario</A> in which theUSB-ethernet package is being used.</P><P>The call to <TTCLASS="FUNCTION">usbs_eth_init</TT> should normally happenafter the enumeration data has been provided but before the underlyingUSB device driver has been started. If the USB device were to bestarted first then a connection between host and peripheral could beestablished immediately, and the host-side device driver would attemptto contact the USB-ethernet package for information such as the MACaddress. </P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">intmain(int argc, char** argv){ unsigned char host_MAC[6] = { 0x40, 0x5d, 0x90, 0xa9, 0xbc, 0x02 }; 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_start(&usbs_sa11x0_ep0); …}</PRE></TD></TR></TABLE></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-intro.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-data.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Introduction</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-usb-slave-eth.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">USB-ethernet Data Transfers</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -