Writing new devices target, Name, Synopsis – Comtrol eCos User Manual
Page 769: Description, Instantiating a device, Writing new devices - target

Writing New Devices - target
Name
Writing New Devices
— extending the synthetic target, target-side
Synopsis
#include
<
cyg/hal/hal_io.h
>
int synth_auxiliary_instantiate(const char* package, const char* version, const char*
device, const char* instance, const char* data);
void synth_auxiliary_xchgmsg(int device_id, int request, int arg1, int arg2, const
unsigned char* txdata, int txlen, int* reply , unsigned char* rxdata, int* rxlen, int
max_rxlen);
Description
In some ways writing a device driver for the synthetic target is very similar to writing one for a real target. Obviously
it has to provide the standard interface for that class of device, so for example an ethernet device has to provide
can_send
,
send
,
recv
and similar functions. Many devices will involve interrupts, so the driver contains ISR and
DSR functions and will call
cyg_drv_interrupt_create
,
cyg_drv_interrupt_acknowledge
, and related
functions.
In other ways writing a device driver for the synthetic target is very different. Usually the driver will not have any
direct access to the underlying hardware. In fact for some devices the I/O may not involve real hardware, instead
everything is emulated by widgets on the graphical display. Therefore the driver cannot just peek and poke device
registers, instead it must interact with host-side code by exchanging message. The synthetic target HAL provides a
function
synth_auxiliary_xchgmsg
for this purpose.
Initialization of a synthetic target device driver is also very different. On real targets the device hardware already
exists when the driver’s initialization routine runs. On the synthetic target it is first necessary to instantiate the
device inside the I/O auxiliary, by a call to
synth_auxiliary_instantiate
. That function performs a special
message exchange with the I/O auxiliary, causing it to load a Tcl script for the desired type of device and run an
instantiation procedure within that script.
Use of the I/O auxiliary is optional: if the user does not specify
--io
on the command line then the auxiliary will
not be started and hence most I/O operations will not be possible. Device drivers should allow for this possibility,
for example by just discarding any data that gets written. The HAL exports a flag
synth_auxiliary_running
which should be checked.
Instantiating a Device
Device instantiation should happen during the C++ prioritized static constructor phase of system initialization,
before control switches to
cyg_user_start
and general application code. This ensures that there is a clearly
665