📄 io-eth-drv-api-funcs.html
字号:
><PRECLASS="PROGRAMLISTING">static int <TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_can_send(struct eth_drv_sc *sc)</PRE></TD></TR></TABLE>This function is called to determine if it is possible to start thetransmission of a packet on the interface. Some interfaces will allowmultiple packets to be "queued" and this function allows for the highestpossible utilization of that mode.</P><P>Return the number of packets which could be accepted at this time, zeroimplies that the interface is saturated/busy.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="IO-ETH-DRV-API-SEND">Send function</H2><P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">struct eth_drv_sg { CYG_ADDRESS buf; CYG_ADDRWORD len;};static void<TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_send( struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len, int total_len, unsigned long key)</PRE></TD></TR></TABLE>This function is used to send a packet of data to the network. It isthe responsibility of this function to somehow hand the data over to thehardware interface. This will most likely require copying, but just theaddress/length values could be used by smart hardware.</P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>All data in/out of the driver is specified via a“scatter-gather”list. This is just an array of address/length pairs which describesections of data to move (in the order given by the array), as in the<SPANCLASS="TYPE">struct eth_drv_sg</SPAN> defined above and pointed to by<TTCLASS="PARAMETER"><I>sg_list</I></TT>.</P></BLOCKQUOTE></DIV><P>Once the data has been successfully sent by the interface (or if anerror occurs), the driver should call<TTCLASS="FUNCTION">(sc->funs->eth_drv->tx_done)()</TT>(see <AHREF="io-eth-drv-upper-api.html#IO-ETH-DRV-TX-DONE">the Section called <I>Callback Tx-Done function</I></A>)using the specified <TTCLASS="PARAMETER"><I>key</I></TT>.Only then will the upper layers release the resourcesfor that packet and start another transmission.</P><DIVCLASS="NOTE"><BLOCKQUOTECLASS="NOTE"><P><B>Note: </B>In future, this function may be extended so that the data need not becopied by having the function return a “disposition” code(done, send pending, etc). At this point, you should move the data to some“safe” location before returning.</P></BLOCKQUOTE></DIV></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="IO-ETH-DRV-API-DELIVER">Deliver function</H2><P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">static void<TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_deliver(struct eth_drv_sc *sc)</PRE></TD></TR></TABLE>This function is called from the “Network Delivery Thread” inorder to let the device driver do the time-consuming work associated withreceiving a packet — usually copying the entire packet from thehardware or a special memory location into the network stack's memory.</P><P>After handling any outstanding incoming packets or pending transmissionstatus, it can unmask the device's interrupts, and free any relevantresources so it can process further packets.</P><P>It will be called when the interrupt handler for the network devicehas called<TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING"> eth_drv_dsr( vector, count, (cyg_addrword_t)sc );</PRE></TD></TR></TABLE>to alert the system that “something requires attention.”This <TTCLASS="FUNCTION">eth_drv_dsr()</TT> call must occur from within theinterrupt handler's DSR (not the ISR) or actually <SPANCLASS="emphasis"><ICLASS="EMPHASIS">be</I></SPAN>the DSR, whenever it is determined thatthe device needs attention from the foreground. The third parameter(<TTCLASS="PARAMETER"><I>data</I></TT> in the prototype of<TTCLASS="FUNCTION">eth_drv_dsr()</TT> <SPANCLASS="emphasis"><ICLASS="EMPHASIS">must</I></SPAN>be a valid <SPANCLASS="TYPE">struct eth_drv_sc</SPAN> pointer <TTCLASS="VARNAME">sc</TT>.</P><P>The reason for this slightly convoluted train of events is to keep the DSR(and ISR) execution time as short as possible, so that other activities ofhigher priority than network servicing are not denied the CPU by networktraffic.</P><P>To deliver a newly-received packet into the network stack, the deliverroutine must call<TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">(sc->funs->eth_drv->recv)(sc, len);</PRE></TD></TR></TABLE>which will in turn call the receive function, which we talk about next.See also <AHREF="io-eth-drv-upper-api.html#IO-ETH-DRV-UPPER-RECV">the Section called <I>Callback Receive function</I></A> below.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="IO-ETH-DRV-API-RECV">Receive function</H2><P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">static void<TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_recv( struct eth_drv_sc *sc, struct eth_drv_sg *sg_list, int sg_len)</PRE></TD></TR></TABLE>This function is a call back, only invoked after theupper-level function<TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">(sc->funs->eth_drv->recv)(struct eth_drv_sc *sc, int total_len)</PRE></TD></TR></TABLE>has been called itself from your deliver function when it knows that apacket of data is available on theinterface. The <TTCLASS="FUNCTION">(sc->funs->eth_drv->recv)()</TT>function then arranges network buffersand structures for the data and then calls<TTCLASS="FUNCTION"><TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_recv()</TT> to actuallymove the data from the interface.</P><P>A scatter-gather list (<SPANCLASS="TYPE">struct eth_drv_sg</SPAN>) is used once more,just like in the send case.</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="IO-ETH-DRV-API-POLL">Poll function</H2><P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">static void<TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_poll(struct eth_drv_sc *sc)</PRE></TD></TR></TABLE>This function is used when in a non-interrupt driven system, e.g. wheninterrupts are completely disabled. This allows the driver time to checkwhether anything needs doing either for transmission, or to check ifanything has been received, or if any other processing needs doing.</P><P>It is perfectly correct and acceptable for the poll function to look likethis:<TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">static void<TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_poll(struct eth_drv_sc *sc){ <TTCLASS="REPLACEABLE"><I>my_interrupt_ISR</I></TT>(sc); <TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_deliver(struct eth_drv_sc *sc);}</PRE></TD></TR></TABLE>provided that both the ISR and the deliver functions are idempotent andharmless if called when there is no attention needed by the hardware. Somedevices might not need a call to the ISR here if the deliver functioncontains all the “intelligence.”</P></DIV><DIVCLASS="SECT2"><H2CLASS="SECT2"><ANAME="IO-ETH-DRV-API-INT-VECTOR">Interrupt-vector function</H2><P><TABLEBORDER="5"BGCOLOR="#E0E0F0"WIDTH="70%"><TR><TD><PRECLASS="PROGRAMLISTING">static int<TTCLASS="REPLACEABLE"><I>HRDWR</I></TT>_int_vector(struct eth_drv_sc *sc)</PRE></TD></TR></TABLE>This function returns the interrupt vector number used for receiveinterrupts.This is so that the common GDB stubs can detect when to checkfor incoming “CTRL-C” packets (used to asynchronouslyhalt the application) when debugging over ethernet.The GDB stubs need to know which interrupt the ethernet device usesso that they can mask or unmask that interrupt as required.</P></DIV></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="io-eth-drv-generic1.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="io-eth-drv-upper-api.html"ACCESSKEY="N">Next</A></TD></TR><TR><TDWIDTH="33%"ALIGN="left"VALIGN="top">Generic Ethernet Device Driver</TD><TDWIDTH="34%"ALIGN="center"VALIGN="top"><AHREF="io-eth-drv-generic1.html"ACCESSKEY="U">Up</A></TD><TDWIDTH="33%"ALIGN="right"VALIGN="top">Upper Layer Functions</TD></TR></TABLE></DIV></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -