Instantiation, Handling requests – Comtrol eCos User Manual
Page 776

Writing New Devices - host
then be processed using aclocal, autoconf and automake in that order. Actually building the software then just
involves configure, make and make install, as per the instructions in the toplevel
README.host
file.
To assist developers, if the environment variable ECOSYNTH_DEVEL is set then a slightly different algorithm is
used for locating device Tcl scripts. Instead of looking only in the install tree the I/O auxiliary will also look in the
source tree, and if the script there is more recent than the installed version it will be used in preference. This allows
developers to modify the master copy without having to run make install all the time.
If a script needs to know where it has been installed it can examine the Tcl variable
synth::device_install_dir
. This variable gets updated whenever a script is loaded, so if the value may be needed later it should be saved away
in a device-specific variable.
Instantiation
The I/O auxiliary will source the device-specific Tcl script when the eCos application first attempts to instantiate
a device of that type. The script should return a procedure that will be invoked to instantiate a device.
namespace eval ethernet {
...
proc instantiate { id instance data } {
...
return ethernet::handle_request
}
}
return ethernet::instantiate
The
id
argument is a unique identifier for this device instance. It will also be supplied on subsequent calls to
the request handler, and will match the return value of
synth_auxiliary_instantiate
on the target side. A
common use for this value is as an array index to support multiple instances of this types of device. The
instance
and
data
arguments match the corresponding arguments to
synth_auxiliary_instantiate
on the target side,
so a typical value for
instance
would be
eth0
, and
data
is used to pass arbitrary initialization parameters from
target to host.
The actual work done by the instantiation procedure is obviously device-specific. It may involve allocating an
, adding a device-specific subwindow to the display, opening a real Linux device, establishing a
socket connection to some server, spawning a separate process to handle the actual I/O, or a combination of some
or all of the above.
If the device is successfully instantiated then the return value should be a handler for subsequent I/O requests.
Otherwise the return value should be an empty string, and on the target-side the
synth_auxiliary_instantiate
call will return
-1
. The script is responsible for providing
explaining why the device could not be
instantiated.
Handling Requests
When the target-side calls
synth_auxiliary_xchgmsg
, the I/O auxiliary will end up calling the request handler
for the appropriate device instance returned during instantiation:
namespace eval ethernet {
...
proc handle_request { id request arg1 arg2 txdata txlen max_rxlen } {
672