Files
root ca13734bf0 Add full automotive RTOS project
Add kernel (Cortex-M0/M3/M4, Tricore, S32K, RISC-V ports), drivers,
middleware (CAN stack, diagnostics, safety), applications, board
support, build/test tooling, and documentation.
2026-08-23 03:35:29 -04:00

108 lines
2.8 KiB
C

/**
* @file uart_driver.h
* @brief UART driver interface
*/
#ifndef UART_DRIVER_H
#define UART_DRIVER_H
#include <stdint.h>
#include <stdbool.h>
#include "kernel.h"
/* UART Configuration Constants */
#define UART_MAX_INSTANCES 6
#define UART_MAX_BUFFER_SIZE 2048
#define UART_DEFAULT_BAUDRATE 115200
/* UART Baudrates */
typedef enum {
UART_BAUD_9600 = 9600,
UART_BAUD_19200 = 19200,
UART_BAUD_38400 = 38400,
UART_BAUD_57600 = 57600,
UART_BAUD_115200 = 115200,
UART_BAUD_230400 = 230400,
UART_BAUD_460800 = 460800,
UART_BAUD_921600 = 921600
} UartBaudrate_t;
/* UART Data Bits */
typedef enum {
UART_DATA_BITS_5 = 5,
UART_DATA_BITS_6 = 6,
UART_DATA_BITS_7 = 7,
UART_DATA_BITS_8 = 8,
UART_DATA_BITS_9 = 9
} UartDataBits_t;
/* UART Stop Bits */
typedef enum {
UART_STOP_BITS_1 = 0,
UART_STOP_BITS_1_5 = 1,
UART_STOP_BITS_2 = 2
} UartStopBits_t;
/* UART Parity */
typedef enum {
UART_PARITY_NONE = 0,
UART_PARITY_EVEN = 1,
UART_PARITY_ODD = 2
} UartParity_t;
/* UART Flow Control */
typedef enum {
UART_FLOW_CONTROL_NONE = 0,
UART_FLOW_CONTROL_RTS_CTS = 1,
UART_FLOW_CONTROL_XON_XOFF = 2
} UartFlowControl_t;
/* UART Callbacks */
typedef void (*UartRxCallback_t)(uint8_t* data, uint16_t length);
typedef void (*UartTxCallback_t)(void);
typedef void (*UartErrorCallback_t)(uint32_t error);
/* UART Configuration */
typedef struct {
UartBaudrate_t baudrate;
UartDataBits_t data_bits;
UartStopBits_t stop_bits;
UartParity_t parity;
UartFlowControl_t flow_control;
bool enable_rx;
bool enable_tx;
bool use_dma;
UartRxCallback_t rx_callback;
UartTxCallback_t tx_callback;
UartErrorCallback_t error_callback;
} UartConfig_t;
/* UART Statistics */
typedef struct {
uint32_t tx_bytes;
uint32_t rx_bytes;
uint32_t tx_errors;
uint32_t rx_errors;
uint32_t parity_errors;
uint32_t framing_errors;
uint32_t overrun_errors;
uint32_t dma_transfers;
} UartStatistics_t;
/* UART Driver Interface */
KernelStatus_t uart_init(uint8_t instance, UartConfig_t* config);
KernelStatus_t uart_deinit(uint8_t instance);
KernelStatus_t uart_send(uint8_t instance, const uint8_t* data, uint16_t length,
uint32_t timeout_ms);
KernelStatus_t uart_receive(uint8_t instance, uint8_t* data, uint16_t length,
uint32_t timeout_ms);
KernelStatus_t uart_send_async(uint8_t instance, const uint8_t* data, uint16_t length);
KernelStatus_t uart_receive_async(uint8_t instance, uint8_t* data, uint16_t length);
KernelStatus_t uart_flush(uint8_t instance);
KernelStatus_t uart_get_statistics(uint8_t instance, UartStatistics_t* stats);
uint16_t uart_get_rx_count(uint8_t instance);
uint16_t uart_get_tx_count(uint8_t instance);
void uart_process_interrupt(uint8_t instance);
#endif /* UART_DRIVER_H */