R-Engine-D
Chapter 4: Software
4-15
method. The transmit ring buffer address (
obuf
) and buffer length (
osiz)
are also specified at the time of
initialization. The transmit interrupt service will check the availability of data in the transmit buffer. If
there is no more data (the head and tail pointers are equal), it will disable the transmit interrupt. Otherwise,
it will continue to take out the data from the out buffer, and transmit. After you call
putser0()
and
transmit functions, you are free to do other tasks with no additional software overhead on the transmitting
operation. It will automatically send out all the data you specify. After all data has been sent, it will clear
the busy flag and be ready for the next transmission.
The sample program
ser1_0.c
demonstrates how a protocol translator works. It would receive an input
HEX file from SER1 and translate every ‘:’ character to ‘?’. The translated HEX file is then transmitted
out of SER0. This sample program can be found in
tern\186\samples\ae
.
Software Interface
Before using the serial ports, they must be initialized.
There is a data structure containing important serial port state information that is passed as argument to the
TERN library interface functions. The
COM
structure should normally be manipulated only by TERN
libraries. It is provided to make debugging of the serial communication ports more practical. Since it
allows you to monitor the current value of the buffer and associated pointer values, you can watch the
transmission process.
typedef struct {
unsigned char ready; /* TRUE when ready */
unsigned char baud;
unsigned char mode;
unsigned char iflag; /* interrupt status */
unsigned char *in_buf; /* Input buffer */
int in_tail; /* Input buffer TAIL ptr */
int in_head; /* Input buffer HEAD ptr */
int in_size; /* Input buffer size */
int in_crcnt; /* Input <CR> count */
unsigned char in_mt; /* Input buffer FLAG */
unsigned char in_full; /* input buffer full */
unsigned char *out_buf; /* Output buffer */
int out_tail; /* Output buffer TAIL ptr */
int out_head; /* Output buffer HEAD ptr */
int out_size; /* Output buffer size */
unsigned char out_full; /* Output buffer FLAG */
unsigned char out_mt; /* Output buffer MT */
unsigned char tmso; // transmit macro service operation
unsigned char rts;
unsigned char dtr;
unsigned char en485;
unsigned char err;
unsigned char node;
unsigned char cr; /* scc CR register */
unsigned char slave;
unsigned int in_segm; /* input buffer segment */
unsigned int in_offs; /* input buffer offset */
unsigned int out_segm; /* output buffer segment */
unsigned int out_offs; /* output buffer offset */
unsigned char byte_delay; /* V25 macro service byte delay */
}
COM
;
s
n
_init
Arguments: unsigned char b, unsigned char* ibuf, int isiz, unsigned char* obuf, int osiz, COM* c
Return value: none