Programming the TS-7300 UARTS

There are 8 serial ports on the TS-7300.  Each serial port has four device
files as follows.

       tty    cua    tty     cua
Port  8-bit  8-bit  9-bit   9-bit
   1  ttyTS0 cuats0 ttyT9S0 cuat9s0
   2  ttyTS1 cuats1 ttyT9S1 cuat9s1
   3  ttyTS2 cuats2 ttyT9S2 cuat9s2
   4  ttyTS3 cuats3 ttyT9S3 cuat9s3
   5  ttyTS4 cuats4 ttyT9S4 cuat9s4
   6  ttyTS5 cuats5 ttyT9S5 cuat9s5
   7  ttyTS6 cuats6 ttyT9S6 cuat9s6
   8  ttyTS7 cuats7 ttyT9S7 cuat9s7

To use the port in 8-bit mode, open the corresponding ttyTS or cuats file. 
The opened file can be read or written bytewise as expected.

To use the port in 9-bit mode, open the corresponding ttyT9S or cuat9s file
(e.g. /dev/ttyT9S0).  In this mode the length of all reads and writes should
be a multiple of two.  Data read and written is packed into a character array
in big-endian format, using two bytes for every 9 bit value (nontet).  The 
following example C snippet illustrates a simple read and write:

...
FILE *f;
unsigned char buffer[4];
int data;

f = fopen("/dev/ttyT9S0","r+");
buffer[0] = 0x01;	// set bit 8 of first nontet
buffer[1] = 0x55;	// lower 8-bits of first nontet
buffer[2] = 0x00;	// msB of second nontet, bit 8 is cleared
buffer[3] = 0xAA;	// lsB of second nontet
fwrite(buffer,1,4,f);

fread(buffer,1,4,f);
data = buffer[0] << 8 + buffer[1]; // extract first nontet
data = buffer[2] << 8 + buffer[3]; // extract second nontet
...

In the above case, buffer[0] and buffer[2] are the most significant bytes
(msB) of their respective nontets, and buffer[1] and buffer[3] are the
least significant bytes (lsB).

Each serial port can only have one device file open on it at a time. This
ensures that 8-bit and 9-bit mode are mutually exclusive and that the
byte stream remains synchronized when switching modes.

When reading, the upper 7 bits of the msB will always be zero.  This fact 
can be used for synchronization should the current state of the byte
stream be unknown. If the upper 7 bits of a given byte are not all zeros, 
then the byte is not the msB.

Likewise when writing, the upper 7 bits of the msB must always be set to
zero.  The serial port driver will reject bytes which do not have the
msB upper 7 bits set.  This can be used to ensure that synchronization is
maintained if the current synchronization state is unknown.  For example,
if 4 bytes of 0xFF are written, regardless of what state the serial
transmission is in, at most one 0xFF will be sent and then the driver
will start skipping invalid msBs.  As a result, the first byte of data
sent after the 0xFF sequence with the upper 7 bits clear will be considered
the new msB.

Normally these synchronization methods should not be necessary, as the
port, when opened, is synchronized such that the first byte read and
written will be considered the msB.  However for debugging, diagnostic
use, or recovery from application errors these features may be useful.
