The core file supports the serial port installed on the TI TMS320C54x DSP. The serial port on the EVM is connected with a cable to COM2 on the PC. Before jumping to your code, the core file initializes the EVM's serial port to 38,400 bits per second (bps) with no parity, eight data bits, and one stop bit (but it may be necessary to restart the DSP completely if the serial port does not work.) It then accepts characters received from the PC by the UART (Universal Asynchronous Receiver/Transmitter) and buffers them in memory until your code retrieves them. It also can accept a block of bytes to transmit and send them to the UART in sequence.
Two macros are used to control the serial port:
READSER and WRITSER. Both accept
one parameter. READSER n reads up to
*AR3. (AR3 is left pointing one past
the last memory location written.) The actual number of
characters read is left in AR1. If
AR1 is zero, then no characters were available in
the input buffer.
WRITSER n adds
*AR3 to the
serial output buffer; in other words, it queues them to be
sent to the PC. AR3 is left pointing one location
after the last memory location read.
Note that READSER and WRITSER modify
registers AR0, AR1,
AR2, AR3, and BK, as
well as the flag TC. Be sure you restore these
registers after calling READSER and
WRITSER if you need them later in your code.
Note also that the core file allows up to 126 characters to be
stored in the input and output buffers. Neither the DSP
hardware nor the core file protect against serial-buffer
overflows, so you must be careful not to allow the input and
output buffers to overflow. (The length of the buffers can be
changed by editing ser_rxlen and
ser_txlen values in core.asm.)
The buffers are 127 characters long; however, the code cannot
distinguish between a completely-full and completely-empty
buffer. Therefore, only 126 characters can be stored in the
buffers.
It is easy to check if the input or output buffers in memory
are empty. The input buffer can be checked by comparing the
values stored in the memory locations srx_head
and srx_tail; if both memory locations hold the
same value, the input buffer is empty. Likewise, the output
buffer can be checked by comparing the values stored in memory
locations stx_head and stx_tail. The
number of characters in the buffer can be computed by
subtracting the head pointer from the tail pointer; add the
length of the buffer (normally 127) if the resulting distance
is negative.
The following example shows the minimal amount of code necessary to echo received data back through the serial port. It is available as ser_echo.asm.
1 .copy "core.asm"
2
3 .sect ".data"
4 hold .word 0
5
6 .sect ".text"
7 main
8 stm #hold,AR3 ; Read to hold location
9
10 READSER 1 ; Read one byte from serial port
11
12 cmpm AR1,#1 ; Did we get a character?
13 bc main,NTC ; if not, branch back to start
14
15 stm #hold,AR3 ; Write from hold location
16 WRITSER 1 ; ... one byte
17
18 b main
Line 8 sets AR3 to point to the
location hold so that READSER will
store serial data there. On Line 9,
READSER 1 reads one serial byte into hold;
the byte is placed in the low-order bits of the word, and the
high-order bits are zeroed. If a byte was read,
AR1 will be set to 1. AR1 is checked
in Line 12; Line 13 branches back to
the top if no byte was read. Otherwise, AR3 is
reset to hold (since READSER moved
it), then on Line 16, WRITSER sends
the word received. Finally, Line 18 branches back
to the start to receive another character.








