📄 usbseth-control.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>USB-ethernet State Handling</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="USB-ethernet Data Transfers"HREF="usbseth-data.html"><LINKREL="NEXT"TITLE="Network Device for the eCos TCP/IP Stack"HREF="usbseth-netdev.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-data.html"ACCESSKEY="P">Prev</A></TD><TDWIDTH="80%"ALIGN="center"VALIGN="bottom"></TD><TDWIDTH="10%"ALIGN="right"VALIGN="bottom"><AHREF="usbseth-netdev.html"ACCESSKEY="N">Next</A></TD></TR></TABLE><HRALIGN="LEFT"WIDTH="100%"></DIV><H1><ANAME="USBSETH-CONTROL">USB-ethernet State Handling</H1><DIVCLASS="REFNAMEDIV"><ANAME="AEN17514"></A><H2>Name</H2>USB-ethernet State Handling -- Maintaining the USB-ethernet connection with the host</DIV><DIVCLASS="REFSYNOPSISDIV"><ANAME="AEN17517"><H2>Synopsis</H2><DIVCLASS="FUNCSYNOPSIS"><ANAME="AEN17518"><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">usbs_control_return usbs_eth_class_control_handler</CODE>(usbs_control_endpoint* ep0, void* callback_data);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void usbs_eth_state_change_handler</CODE>(usbs_control_endpoint* ep0, void* callback_data, usbs_state_change change, int old_state);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void usbs_eth_disable</CODE>(usbs_eth* usbseth>);</CODE></P><P><CODE><CODECLASS="FUNCDEF">void usbs_eth_enable</CODE>(usbs_eth* usbseth>);</CODE></P><P></P></DIV></DIV><DIVCLASS="REFSECT1"><ANAME="AEN17548"></A><H2>Description</H2><P>When the USB-ethernet package is initialized by a call to <AHREF="usbseth-init.html"><TTCLASS="FUNCTION">usbs_eth_init</TT></A> itinstalls <TTCLASS="FUNCTION">usbs_eth_state_change_handler</TT> to handleUSB state changes. This allows the package to detect when theconnection between the host and the peripheral is established orbroken, resulting in internal calls to<TTCLASS="FUNCTION">usbs_eth_enable</TT> and<TTCLASS="FUNCTION">usbs_eth_disable</TT> respectively. This isappropriate if no other code needs to access the USB device. However,if there is other code, either other USB-related packages or theapplication itself, that needs to perform I/O over the USB bus, thentypically the USB-ethernet package should not have exclusive access tostate change events. Instead, the assumption is that higher-levelcode, typically provided by the application, will install analternative state change handler in the control endpoint datastructure after the call to <TTCLASS="FUNCTION">usbs_eth_init</TT>. Thisalternative handler will either chain into<TTCLASS="FUNCTION">usbs_eth_state_change_handler</TT> when appropriate,or else it will invoke <TTCLASS="FUNCTION">usbs_eth_enable</TT> and<TTCLASS="FUNCTION">usbs_eth_disable</TT> directly. For further details ofstate change handlers and control endpoints generally, see thedocumentation for the common USB-slave package.</P><P>Similarly, <TTCLASS="FUNCTION">usbs_eth_init</TT> will install<TTCLASS="FUNCTION">usbs_eth_class_control_handler</TT> in the controlendpoint data structure as the appropriate handler for class-specificUSB control messages. This code will handle the ethernet-specific<AHREF="usbseth-protocol.html">control messages </A>, for examplerequests by the host to enable or disable promiscuous mode or toobtain the MAC address. If the USB device is not shared with any othercode then this is both necessary and sufficient. However, if other codeis involved and if that code also needs to process certain controlmessages, higher-level code should install its own handler and chainto the USB-ethernet one when appropriate. It should be noted that therequest code is encoded in just a single byte, so there is a realpossibility that exactly the same number will be used by differentprotocols for different requests. Any such problems will have to beidentified and resolved by application developers, and may involvemodifying the source code for the USB-ethernet package.</P><P>As an alternative to chaining the state change handler, higher-levelcode can instead call <TTCLASS="FUNCTION">usbs_eth_disable</TT> and<TTCLASS="FUNCTION">usbs_eth_enable</TT> directly. These functions mayalso be called if the USB-ethernet package should become inactive forreasons not related directly to events on the USB bus. The main effectof <TTCLASS="FUNCTION">usbs_eth_enable</TT> is to restart receiveoperations and to allow transmits. The main effect of<TTCLASS="FUNCTION">usbs_eth_disable</TT> is to block further transmits:any current receive operations need to be aborted at the USB level,for example by halting the appropriate endpoint.</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-data.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-netdev.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">USB-ethernet Data Transfers</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-usb-slave-eth.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Network Device for the eCos TCP/IP Stack</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -