📄 usbseth.sgml
字号:
<!-- DOCTYPE reference PUBLIC "-//OASIS//DTD DocBook V3.1//EN" --><!-- {{{ Banner --><!-- =============================================================== --><!-- --><!-- usbseth.sgml --><!-- --><!-- USB slave-side ethernet support package. --><!-- --><!-- =============================================================== --><!-- ####COPYRIGHTBEGIN#### --><!-- --><!-- =============================================================== --><!-- Copyright (C) 2001, 2002 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 obtained from the copyright holder --><!-- =============================================================== --><!-- --> <!-- ####COPYRIGHTEND#### --><!-- =============================================================== --><!-- #####DESCRIPTIONBEGIN#### --><!-- --><!-- Author(s): bartv --><!-- Contact(s): bartv --><!-- Date: 2001/01/13 --><!-- Version: 0.01 --><!-- --><!-- ####DESCRIPTIONEND#### --><!-- =============================================================== --><!-- }}} --><part id="io-usb-slave-eth"><!-- reference id="io-usb-slave-eth" --> <title>eCos Support for Developing USB-ethernet Peripherals</title><!-- {{{ Intro --><refentry id="usbseth-intro"><refmeta><refentrytitle>Introduction</refentrytitle></refmeta><refnamediv><refname>Introduction</refname><refpurpose>eCos support for developing USB ethernet peripherals</refpurpose></refnamediv><refsect1><title>Introduction</title><para>The eCos USB-ethernet package provides additional support for USBperipherals that involve some sort of ethernet-style network. This canbe a traditional ethernet, or it can involve some other networkingtechnology that uses ethernet frames as a unit of transfer. Itprovides functions to transfer ethernet frames over the USB bus,handles certain control messages from the host, and optionally it canprovide a network device driver for use by the eCos TCP/IP stack.The package comes with an example host-side device driver.</para><para>The USB-ethernet package is not tied to any specific hardware. Itrequires the presence of USB hardware and a suitable device driver,but not all USB peripherals involve ethernet communications. Hence theconfiguration system cannot load the package automatically forspecific targets, in the way that a USB device driver or an ethernetdriver can be loaded automatically. Instead, the package has to beadded explicitly. When using the command line tools this will involvean operation like the following:</para><screen width=72 format=linespecific>$ ecosconfig add usbs_eth</screen><para>Typically, this will automatically cause the USB device driver tobecome active. Loading the USB-ethernet package automatically providesfunctionality for <link linkend="usbseth-init">initialization</link>,<link linkend="usbseth-data">data transfer</link>, and the handling of<link linkend="usbseth-control">control messages</link> and statechanges. If the current configuration includes the eCos TCP/IP stackthen the <link linkend="usbseth-netdev">network device driver</link>support will be enabled as well by default, allowing the stack toexchange ethernet frames over the USB bus.</para><para>There is a USB standard for a class of communication devices includingethernet. The package does not implement this standard, due tolimitations in the hardware for which the package was first developed.Instead, the package uses its own <linklinkend="usbseth-protocol">protocol</link> between USB<link linkend="usbseth-host">host device driver</link> and theperipheral. </para></refsect1><refsect1><title id="usbseth-intro-scenarios">Usage Scenarios</title><para>The USB-ethernet package can be used several different scenarios. Ina simple scenario, the peripheral serves only to connect the USB hostto a suitable network:</para><informalfigure PgWide=1><mediaobject><imageobject><imagedata fileref="simple.png" Align="Center"></imageobject></mediaobject></informalfigure><para>After initialization, and once the USB connection between host andperipheral has been established, higher-level code needs to detectpackets that are intended for the host, and to forward these. This canbe achieved by the low-level <function>usbs_eth_start_tx</function>function. Similarly, higher-level code needs to detect packets comingfrom the host, using <function>usbs_eth_start_rx</function>, and toforward these using the real network. As far as the host is concernedit is connected directly to the network. In this scenario there is noconfusion about addresses: there is a single MAC address for thehost/peripheral combination, corresponding to the connection to thereal network, and it is this address which should be supplied during<link linkend="usbseth-init">initialization</link>.</para><para>In a more complicated scenario, there is a TCP/IP stack running insidethe peripheral.</para><informalfigure PgWide=1><mediaobject><imageobject><imagedata fileref="tcpip.png" Align="Center"></imageobject></mediaobject></informalfigure><para>This involves the USB-ethernet package providing a service both to thehost and to the eCos TCP/IP stack. It achieves the latter by acting asan eCos network device. Typically, the TCP/IP stack will be configuredto act as a network bridge. The USB peripheral needs to examine thepackets arriving over the real network. Some of these packets will beintended for the host, while others will be intended for theperipheral itself. To distinguish between these two scenarios, twodistinct MAC addresses are needed: one for the host, and one for theperipheral. Similarly, packets sent by the host may have to beforwarded via the real network, or they may be intended for the TCP/IPstack inside the peripheral. Packets generated inside the peripheral'sTCP/IP stack may need to be sent via the real network or over the USBbus. The network bridge software will have to take care of all thesepossibilities. Unusually for a network bridge, one of the networksegments being bridged will only ever have one machine attached.</para><para>There are other possible usage scenarios. For example, the peripheralmight not be attached to a real network at all. Instead it could bethe USB host that acts as a network bridge, allowing a TCP/IP stackinside the peripheral to communicate with the outside world. Thevarious details will depend on the exact type of peripheral beingdeveloped. </para></refsect1></refentry><!-- }}} --><!-- {{{ Initialization --><refentry id="usbseth-init"><refmeta><refentrytitle>Initializing the USB-ethernet Package</refentrytitle></refmeta><refnamediv><refname><function>usbs_eth_init</function></refname><refpurpose>Initializing the USB-ethernet Package</refpurpose></refnamediv><refsynopsisdiv><funcsynopsis><funcsynopsisinfo>#include <cyg/io/usb/usbs_eth.h></funcsynopsisinfo> <funcprototype><funcdef>void <function>usbs_eth_init</function></funcdef><paramdef>usbs_eth* <parameter>usbeth</parameter></paramdef><paramdef>usbs_control_endpoint* <parameter>ep0</parameter></paramdef><paramdef>usbs_rx_endpoint* <parameter>ep1</parameter></paramdef><paramdef>usbs_tx_endpoint* <parameter>ep2</parameter></paramdef><paramdef>unsigned char* <parameter>mac_address</parameter></paramdef></funcprototype></funcsynopsis></refsynopsisdiv><refsect1><title>Description</title><para>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.</para><para>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 <function>usbs_eth_init</function> function.</para><para>The first argument identifies the specific<structname>usbs_eth</structname> 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<literal>usbs_eth0</literal> to support this. If multiple<structname>usbs_eth</structname> structures are needed for somereason then these need to be instantiated by other code, and each oneneeds to be initialised by a call to<function>usbs_eth_init()</function>. </para><para>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<function>usbs_eth_disable</function> and<function>usbs_eth_enable</function> control functions. The packagealso assumes that no other code is interested in USB state changes orclass control messages: it installs handlers<link linkend="usbseth-control"><function>usbs_eth_state_change_handler</function></link>and<link linkend="usbseth-control"><function>usbs_eth_class_control_handler</function></link>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<function>usbs_eth_init</function>, and those replacements shouldinvoke the USB-ethernet ones when appropriate.</para><para>The final argument to <function>usbs_eth_init</function> 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 <linklinkend="usbseth-intro-scenarios">scenario</link> in which theUSB-ethernet package is being used.</para><para>The call to <function>usbs_eth_init</function> 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. </para><programlisting width=72>intmain(int argc, char** argv){ unsigned char host_MAC[6] = { 0x40, 0x5d, 0x90, 0xa9, 0xbc, 0x02 };
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -