Comtrol eCos User Manual

Page 781

Advertising
background image

Writing New Devices - host

order of device initialization is not sufficiently defined. User scripts run from

mainrc.tcl

can use any hooks that

have been defined.

synth::hook_call takes an arbitrary list of arguments, for example:

synth::hook_call "ethernet_rx" "eth0" $packet

The callback function will always be invoked with a single argument, a list of the arguments that were passed to
synth::hook_call:

proc rx_callback { arg_list } {

set device [lindex $arg_list 0]

set packet [lindex $arg_list 1]

}

Although it might seem more appropriate to use Tcl’s eval procedure and have the callback functions invoked
with the right number of arguments rather than a single list, that would cause serious problems if any of the data
contained special characters such as

[

or

$

. The current implementation of hooks avoids such problems, at the cost

of minor inconvenience when writing callbacks.

A number of hooks are defined as standard. Some devices will add additional hooks, and the device-specific docu-
mentation should be consulted for those. User scripts can add their own hooks if desired.

exit

This hook is called just before the I/O auxiliary exits. Hence it provides much the same functionality as

atexit

in C programs. The argument list passed to the callback function will be empty.

ecos_exit

This hook is called when the eCos application has exited. It is used mainly to shut down I/O operations: if the
application is no longer running then there is no point in raising interrupts or storing incoming packets. The
callback argument list will be empty.

ecos_initialized

The synthetic target HAL will send a request to the I/O auxiliary once the static constructors have been run.
All devices should now have been instantiated. A script could now check how many instances there are of
a given type of device, for example ethernet devices, and create a little monitor window showing traffic on
all the devices. The

ecos_initialized

callbacks will be run just before the user’s

mainrc.tcl

script. The

callback argument list will be empty.

help

This hook is also invoked once static constructors have been run, but only if the user specified

-h

or

--help

.

Any scripts that add their own command line arguments should add a callback to this hook which outputs
details of the additional arguments. The callback argument list will be empty.

interrupt

Whenever a device calls synth::interrupt_raise the

interrupt

hook will be called with a single argument,

the interrupt vector. The main use for this is to allow user scripts to monitor interrupt traffic.

677

Advertising