52 lines
1.4 KiB
C
52 lines
1.4 KiB
C
#ifndef UART_TRANS_H
|
|
#define UART_TRANS_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stdint.h>
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
typedef enum {
|
|
UART_CHANNEL_U0 = 0,
|
|
UART_CHANNEL_U1 = 1,
|
|
UART_CHANNEL_MAX
|
|
} uart_channel_t;
|
|
|
|
typedef struct {
|
|
uint8_t src_id;
|
|
uint8_t dst_mask;
|
|
uint16_t payload_len;
|
|
uint8_t payload[512];
|
|
} uart_mux_frame_t;
|
|
|
|
#define UART_RX_DMA_BUFFER_SIZE 256u
|
|
#define UART_TX_DMA_BUFFER_SIZE 256u
|
|
#define UART_RX_RING_BUFFER_SIZE 512u
|
|
#define UART_TX_RING_BUFFER_SIZE 512u
|
|
|
|
int uart_trans_init(void);
|
|
int uart_trans_config(uint8_t uart_index, uint32_t baudrate);
|
|
int uart_trans_start_all(void);
|
|
bool uart_trans_send_buffer(uart_channel_t channel, const uint8_t *data, uint16_t len);
|
|
void uart_trans_notify_rx_from_isr(uart_channel_t channel, BaseType_t *xHigherPriorityTaskWoken);
|
|
void uart_trans_tx_cplt_handler(uart_channel_t channel);
|
|
void UartRxTask(void *argument);
|
|
bool uart_mux_try_extract_frame(uart_channel_t channel, uart_mux_frame_t *frame);
|
|
bool uart_mux_encode_frame(uint8_t src_id,
|
|
uint8_t dst_mask,
|
|
const uint8_t *payload,
|
|
uint16_t payload_len,
|
|
uint8_t *out,
|
|
uint16_t *out_len,
|
|
uint16_t out_capacity);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif
|