Manual

Writing New Devices - target
arg1
arg2
For some requests it is convenient to pass one or two additional parameters alongside the request code. For
example an ethernet device could define a multicast-all request, with arg1 controlling whether this mode
should be enabled or disabled. Both arg1 and arg2 should be signed 32-bit integers, and their values are
interpreted only by the device-specific Tcl script.
txdata
txlen
Some I/O operations may involve sending additional data, for example an ethernet packet. Alternatively a
control operation may require many more parameters than can easily be encoded in arg1 and arg2, so those
parameters have to be placed in a suitable buffer and extracted at the other end. txdata is an arbitrary buffer
of txlen bytes that should be sent to the host-side. There is no specific upper bound on the number of bytes
that can be sent, but usually it is a good idea to allocate the transmit buffer statically and keep transfers down
to at most several kilobytes.
reply
If the host-side is expected to send a reply message then reply should be a pointer to an integer variable and
will be updated with a reply code, a simple 32-bit integer. The synthetic target HAL code assumes that the
host-side and target-side agree on the protocol being used: if the host-side will not send a reply to this message
then the reply argument should be a NULL pointer; otherwise the host-side must always send a reply code
and the reply argument must be valid.
rxdata
rxlen
Some operations may involve additional data coming from the host-side, for example an incoming ethernet
packet. rxdata should be a suitably-sized buffer, and rxlen a pointer to an integer variable that will end up
containing the number of bytes that were actually received. These arguments will only be used if the host-side
is expected to send a reply and hence the reply argument was not NULL.
max_rxlen
If a reply to this message is expected and that reply may involve additional data, max_rxlen limits the size of
that reply. In other words, it corresponds to the size of the rxdata buffer.
Most I/O operations involve only some of the arguments. For example transmitting an ethernet packet would use the
request, txdata and txlen fields (in addition to device_id which is always required), but would not involve
arg1 or arg2 and no reply would be expected. Receiving an ethernet packet would involve request, rxdata,
rxlen and max_rxlen; in addition reply is needed to get any reply from the host-side at all, and could be used
to indicate whether or not any more packets are buffered up. A control operation such as enabling multicast mode
would involve request and arg1, but none of the remaining arguments.
Interrupt Handling
Interrupt handling in the synthetic target is much the same as on a real target. An interrupt object is created using
cyg_drv_interrupt_create, attached, and unmasked. The emulated device - in other words the Tcl script run-
ning inside the I/O auxiliary - can raise an interrupt. Subject to interrupts being disabled and the appropriate vector
being masked, the system will invoke the specified ISR function. The synthetic target HAL implementation does
668