Chapter 4: Software
R-Engine-D
4-14
Function Argument
Baud Rate
12 115,200
13 250,000
14 500,000
15 1,250,000
Table 4.1 Baud rate values for ser0 only
After initialization by calling
s0_init()
, SER0 is configured as a full-duplex serial port and is ready to
transmit/receive serial data at one of the specified 15 baud rates.
An input buffer,
ser0_in_buf
(whose size is specified by the user), will automatically store the
receiving serial data stream into the memory by DMA0 operation. In terms of receiving, there is no
software overhead or interrupt latency for user application programs even at the highest baud rate. DMA
transfer allows efficient handling of incoming data. The user only has to check the buffer status with
serhit0()
and take out the data from the buffer with
getser0()
, if any. The input buffer is used as a
circular ring buffer, as shown in Figure 4.1. However, the transmit operation is interrupt-driven.
ibuf
in_tail
ibuf+isiz
in_head
Figure 4.1 Circular ring input buffer
The input buffer (
ibuf
), buffer size (
isiz
), and baud rate (
baud
) are specified by the user with
s0_init()
with a default mode of 8-bit, 1 stop bit, no parity. After
s0_init()
you can set up a new mode with
different numbers for data-bit, stop bit, or parity by directly accessing the Serial Port 0 Control Register
(SP0CT) if necessary, as described in chapter 12 of the Am186ER manual for asynchronous serial ports.
Due to the nature of high-speed baud rates and possible effects from the external environment, serial input
data will automatically fill in the buffer circularly without stopping, regardless of overwrite. If the user
does not take out the data from the ring buffer with
getser0()
before the ring buffer is full, new data
will overwrite the old data without warning or control. Thus it is important to provide a sufficiently large
buffer if large amounts of data are transferred. For example, if you are receiving data at 9600 baud, a 4-
KB buffer will be able to store data for approximately four seconds.
However, it is always important to take out data early from the input buffer, before the ring buffer rolls
over. You may designate a higher baud rate for transmitting data out and a slower baud rate for receiving
data. This will give you more time to do other things, without overrunning the input buffer. You can use
serhit0()
to check the status of the input buffer and return the offset of the in_head pointer from the
in_tail pointer. A return value of 0 indicates no data is available in the buffer.
You can use
getser0()
to get the serial input data byte by byte using FIFO from the buffer. The in_tail
pointer will automatically increment after every
getser0()
call. It is not necessary to suspend external
devices from sending in serial data with /RTS. Only a hardware reset or
s0_close()
can stop this
receiving operation.
For transmission, you can use
putser0()
to send out a byte, or use
putsers0()
to transmit a
character string. You can put data into the transmit ring buffer,
s0_out_buf
, at any time using this