Comtrol eCos User Manual

Page 770

Advertising
background image

Writing New Devices - target

defined point at which the I/O auxiliary knows that all required devices have been loaded. It can then perform
various consistency checks and clean-ups, run the user’s

mainrc.tcl

script, and make the main window visible.

For standard devices generic eCos I/O code will call the device initialization routines at the right time, iterating
through the

DEVTAB

table in a static constructor. The same holds for network devices and file systems. For more

custom devices code like the following can be used:

#include

<

cyg/infra/cyg_type.h

>

class mydev_init {

public:

mydev_init() {

...

}

};

static mydev_init mydev_init_object CYGBLD_ATTRIB_INIT_PRI(CYG_INIT_IO);

Some care has to be taken because the object

mydev_init_object

will typically not be referenced by other code,

and hence may get eliminated at link-time. If the code is part of an eCos package then problems can be avoided by
putting the relevant file in

libextras.a

:

cdl_package CYGPKG_DEVS_MINE {

...

compile -library=libextras.a init.cxx

}

For devices inside application code the same can be achieved by linking the relevant module as a

.o

file rather than

putting it in a

.a

library.

In the device initialization routine the main operation is a call to

synth_auxiliary_instantiate

. This takes

five arguments, all of which should be strings:

package

For device drivers which are eCos packages this should be a directory path relative to the eCos repository,
for example

devs/eth/synth/ecosynth

. This will allow the I/O auxiliary to find the various host-side

support files for this package within the install tree. If the device is application-specific and not part of an
eCos package then a NULL pointer can be used, causing the I/O auxiliary to search for the support files in the
current directory and then in

~/.ecos/synth

instead.

version

For eCos packages this argument should be the version of the package that is being used, for example

cur-

rent

. A simple way to get this version is to use the

SYNTH_MAKESTRING

macro on the package name. If the

device is application-specific then a NULL pointer should be used.

device

This argument specifies the type of device being instantiated, for example

ethernet

. More specifically the

I/O auxiliary will append a

.tcl

suffix, giving the name of a Tcl script that will handle all I/O requests for

the device. If the application requires several instances of a type of device then the script will only be loaded
once, but the script will contain an instantiation procedure that will be called for each device instance.

666

Advertising