HOWTO: use the SCI I/O model on an Series 5000 Smart Transceiver (KB799)

To use the SCI I/O model properly on series 5000 chips, perform the following tasks: 

  1. Use the sci_in_request_ex() function instead of the io_in_request()function. The sci_in_request_ex() function has different parameters from the io_in_request()function.   sci_in_request_ex()  performs an interrupt-safe switch to the buffer & count passed in, and returns the count of bytes in the RX buffer during that interrupt-safe code section when the switch occurs.
  2. Use a "double buffering" technique to switch between two different incoming data buffer so that you will not miss any data.

The following Neuron C code example demonstrates steps 2 and 3, above:

// pragmas
#pragma num_alias_table_entries 0
#pragma specify_io_clock "10 MHz" 

// SCI_4800 etc., are declared in this header file
#include <io_types.h>

// SCI declaration
IO_8 sci baud(SCI_115200) iosci; 

// Buffers and variable declarations
char szRxBufA[50];
char szRxBufB[50];
unsigned short rx_count;
int bufTog;

// Function declaration
void processRxData(char buffer[50], unsigned short rx_count);

when(io_in_ready(iosci))
{
 // Switch to the other buffer and keep the RX count
 rx_count = sci_in_request_ex((bufTog) ? szRxBufA : szRxBufB, sizeof(szRxBufA));
 bufTog ^= 1; // toggle this
 
 // Do something with RX data using the filled data buffer. 
 // It may be only a few bytes, or it may be close to 50 bytes. 
 processRxData((bufTog) ? szRxBufA : szRxBufB, rx_count);
}

when (reset)
{
 (void)io_in_request(iosci, szRxBufA, 50);
 bufTog = 0;  // indicates that A is in use.
}

void processRxData(char buffer[50], unsigned short rx_count)
{
 io_out_request(iosci, buffer, rx_count);
}