Skip to content

File syn_uart.c

FileList > drivers > syn_uart.c

Go to the source code of this file

UART driver implementation.

  • #include "../util/syn_assert.h"
  • #include "syn_uart.h"
  • #include <string.h>

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.
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.
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_str (const SYN_UART * uart, const char * str, uint32_t timeout_ms)
Write a string to the UART (blocking).

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_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_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_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.



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