UART Emulator

Description

Full-duplex UART interface emulator

This resource emulates a single full-duplex UART interface, which is useful when an additional system UART interface is needed. Once started, the UART emulator code runs continuously on the Sensor Controller until it is stopped. No other tasks can be run on the Sensor Controller during this time frame.

This resource can only be used in one task per project.

An extensive API for accessing the UART Emulator from the System CPU application code is included in the generated driver. The API functions and constants begin with scifUart / scif<Prefix>Uart and (BV_)SCIF_UART / (BV_)SCIF_<PREFIX>_UART , respectively. The documentation for the API is also included in the generated driver.

General features:

  • Data rate up to 115200 baud, which can be changed dynamically. See below for details on baud rate and tolerance in RX.
  • No parity bit
  • No support for flow control
  • Large FIFOs with configurable size

RX features:

  • 1, 1.5 or 2 stop bits (only first stop bit is validated)
  • RX start bit detection can be enabled or disabled
    • Configurable RX idle period requirement, to prevent starting reception in the middle of ongoing traffic
  • Configurable RX byte timeout
  • Status flags for each received byte:
    • Framing error
    • Break
    • RX FIFO overflow
    • RX byte timeout
  • Maskable ALERT interrupt generation for these event(s):
    • The RX FIFO contains a configurable number of bytes, or more
    • RX byte timeout
    • Break or framing error

TX features:

  • 2 stop bits (compatible with 1 and 1.5 stop bits at the receiver end)
  • Configurable delay (0 to 255 bit periods) can be inserted before transmission of specific bytes in a TX stream
  • Maskable ALERT interrupt generation for these event(s):
    • The TX FIFO contains less than a configurable number of bytes

Baud Rate

The UART Emulator baud rate is 24000000 / (4 * N) , where N is an integer between 52 and 65535.

RX Baud Rate Tolerance

The UART Emulator runs at an interval that is 4 times the baud rate, and goes through these states for each bit:

  1. RX start bit detection + TX
  2. RX (if start bit was detected in state 1.)
  3. RX start bit detection + Interrupt and command handling
  4. RX (if start bit was detected in state 3.)

Since start bit detection is done two times per bit, the start bit will be sampled anywhere between 1/4 and 3/4 within that bit, instead of at 1/2 as for most hardware UART peripherals.

This means that the UART Emulator only tolerates 2.5 percent frequency offset, compared to the normal 5 percent.

Examples

Execution Code

// Run the UART emulator until the System CPU application calls scifUartStopEmulator()
uartEmulator();

System CPU Application (Simple Loopback)

// Start the UART emulator task
scifExecuteTasksOnceNbl(BV(SCIF_UART_TASK_ID));

// Enable baud rate generation
scifUartSetBaudRate(57600);

// Enable RX
scifUartSetRxEnableReqIdleCount(1);
scifUartRxEnable(1);

// Main loop
while (1) {

    // Loop back any received characters
    while (scifUartGetRxFifoCount()) {
        scifUartTxPutChar((char) scifUartRxGetChar());
    }
}

Procedures Overview

Name Brief description
uartEmulator() Runs the UART emulator. More …

Constants

Name Description
RX_BUFFER_SIZE RX buffer size (from configuration)
RX_FIFO_MAX_COUNT RX FIFO maximum number of used entries
TX_BUFFER_SIZE TX buffer size (from configuration)
TX_FIFO_MAX_COUNT TX FIFO maximum number of used entries

Global Variables

Name Description
cfg.alertMask Bit-vector selecting which UART events trigger ALERT interrupt
cfg.alertRxFifoThr Number of bytes (or higher) in the RX FIFO that triggers ALERT interrupt
cfg.alertTxFifoThr Number of bytes (or lower) in the TX FIFO that triggers ALERT interrupt
cfg.rxByteTimeout Maximum number of idle half bit-periods after a received byte before indicating timeout
cfg.rxEnableReqIdleCount Required number of idle half-bits before enabling RX.
input.pTxBuffer[] TX FIFO ring buffer
output.pRxBuffer[] RX FIFO ring buffer
state.alertBacklog Bit-vector of events not yet communicated to the application
state.alertEvents Bit-vector of events communicated to the application in the last ALERT interrupt
state.alertMask Currently used ALERT interrupt mask
state.exit Set to exit the UART emulator
state.rxEnable Set to enable RX, or clear to disable RX (controls whether start bits are detected)
state.rxEnabled Is RX currently enabled?
state.rxHead RX FIFO head index (updated by the Sensor Controller)
state.rxTail RX FIFO tail index (updated by the application)
state.txHead TX FIFO head index (updated by the application)
state.txTail TX FIFO tail index (updated by the Sensor Controller)

Procedures

uartEmulator

Prototype: uartEmulator()

Runs the UART emulator. Once this procedure has been called, the application can call the SCIF driver’s UART API.

This procedure does not return until the application has called scifUartStop() .