⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 io-eth-drv-api-funcs.html

📁 ecos 文档
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!-- 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
>Review of the functions</TITLE
><meta name="MSSmartTagsPreventParsing" content="TRUE">
<META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
"><LINK
REL="HOME"
TITLE="eCos Reference Manual"
HREF="ecos-ref.html"><LINK
REL="UP"
TITLE="Generic Ethernet Device Driver"
HREF="io-eth-drv-generic1.html"><LINK
REL="PREVIOUS"
TITLE="Generic Ethernet Device Driver"
HREF="io-eth-drv-generic1.html"><LINK
REL="NEXT"
TITLE="Upper Layer Functions"
HREF="io-eth-drv-upper-api.html"></HEAD
><BODY
CLASS="SECT1"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
SUMMARY="Header navigation table"
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>eCos Reference Manual</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="io-eth-drv-generic1.html"
ACCESSKEY="P"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 46. Generic Ethernet Device Driver</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="io-eth-drv-upper-api.html"
ACCESSKEY="N"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="SECT1"
><H1
CLASS="SECT1"
><A
NAME="IO-ETH-DRV-API-FUNCS">Review of the functions</H1
><P
>Now a brief review of the functions.  This discussion will use generic
names for the functions &#8212; your driver should use hardware-specific
names to maintain uniqueness against any other drivers.</P
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="IO-ETH-DRV-API-INIT">Init function</H2
><P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>static bool <TT
CLASS="REPLACEABLE"
><I
>DRV_HDWR</I
></TT
>_init(struct cyg_netdevtab_entry *tab)</PRE
></TD
></TR
></TABLE
>
This function is called as part of system initialization.  Its primary
function is to decide if the hardware (as indicated via
<SPAN
CLASS="TYPE"
>tab-&gt;device_instance</SPAN
>)
is working and if the interface needs to be made
available in the system.  If this is the case, this function needs to
finish with a call to the ethernet driver function:
<TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>    struct eth_drv_sc *sc = (struct eth_drv_sc *)tab-&#62;device_instance;
    <TT
CLASS="REPLACEABLE"
><I
>....initialization code....</I
></TT
>
    // Initialize upper level driver
    (sc-&gt;funs-&gt;eth_drv-&gt;init)( sc, unsigned char *enaddr );</PRE
></TD
></TR
></TABLE
>
where <TT
CLASS="PARAMETER"
><I
>enaddr</I
></TT
>
is a pointer to the ethernet station address for this unit, to inform
the stack of this device's readiness and availability.</P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>The ethernet station address
(<SPAN
CLASS="ACRONYM"
>ESA</SPAN
>)
is supposed to be a
world-unique, 48 bit address for this particular ethernet interface.
Typically it is provided by the board/hardware manufacturer in ROM.</P
><P
>In many packages it is possible for the
<SPAN
CLASS="ACRONYM"
>ESA</SPAN
>
to be set from RedBoot,
(perhaps from 'fconfig' data), hard-coded from
<SPAN
CLASS="ACRONYM"
>CDL</SPAN
>, or from an <SPAN
CLASS="ACRONYM"
>EPROM</SPAN
>.
A driver should choose a run-time specified
<SPAN
CLASS="ACRONYM"
>ESA</SPAN
>
(e.g. from RedBoot)
preferentially, otherwise (in order) it should use a <SPAN
CLASS="ACRONYM"
>CDL</SPAN
> specified
<SPAN
CLASS="ACRONYM"
>ESA</SPAN
>
if one has been set, otherwise an <SPAN
CLASS="ACRONYM"
>EPROM</SPAN
> set
<SPAN
CLASS="ACRONYM"
>ESA</SPAN
>, or otherwise
fail. See the <TT
CLASS="FILENAME"
>cl/cs8900a</TT
>
ethernet driver for an example.</P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="IO-ETH-DRV-API-START">Start function</H2
><P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>static void
<TT
CLASS="REPLACEABLE"
><I
>HRDWR</I
></TT
>_start(struct eth_drv_sc *sc, unsigned char *enaddr, int flags)</PRE
></TD
></TR
></TABLE
>
This function is called, perhaps much later than system initialization
time, when the system (an application) is ready for the interface to
become active.  The purpose of this function is to set up the hardware
interface to start accepting packets from the network and be able to
send packets out.  The receiver hardware should not be enabled prior to
this call.</P
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>This function will be called whenever the
up/down state of the logical interface changes, e.g. when the IP address
changes, or when promiscuous mode is selected by means of an
<TT
CLASS="FUNCTION"
>ioctl()</TT
> call in the application.
This may occur more than once, so this function needs to
be prepared for that case.</P
></BLOCKQUOTE
></DIV
><DIV
CLASS="NOTE"
><BLOCKQUOTE
CLASS="NOTE"
><P
><B
>Note: </B
>In future, the <TT
CLASS="PARAMETER"
><I
>flags</I
></TT
>
field (currently unused) may be used to tell the
function how to start up, e.g. whether interrupts will be used,
alternate means of selecting promiscuous mode etc.</P
></BLOCKQUOTE
></DIV
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="IO-ETH-DRV-API-STOP">Stop function</H2
><P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>static void <TT
CLASS="REPLACEABLE"
><I
>HRDWR</I
></TT
>_stop(struct eth_drv_sc *sc)</PRE
></TD
></TR
></TABLE
>
This function is the inverse of &#8220;start.&#8221;
It should shut down the hardware, disable the receiver, and keep it from
interacting with the physical network.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="IO-ETH-DRV-API-CONTROL">Control function</H2
><P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>static int
<TT
CLASS="REPLACEABLE"
><I
>HRDWR</I
></TT
>_control(
	struct eth_drv_sc *sc, unsigned long key,
	void *data, int len)</PRE
