Beruflich Dokumente
Kultur Dokumente
UART PROJECT
12.1UART ARCHITECTURE
A typical UART consists of a transmitter partition and a receiver partition.
A
commercial UART includes a set of programmable registers to characterize the device
environment and error reporting features. The environment includes baud rate, number
of STOP bits, and insertion of parity. The error reporting features include framing error
(message with no STOP bit), overrun error (UART receives a new message prior to the
CPU reading the old message), and parity error.
For this project, a simple UART
design is considered with NO personality registers, NO parity, and NO error detection
logic.
A CPU typically loads an eight-bit word into a UART. The UART frames the word with
a START bit (a logical 0) at the beginning and a STOP bit (a logical 1) at the end of the
word. It sends the framing information along with the data in a serial manner from the
Least Significant data Bit (LSB) to the Most Significant Bit (MSB). Figure 12.1.1-1
represents the timing waveform of a UART message issued by a UART transmitter and
received by a UART receiver.
354
In this example, the CPU loads a value of 54 (in hex) to the UART transmitter. TxDataT
represents the CPU parallel data, and Shift_LdF is the synchronous load, active low
pulse to the UART.
As soon as the data is loaded, the UART asserts on the
TxSerial_Out signal the START bit (a logical 0), followed by the 8-bit data from LSB to
MSB, followed by a STOP bit (a logical 1). In this example the data is 54 in hex or
0101_0100 in binary. Thus, the serial data sequence from LSB to MSB is 0010_1010, or
0_0010_1010_1 when the START and STOP bits are considered. The transmit UART
deasserts a Transmitter Empty (XmitMT) signal when the data is sent. This flags the
CPU that it cannot receive another character. When all bits are sent, it reasserts the
XmitMT signal so that at the next clock cycle a new data can be loaded.
The serial data is received by a UART receiver. Synchronization is based on the negative
transition of the START bit that resets a divide by 16 counter, which is clocked by a clock
16 times the bit clock. This counter is then used to detect mid-clock when it reaches a
value of 7. The receive UART stores the serial data into a Receive Shift register. When
all the data is framed, it alerts the receive CPU that data is ready (DataRdyT signal). The
RxData signal represents the received 8-bit word.
12.1.1.2
UART Project
355
356
Figure 12.1.1.2-3
Synplicity.
UART Project
357
358
UART Project
359
360
UART Project
361
12.2UART TESTBENCH
The UART testbench provides the following functions:
1. Instantiates the UART transmitter and UART receiver into an architecture so that the
serial data from the transmitter can be received by the receiver.
2. Emulates a UART CPU interface to load data into the transmit UART.
3. Sources the data to be sent to the UART from a text file to allow for easy
modifications of the contents of the data.
4. Emulates a UART CPU interface to extract data received from the Receive UART.
5. Stores the receive data into an output file, and also displays received data onto the
transcript window during simulation.
6. Emulates data link jitter between the transmitter and the receiver.
represents long and random delays caused by switching networks.
This jitter
7. Automatically verifies that the receiver properly receives the transmitted data.
Figure 12.2-1 represents a high level view of the UART testbench. A CPU transmit
emulator reads characters from a file and transfers the binary encoding of that character
to the transmit UART. It also sends through an abstract data path (global signal declared
in a package) a copy of the character to alert the automatic verifier that a character was
sent.
The serial output of the transmit UART is then passed through a link delay line that
delays the data with a pseudorandom delay.
The UART Receiver decodes a framed word and passes that data to a CPU receive
emulator. That CPU stores the received data into a file and passes the received
information to the verifier. It also displays the received data onto the transcript window
during simulation.
The verifier automatically verifies that the transmitted character matches the received
character. It detects the case when a transmitter sent a message, but after a reasonable
transmission delay the receiver never received the message. It also detects the case
when the receiver detects a received message without the character being transmitted
from the source.
Figure 12.2-2 is a more detailed representation of the testbench design that features the
following methodology:
1. Instantiation of UART transmitter and receiver as components.
362
UART Project
363
364
UART Project
12.2.1
365
UART Package
The UART package declaration provides subtype declarations and constant declarations
used by the testbench. To speedup the design of the testbench, a subset of the allowed
characters was specified as legal characters to use for transmission. Specifically, the
character 'A' through 'Z', the CR, and ' ' character are allowed. All other characters get
translated to '?'.
A constant Asc2Bit_c provides the type conversion between an ASCII
character between 'A' through 'Z' to a bit vector equivalent. This package also defines
two functions, one to determine if a character is in the range from 'A' to 'Z', and another
function to convert a bit vector to its ASCII equivalent. Again, this last conversion
functions limits the character sets to the one described above.
A user may wish to
enhance this package to include all the legal characters. The attributes 'POS and 'VAL
could be used to provide for those conversions.
To support automatic verification of data transfer, this package defines two global
signals:
1. SentData_s that is driven by the transmit protocol as it sends a character.
366
UART Project
367
368
12.2.2
Transmit Protocol
The transmit protocol is accomplished in a component that accepts a character from the
Command process, and is responsible for transferring that character to the Transmit
UART component using the UART processor interface protocol. This component also
alerts the Command process when the UART has completed the transaction. Figure
12.2.2 represents the VHDL code for the transmit protocol component.
UART Project
369
370
12.2.3
The Receive protocol component interfaces with the UART receiver, thus emulating a
processor interface to the receive UART. This component detects the receipt of data and
passes the converted value to a receive process located in the testbench. Figure 12.2.3
represents the VHDL code for the receive protocol component.
UART Project
12.2.4
371
This component models the transmission line jitter. This component delays the serial
input transitions by a pseudorandom delay defined in a generic. A configuration
declaration can be used to modify the value of this generic. A transport delay is used to
emulate the transmission line.
Figure 12.2.4 represents the VHDL code for
transmission line component.
372
12.2.5
The verifier is used to detect errors in the data transmission between the transmitter and
receiver. The verifier performs the following functions:
1. Automatically verifies that the transmitted character matches the received character.
2. Detects that a message is received after it is sent.
3. Detects when a message is received without being sent.
UART Project
373
374
12.2.6
The testbench components incorporates all the elements required to verify the operation
of the UART transmitter and receiver. Figure 12.2.6-1 represents the VHDL code for the
UART testbench. Figures 12.2.6-2 through 12.2.6-5 represent some simulation results.
UART Project
375
376
UART Project
377
378
UART Project
379
380
12.2.7
Configuration
A configuration can be used to modify the value of generics or to modify the selection of
an architecture. Figure 12.2.7-1 represents a configuration of the testbench to modify
the value of the delay generic in the transmission line jitter. Figure 12.2.7-2 represents
the simulation for this configuration. Note the transmission errors caused by this
excessive data line jitters.
381
UART Project
EXERCISES
1. Modify the transmit and receive UART components to include 2 STOP bits.
testbench and verify your results.
Rerun
2. Modify the transmit and receive UART components to include odd parity on the data.
Modify the testbench. Rerun the testbench and verify your results.
3. A real UART device includes a transmit Hold register that interfaces with the CPU
and loads an 8-bit word under the control of the processor. When the transmit shift
register is empty, it loads data from the transmit hold register if that register has a value.
Modify the architecture of the transmit UART to incorporate this transmit HOLD
register. Rerun the testbench and verify your results.
4. A real UART device includes a receive HOLD register to hold the value of the
received data. Data passed to the CPU is read from this receive HOLD register. Modify
the architecture of the receive UART to incorporate this receive HOLD register. Rerun
the testbench and verify your results.