Example – Echelon I/O Model Reference for Smart Transceivers and Neuron Chips User Manual
Page 127
I/O Model Reference
117
extra bytes. For example, if a transfer is set up by the slave for 100 bytes, and
there is a need to stop the transfer after 50 bytes, the interrupt driven firmware
will have most likely placed bytes 51 and 52 into the SPI’s transmit hardware.
You can use either the io_in( ) or io_out( ) function to initiate an I/O operation:
io_in(
io-object-name
, void *
buf
, unsigned
len
)
io_out(
io-object-name
, void *
buf
, unsigned
len
)
The io_in( ) and io_out( ) functions are non-blocking; they just initiate the data
transfer. You can use the io_in_ready(
io-object-name
) and io_out_ready(
io-object-
name
) event functions to test the state of the SPI interface. These functions are
used to determine when the transmission is complete. The io_out_ready event
returns TRUE when output is complete. The io_in_ready event returns the
number of bytes read in as an unsigned short, so when this value matches the
len
parameter from the call to io_in_request( ) the input operation is complete.
Although the io_in_ready(
) and io_out_ready(
) event functions both test the SPI
interface, the io_out_ready( ) function returns TRUE before the io_in_ready( )
function returns a count for the expected count. This difference is due to the fact
that the transmit data register chain holds two bytes of data and completes the
transmit process before the receive process completes. Thus, you should use the
io_in_ready( ) function to qualify the completion of a transfer.
You can use the spi_get_error(
io-object-name
) function to test for SPI errors.
Calling io_in( ) or io_out( ) clears any previous SPI error code. The spi_get_error(
) function also clears any SPI error code after returning it. This function returns
a cumulative OR of the following bits that reflect data errors:
0x10
Mode fault occurred
0x20
Receive overrun detected
You can use the spi_abort(
io-object-name
) function to terminate any operation in
progress. After an abort, the io_in_ready( ) function returns the number of
characters read up to the abort.
Example
IO_8 spi master clock(4) ioSpi;
when (...) {
io_out(ioSpi, “Hello SPI World!\r\n”, 18);
}
when (io_out_ready(ioSpi)) {
unsigned short spiEerror;
spiEerror = spi_get_error(ioSpi));
if (spiEerror) {
// Process SPI error
...
}
else {
// Process end of SPI transmission
...
}
}