Files
TCP2UART/App/uart_trans.h
T

70 lines
1.8 KiB
C

/**
* @file uart_trans.h
* @brief Bare-metal UART DMA/IDLE transport layer.
*/
#ifndef __UART_TRANS_H__
#define __UART_TRANS_H__
#include <stdbool.h>
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum {
UART_CHANNEL_SERVER = 0,
UART_CHANNEL_CLIENT = 1,
UART_CHANNEL_MAX
} uart_channel_t;
#define UART_RX_DMA_BUFFER_SIZE 128u
#define UART_TX_DMA_BUFFER_SIZE 128u
#define UART_RX_RING_BUFFER_SIZE 512u
#define UART_TX_RING_BUFFER_SIZE 512u
typedef struct {
uint32_t baudrate;
uint8_t data_bits;
uint8_t stop_bits;
uint8_t parity;
} uart_config_t;
#define UART_DEFAULT_BAUDRATE 115200u
#define UART_DEFAULT_DATA_BITS 8u
#define UART_DEFAULT_STOP_BITS 1u
#define UART_DEFAULT_PARITY 0u
typedef struct {
uint32_t rx_bytes;
uint32_t tx_bytes;
uint32_t rx_packets;
uint32_t tx_packets;
uint32_t idle_events;
uint32_t rx_half_events;
uint32_t rx_full_events;
uint32_t errors;
} uart_stats_t;
int uart_trans_init(void);
int uart_trans_config(uart_channel_t channel, const uart_config_t *config);
int uart_trans_start(uart_channel_t channel);
int uart_trans_stop(uart_channel_t channel);
void uart_trans_poll(void);
uint16_t uart_trans_rx_available(uart_channel_t channel);
uint16_t uart_trans_read(uart_channel_t channel, uint8_t *data, uint16_t max_len);
uint16_t uart_trans_write(uart_channel_t channel, const uint8_t *data, uint16_t len);
void uart_trans_get_stats(uart_channel_t channel, uart_stats_t *stats);
void uart_trans_reset_stats(uart_channel_t channel);
void uart_trans_idle_handler(uart_channel_t channel);
void uart_trans_rx_half_cplt_handler(uart_channel_t channel);
void uart_trans_rx_cplt_handler(uart_channel_t channel);
void uart_trans_tx_cplt_handler(uart_channel_t channel);
#ifdef __cplusplus
}
#endif
#endif