Callbacks – Comtrol eCos User Manual
Page 384

Chapter 17. How to Write a Driver
Callbacks
The device interface module can execute functions in the hardware independent driver via
chan-
>
callbacks
.
These functions are available:
void (*serial_init)( serial_channel *chan )
This function is used to initialize the serial channel. It is only required if the channel is being used in interrupt
mode.
void (*xmt_char)( serial_channel *chan )
This function would be called from an interrupt handler after a transmit interrupt indicating that additional charac-
ters may be sent. The upper driver will call the
putc
function as appropriate to send more data to the device.
void (*rcv_char)( serial_channel *chan, unsigned char c )
This function is used to tell the driver that a character has arrived at the interface. This function is typically called
from the interrupt handler.
Furthermore, if the device has a FIFO it should require the hardware independent driver to provide block transfer
functionality (driver CDL should include "implements CYGINT_IO_SERIAL_BLOCK_TRANSFER"). In that
case, the following functions are available as well:
bool (*data_xmt_req)(serial_channel *chan,
int space,
int* chars_avail,
unsigned char** chars)
void (*data_xmt_done)(serial_channel *chan)
Instead of calling
xmt_char()
to get a single character for transmission at a time, the driver should call
data_xmt_req()
in a loop, requesting character blocks for transfer. Call with a
space
argument of how much
space there is available in the FIFO.
If the call returns
true
, the driver can read
chars_avail
characters from
chars
and copy them into the FIFO.
If the call returns
false
, there are no more buffered characters and the driver should continue without filling up
the FIFO.
When all data has been unloaded, the driver must call
data_xmt_done()
.
bool (*data_rcv_req)(serial_channel *chan,
int avail,
int* space_avail,
unsigned char** space)
void (*data_rcv_done)(serial_channel *chan)
Instead of calling
rcv_char()
with a single character at a time, the driver should call
data_rcv_req()
in a loop,
requesting space to unload the FIFO to.
avail
is the number of characters the driver wishes to unload.
If the call returns
true
, the driver can copy
space_avail
characters to
space
.
If the call returns
false
, the input buffer is full. It is up to the driver to decide what to do in that case (callback
functions for registering overflow are being planned for later versions of the serial driver).
When all data has been unloaded, the driver must call
data_rcv_done()
.
280