UART
- group UART Driver
Generic UART driver implementation for Chimera-SDK.
UART Parity Modes
Defines available parity options for UART.
-
UART_PARITY_NONE
No parity.
-
UART_PARITY_EVEN
Even parity.
-
UART_PARITY_ODD
Odd parity.
Default UART Configurations
Defines default UART settings, which can be overridden at compile-time.
-
UART_DEFAULT_BAUD_RATE
Default baud rate (bps).
-
UART_DEFAULT_DATA_BITS
Default number of data bits.
-
UART_DEFAULT_PARITY
Default parity mode.
-
UART_DEFAULT_STOP_BITS
Default number of stop bits.
-
UART_CLK_FREQ_HZ
Default clock frequency in Hz.
-
UART_BASE_ADDR
Default base address for UART.
Functions
-
void _uart_init(void)
Initializes the UART interface. This function sets up the UART hardware with the specified configuration.
-
void _uart_deinit(void)
De-initializes the UART interface. This function releases any resources held by the UART driver.
-
int uart_putc(char c, FILE *file)
Puts a character to the UART.
- Parameters:
c – Character to send.
file – Pointer to the FILE structure (unused).
- Returns:
The character written as an unsigned char cast to an int or EOF on error.
Variables
-
const uart_config_t default_uart_cfg
Default UART configuration settings.
This global configuration structure defines default parameters for UART communication, which can be overridden by the user.
Default Configuration:
uart_config_t default_cfg = { .baud_rate = UART_DEFAULT_BAUD_RATE, .clk_freq_hz = UART_CLK_FREQ_HZ, .data_bits = UART_DEFAULT_DATA_BITS, .parity = UART_DEFAULT_PARITY, .stop_bits = UART_DEFAULT_STOP_BITS };
-
const chi_interface_api_t default_uart_api
UART HAL API structure.
This structure defines function pointers for UART operations, allowing for modular driver implementations.
chi_interface_api_t uart_api = { .open = uart_open, .close = uart_close, .read = uart_read, .write = uart_write, .flush = uart_flush };
-
chi_interface_t default_uart_inst
-
struct uart_config_t
- #include <uart.h>
UART configuration structure.
This structure holds the configuration settings for UART initialization.
-
UART_PARITY_NONE
APB UART Driver
The APB UART driver implementation for Chimera-SDK. This driver provides initialization, read, and write functions for an APB-based UART peripheral.
- group UART APB Driver
APB UART driver implementation for Chimera-SDK.
APB UART register definitions for Chimera-SDK.
This file provides the implementation of UART initialization, read, and write functions for an APB-based UART peripheral. It includes blocking read and write operations along with basic configuration.
This file defines register offsets and fields for an APB-based UART peripheral. It is used in conjunction with the UART driver to configure and interact with the hardware.
UART Register Offsets
Defines the register offsets for the APB UART peripheral.
-
UART_RBR_REG_OFFSET
Receiver Buffer Register (RBR) Offset.
-
UART_THR_REG_OFFSET
Transmitter Holding Register (THR) Offset.
-
UART_INTR_ENABLE_REG_OFFSET
Interrupt Enable Register (IER) Offset.
-
UART_INTR_IDENT_REG_OFFSET
Interrupt Identification Register (IIR) Offset.
-
UART_FIFO_CONTROL_REG_OFFSET
FIFO Control Register (FCR) Offset.
-
UART_LINE_CONTROL_REG_OFFSET
Line Control Register (LCR) Offset.
-
UART_MODEM_CONTROL_REG_OFFSET
Modem Control Register (MCR) Offset.
-
UART_LINE_STATUS_REG_OFFSET
Line Status Register (LSR) Offset.
-
UART_MODEM_STATUS_REG_OFFSET
Modem Status Register (MSR) Offset.
-
UART_DLAB_LSB_REG_OFFSET
Divisor Latch LSB Register (DLAB_LSB) Offset.
-
UART_DLAB_MSB_REG_OFFSET
Divisor Latch MSB Register (DLAB_MSB) Offset.
UART Line Status Register (LSR) Bit Definitions
Defines the bit positions for the Line Status Register (LSR).
-
UART_LINE_STATUS_DATA_READY_BIT
Data Ready (DR) bit. Set when data is available in RBR.
-
UART_LINE_STATUS_THR_EMPTY_BIT
Transmitter Holding Register (THR) empty bit.
-
UART_LINE_STATUS_TMIT_EMPTY_BIT
Transmitter empty bit. Set when both THR and shift register are empty.
Functions
-
static inline int rx_ready(uint32_t base)
Checks if data is available to read from the UART receiver.
- Parameters:
base – Base address of the UART peripheral.
- Returns:
1 if data is ready, 0 otherwise.
-
static inline int tx_ready(uint32_t base)
Checks if the transmitter is ready to accept new data.
- Parameters:
base – Base address of the UART peripheral.
- Returns:
1 if the transmitter is ready, 0 otherwise.
-
static inline int tx_empty(uint32_t base)
Checks if the transmitter is completely empty.
- Parameters:
base – Base address of the UART peripheral.
- Returns:
1 if the transmitter is empty, 0 otherwise.
-
int uart_apb_flush(const chi_interface_t *iface)
Flushes the UART transmitter, ensuring all data is sent.
- Parameters:
iface – UART interface instance.
- Returns:
0 on success, -1 on failure.
-
int uart_apb_open(const chi_interface_t *iface)
Opens and initializes the UART interface.
- Parameters:
iface – UART interface instance.
- Returns:
0 on success, -1 on failure.
-
int uart_apb_close(const chi_interface_t *iface)
Closes the UART interface.
- Parameters:
iface – UART interface instance.
- Returns:
0 on success, -1 on failure.
-
ssize_t uart_apb_read(const chi_interface_t *iface, void *buffer, uint32_t size, chi_interface_callback_t cb)
Reads data from the UART receiver (blocking mode).
- Parameters:
iface – UART interface instance.
buffer – Buffer to store received data.
size – Number of bytes to read.
cb – Optional callback function (set to NULL if not needed).
- Returns:
Number of bytes read on success, -1 on failure.
-
ssize_t uart_apb_write(const chi_interface_t *iface, const void *buffer, uint32_t size, chi_interface_callback_t cb)
Writes data to the UART transmitter (blocking mode).
- Parameters:
iface – UART interface instance.
buffer – Data to send.
size – Number of bytes to write.
cb – Optional callback function (set to NULL if not needed).
- Returns:
Number of bytes written on success, -1 on failure.
-
UART_RBR_REG_OFFSET