Skip to content

File syn_uart.h

FileList > drivers > syn_uart.h

Go to the source code of this file

UART driver — buffered I/O and formatted output. More...

  • #include "../common/syn_defs.h"
  • #include "../port/syn_port_uart.h"
  • #include "../util/syn_ringbuf.h"

Classes

Type Name
struct SYN_UART
UART driver handle.
struct SYN_UART_Config
Configuration struct for UART initialization with optional DMA.

Public Functions

Type Name
SYN_Status syn_uart_deinit (SYN_UART * uart)
De-initialize a UART instance.
SYN_Status syn_uart_init (SYN_UART * uart, SYN_UARTInstance instance, uint32_t baudrate)
Initialize a UART instance with buffered I/O.
SYN_Status syn_uart_init_config (SYN_UART * uart, const SYN_UART_Config * cfg)
Initialize a UART instance with custom configuration (optional DMA).
size_t syn_uart_read (SYN_UART * uart, uint8_t * data, size_t max_len)
Read bytes from the UART RX ring buffer.
bool syn_uart_rx_isr_feed (SYN_UART * uart, uint8_t byte)
Feed a received byte into the UART RX ring buffer.
bool syn_uart_tx_complete (const SYN_UART * uart)
Check if asynchronous TX is complete (tx_rb drained AND hardware shift register clear).
bool syn_uart_tx_isr_flush (SYN_UART * uart)
TX ISR drain callback — call from UART TXE interrupt.
SYN_Status syn_uart_write (const SYN_UART * uart, const uint8_t * data, size_t len, uint32_t timeout_ms)
Write a buffer of bytes to the UART (blocking).
SYN_Status syn_uart_write_async (SYN_UART * uart, const uint8_t * data, size_t len)
Non-blocking write to UART TX ring buffer (all-or-nothing atomic).
SYN_Status syn_uart_write_str (const SYN_UART * uart, const char * str, uint32_t timeout_ms)
Write a string to the UART (blocking).

Macros

Type Name
define SYN_UART_MAX_INSTANCES 2
Maximum UART instances supported.
define SYN_UART_RX_BUF_SIZE 128
UART receive buffer size (bytes).
define SYN_UART_TX_BUF_SIZE 128
UART transmit buffer size (bytes).

Detailed Description

Provides interrupt-driven buffered UART on top of the port layer. Each UART instance gets a TX and RX ring buffer. The buffer sizes are configurable in syn_config.h.

Public Functions Documentation

function syn_uart_deinit

De-initialize a UART instance.

SYN_Status syn_uart_deinit (
    SYN_UART * uart
) 

Parameters:

  • uart UART handle to deinitialize.

Returns:

SYN_OK on success.


function syn_uart_init

Initialize a UART instance with buffered I/O.

SYN_Status syn_uart_init (
    SYN_UART * uart,
    SYN_UARTInstance instance,
    uint32_t baudrate
) 

Parameters:

  • uart Pointer to a caller-owned SYN_UART struct.
  • instance UART peripheral number (0, 1, …).
  • baudrate Desired baud rate.

Returns:

SYN_OK on success.


function syn_uart_init_config

Initialize a UART instance with custom configuration (optional DMA).

SYN_Status syn_uart_init_config (
    SYN_UART * uart,
    const SYN_UART_Config * cfg
) 

Parameters:

  • uart Pointer to a caller-owned SYN_UART struct.
  • cfg Pointer to initialization configuration.

Returns:

SYN_OK on success.


function syn_uart_read

Read bytes from the UART RX ring buffer.

size_t syn_uart_read (
    SYN_UART * uart,
    uint8_t * data,
    size_t max_len
) 

Reads up to max_len bytes that have been received. Non-blocking: returns immediately with however many bytes are available.

Parameters:

  • uart UART handle.
  • data Buffer to read into.
  • max_len Maximum number of bytes to read.

Returns:

Number of bytes actually read.


function syn_uart_rx_isr_feed

Feed a received byte into the UART RX ring buffer.

bool syn_uart_rx_isr_feed (
    SYN_UART * uart,
    uint8_t byte
) 

Call this from your UART RX ISR to push incoming data into the driver's buffer.

Parameters:

  • uart UART handle.
  • byte The received byte.

Returns:

true if the byte was stored, false if the RX buffer is full.


function syn_uart_tx_complete

Check if asynchronous TX is complete (tx_rb drained AND hardware shift register clear).

bool syn_uart_tx_complete (
    const SYN_UART * uart
) 

Parameters:

  • uart UART handle.

Returns:

true if no bytes remain in software tx_rb AND hardware TC flag is set.


function syn_uart_tx_isr_flush

TX ISR drain callback — call from UART TXE interrupt.

bool syn_uart_tx_isr_flush (
    SYN_UART * uart
) 

Pops the next byte from tx_rb into the hardware data register. When the ring buffer empties, disables the TXE interrupt.

Parameters:

  • uart UART handle.

Returns:

true if a byte was transmitted, false if tx_rb is empty.


function syn_uart_write

Write a buffer of bytes to the UART (blocking).

SYN_Status syn_uart_write (
    const SYN_UART * uart,
    const uint8_t * data,
    size_t len,
    uint32_t timeout_ms
) 

Parameters:

  • uart UART handle.
  • data Data to transmit.
  • len Number of bytes.
  • timeout_ms Timeout in milliseconds (0 = no timeout).

Returns:

SYN_OK on success.


function syn_uart_write_async

Non-blocking write to UART TX ring buffer (all-or-nothing atomic).

SYN_Status syn_uart_write_async (
    SYN_UART * uart,
    const uint8_t * data,
    size_t len
) 

Pushes data into the internal TX ring buffer if space is available for all len bytes, and enables the TX interrupt to drain asynchronously. Returns SYN_BUSY without modifying the buffer if space is insufficient.

Parameters:

  • uart UART handle.
  • data Data to transmit.
  • len Number of bytes.

Returns:

SYN_OK on success, SYN_BUSY if ring buffer free space < len.


function syn_uart_write_str

Write a string to the UART (blocking).

SYN_Status syn_uart_write_str (
    const SYN_UART * uart,
    const char * str,
    uint32_t timeout_ms
) 

Parameters:

  • uart UART handle.
  • str Null-terminated string.
  • timeout_ms Timeout in milliseconds (0 = no timeout).

Returns:

SYN_OK on success.


Macro Definition Documentation

define SYN_UART_MAX_INSTANCES

Maximum UART instances supported.

#define SYN_UART_MAX_INSTANCES `2`


define SYN_UART_RX_BUF_SIZE

UART receive buffer size (bytes).

#define SYN_UART_RX_BUF_SIZE `128`


define SYN_UART_TX_BUF_SIZE

UART transmit buffer size (bytes).

#define SYN_UART_TX_BUF_SIZE `128`



The documentation for this class was generated from the following file src/syntropic/drivers/syn_uart.h