This UART has two modules, one for RX and one for TX each of which uses one thread and is connected via channel to another thread using the UART Client API .
The thread for the UART TX component receives data from the client via a buffer (configurable between 1 and 64 bytes). A full buffer will block the client.
The thread for the UART RX component receives data from external into the RX buffer (configurable between 1 and 64 bytes) which is read by the client using channel. An empty RX buffer will block the client.
This UART is supported by all the hardware platforms from XMOS having suitable IO such as XC-1,XC-1A,XC-2,XK-1,etc and can be run on any XS1-L or XS1-G series devices.
File | Description |
module_uart_tx/src/uart_tx.h | Client API header file for Generic UART TX |
module_uart_tx/src/uart_tx.xc | Client API implementation for Generic UART TX |
module_uart_tx/src/uart_tx_impl.h | UART TX Server Header File |
module_uart_tx/src/uart_tx_impl.xc | UART TX Server implementation |
module_uart_rx/src/uart_rx.h | Client API header file for Generic UART RX |
module_uart_rx/src/uart_rx.xc | Client API implementation for Generic UART RX |
module_uart_rx/src/uart_rx_impl.h | UART RX Server Header File |
module_uart_rx/src/uart_rx_impl.xc | UART RX Server implementation |
The following table details the resource usage of the component.
Resource Usage Code Memory 2110 Ports 2 x 1b ChannelEnds 2
The UART functionality is demonstrated using the app_uart_back2back. This has been rpepared to run on an XK-1 board, but can easily be ported to other development boards with small modificatiosn to the code. To prepare the XK-1 board to run this app, simply connect a jumper such that ports 1A and 1B are connected (e.g. connect X0D1 and X0D0 pins on the GPIO header). Refer to the XK-1 Hardware Manual for pni positions.
The app can then be built and run.
It will send the full set of characters from the UART TX, receive them on UART RX and then print them out in batches of 10 characters.
It will receive via the RX component and echo via TX component.
The UART TX component is started using the uart_tx() function, which causes the TX server (called “_impl” in the code) to run in a while(1) loop until it receives and instruction to shut down via the channel from the client. Additionally a set of client functions are provided to transmit a byte and to alter the baud rate, parity, bits per byte and stop bit settings. Any such action except transmitting a byte causes the TX server to terminate and then be restarted with the new settings. Any data in the TX buffer is preserved and then sent with the new settings.
UART TX server function.
This function never returns and the arguments specify the initial configuration of parity, bits per byte etc. These are checked and then the inner UART TX loop (uart_tx_impl() is started and runs in a while(1) loop until it receives and instruction to shut down via the channel from the client. Additionally a set of client functions are provided to transmit a byte and to alter the baud rate, parity, bits per byte and stop bit settings. Note that the buffer size can only be changed when this function is first called, it cannot be changed thereafter.
The client provides data to the server using the send byte function below.
Arguments are as follows:
Parameters: |
|
---|
Adds a byte into the UART transmit buffer.
If the the buffer is full then this function blocks until there is room in the buffer.
Parameters: |
|
---|
These functions Set the baud rate, parity, stop bits and bits-per-byte settings of the of the UART TX server.
The change of configuration takes effect after all remaining data in transmit buffer is sent, and the functions block until the change of configuration takes effect.
Parameters: |
|
---|
The UART RX component is started using the uart_tx() function, which causes the TX server (called “_impl” in the code) to run in a while(1) loop until it receives and instruction to shut down via the channel from the client. Additionally a set of client functions are provided to fetch a byte from teh recieve buffer and to alter the baud rate, parity, bits per byte and stop bit settings. Any such action except transmitting a byte causes the RX server to terminate, the receive buffer emptied, and then restarted immediately with the new settings.
UART RX server function.
The client must call the uart_rx_init() function to initialize the server before calling any other client functions. Bytes received by the server are buffered in the array. When the buffer is full further incoming bytes of data will be dropped.
This function never returns, and will start the server RX inner loop which runs in a while(1) loop until it is stopped via a command over channelend, following whcih the inner loop is automatyically restarted.
The functions below are provided to change the UART RX parameters, parity, bits-per-byte, stop bits and baud rate, and all of these cause the RX inner loop to terminate while the new settings are applied. Bytes received during this time would be dropped, and any receive buffer contents are discarded when the settings are changed. Note that the buffer size can only be changed when this function is first called, it cannot be changed thereafter.
The client uses uart_rx_get_byte() to get bytes from the receive buffer.
Get a byte from the receive buffer.
This function blocks until there is a byte available.
Set the baud rate of the UART RX server.
The change of configuration takes place immediately.
Set the parity of the UART RX server.
The change of configuration takes place immediately.
Set number of stop bits used by the UART RX server.
The change of configuration takes place immediately.
Set number of bits per byte used by the UART RX server.
The change of configuration takes place immediately.
An application app_uart_test is provided to run in XSIM using the Loopback Plugin DLL (see Tools User Guide for details) that validates the various combinations of parity, stop bit, bits-per-byte and baud rate settings. It will send data out via the UART TX component using single bit port and receive via UART RX component from another single bit port. It will check that the data matches.
The testbench is run using a python script: regression_script_UART.py. The test suites are executed as follows (after having built the application with the makefile provided:
+==========================+===================================================+===============================================================+| |This test will confirm that buffer size is enough and data from |check buffering | <script.py> -check_buffering |TX buffer to RX buffer passes correctly |
runtime parameter change <script.py> -runtime_parameter_change This test will confirm UART module supports change in parameter during runtime such as baud-rate,bits per byte, parity, stopbit Parity test <script.py> -test_parity This test will confirm UART module discards data in case of mismatch in change in parity single test script.py -buad_rate <baud_rate> -bitsperbyte <bitsperbyte> -parity <parity> -stopbit <stopbit> This test will confirm UART module discards data in case of mismatch in change in parity regression test <script.py> This will take all possible combinations of baud-rate,bitsper byte,parity and no. of stop bits.it will use testlist.txt
The output is dumped to log.txt. This file should be manually removed, if it exists, before re-running.