></TD
></TR
></TABLE
>
This function is used to perform low-level &#8220;control&#8221;
operations on the
interface.  These operations would typically be initiated via
<TT
CLASS="FUNCTION"
>ioctl()</TT
> calls in the BSD
stack, and would be anything that might require the hardware setup to
change (i.e. cannot be performed totally by the
platform-independent layers).</P
><P
>The <TT
CLASS="PARAMETER"
><I
>key</I
></TT
> parameter selects the operation, and the
<TT
CLASS="PARAMETER"
><I
>data</I
></TT
> and <TT
CLASS="PARAMETER"
><I
>len</I
></TT
> params point describe,
as required, some data for the operation in question.</P
><P
></P
><DIV
CLASS="VARIABLELIST"
><P
><B
>Available Operations:</B
></P
><DL
><DT
>ETH_DRV_SET_MAC_ADDRESS</DT
><DD
><P
>This operation sets the ethernet station address (ESA or MAC) for the
device.  Normally this address is kept in non-volatile memory and is
unique in the world.  This function must at least set the interface to
use the new address.  It may also update the NVM as appropriate.</P
></DD
><DT
>ETH_DRV_GET_IF_STATS_UD, ETH_DRV_GET_IF_STATS</DT
><DD
><P
>These acquire a set of statistical counters from the interface, and write
the information into the memory pointed to by <TT
CLASS="PARAMETER"
><I
>data</I
></TT
>.
The &#8220;UD&#8221; variant explicitly instructs the driver to acquire
up-to-date values.  This is a separate option because doing so may take
some time, depending on the hardware.</P
><P
>The definition of the data structure is in
<TT
CLASS="FILENAME"
>cyg/io/eth/eth_drv_stats.h</TT
>.</P
><P
>This call is typically made by SNMP, see <A
HREF="net-snmp-ecos-port.html"
>Chapter 47</A
>.</P
></DD
><DT
>ETH_DRV_SET_MC_LIST</DT
><DD
><P
>This entry instructs the device to set up multicast packet filtering
to receive only packets addressed to the multicast ESAs in the list pointed
to by <TT
CLASS="PARAMETER"
><I
>data</I
></TT
>.</P
><P
>The format of the data is a 32-bit count of the ESAs in the list, followed
by packed bytes which are the ESAs themselves, thus:
<TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD
><PRE
CLASS="PROGRAMLISTING"
>#define ETH_DRV_MAX_MC 8
struct eth_drv_mc_list {
    int len;
    unsigned char addrs[ETH_DRV_MAX_MC][ETHER_ADDR_LEN];
};</PRE
></TD
></TR
></TABLE
></P
></DD
><DT
>ETH_DRV_SET_MC_ALL</DT
><DD
><P
>This entry instructs the device to receive all multicast packets, and
delete any explicit filtering which had been set up.</P
></DD
></DL
></DIV
><P
>This function should return zero if the specified operation was
completed successfully.  It should return non-zero if the operation
could not be performed, for any reason.</P
></DIV
><DIV
CLASS="SECT2"
><H2
CLASS="SECT2"
><A
NAME="IO-ETH-DRV-API-CAN-SEND">Can-send function</H2
><P
><TABLE
BORDER="5"
BGCOLOR="#E0E0F0"
WIDTH="70%"
><TR
><TD

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -