Deliver function, Receive function – Comtrol eCos User Manual

Page 607

Advertising
background image

Chapter 46. Generic Ethernet Device Driver

Note: In future, this function may be extended so that the data need not be copied 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.

Deliver function

static void

HRDWR_deliver(struct eth_drv_sc *sc)

This function is called from the “Network Delivery Thread” in order to let the device driver do the time-consuming
work associated with receiving a packet — usually copying the entire packet from the hardware or a special memory
location into the network stack’s memory.

After handling any outstanding incoming packets or pending transmission status, it can unmask the device’s inter-
rupts, and free any relevant resources so it can process further packets.

It will be called when the interrupt handler for the network device has called

eth_drv_dsr( vector, count, (cyg_addrword_t)sc );

to alert the system that “something requires attention.” This

eth_drv_dsr()

call must occur from within the

interrupt handler’s DSR (not the ISR) or actually be the DSR, whenever it is determined that the device needs
attention from the foreground. The third parameter (

data

in the prototype of

eth_drv_dsr()

must be a valid

struct eth_drv_sc pointer

sc

.

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 of higher priority than network servicing are not denied the CPU by network
traffic.

To deliver a newly-received packet into the network stack, the deliver routine must call

(sc->funs->eth_drv->recv)(sc, len);

which will in turn call the receive function, which we talk about next. See also

the Section called Callback Receive

function

below.

Receive function

static void

HRDWR_recv(

struct eth_drv_sc *sc,

struct eth_drv_sg *sg_list, int sg_len)

This function is a call back, only invoked after the upper-level function

(sc->funs->eth_drv->recv)(struct eth_drv_sc *sc, int total_len)

503

Advertising