Init function, Start function, Stop function – Comtrol eCos User Manual

Page 604

Advertising
background image

Chapter 46. Generic Ethernet Device Driver

Init function

static bool DRV_HDWR_init(struct cyg_netdevtab_entry *tab)

This function is called as part of system initialization. Its primary function is to decide if the hardware (as indicated
via tab->device_instance) 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:

struct eth_drv_sc *sc = (struct eth_drv_sc *)tab->device_instance;

....initialization code....

// Initialize upper level driver

(sc-

>

funs-

>

eth_drv-

>

init)( sc, unsigned char *enaddr );

where

enaddr

is a pointer to the ethernet station address for this unit, to inform the stack of this device’s readiness

and availability.

Note: The ethernet station address (ESA) 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.

In many packages it is possible for the ESA to be set from RedBoot, (perhaps from ’fconfig’ data), hard-
coded from CDL, or from an EPROM. A driver should choose a run-time specified ESA (e.g. from RedBoot)
preferentially, otherwise (in order) it should use a CDL specified ESA if one has been set, otherwise an EPROM
set ESA, or otherwise fail. See the

cl/cs8900a

ethernet driver for an example.

Start function

static void

HRDWR_start(struct eth_drv_sc *sc, unsigned char *enaddr, int flags)

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.

Note: 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

ioctl()

call in the application.

This may occur more than once, so this function needs to be prepared for that case.

Note: In future, the

flags

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.

500

Advertising