3.27_433:实现并验证RF433模块接收相应指令:新增UART路由核心模块,使程序能响应RF433/RS485指令,并向UART2输出LOG(RS485由于硬件原因未验证)
This commit is contained in:
97
Core/Inc/multi_uart_router.h
Normal file
97
Core/Inc/multi_uart_router.h
Normal file
@ -0,0 +1,97 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file multi_uart_router.h
|
||||
* @brief 多UART统一路由核心模块头文件
|
||||
* @author Application Layer
|
||||
* @version 1.0
|
||||
******************************************************************************
|
||||
* @attention
|
||||
* 本模块实现多UART端口的统一管理,包括:
|
||||
* - 接收环形缓冲区
|
||||
* - 发送环形缓冲区
|
||||
* - 端口上下文管理
|
||||
* - 响应路由表
|
||||
*
|
||||
* 设计依据:多通信接口统一指令处理系统开发计划 第3.1、3.3、3.5节及附录A
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef __MULTI_UART_ROUTER_H
|
||||
#define __MULTI_UART_ROUTER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include "usart.h"
|
||||
|
||||
#define UART_RX_BUFFER_SIZE 128
|
||||
#define UART_TX_BUFFER_SIZE 256
|
||||
|
||||
typedef enum {
|
||||
PORT_UART1 = 0,
|
||||
PORT_UART2 = 1,
|
||||
PORT_UART3 = 2,
|
||||
PORT_COUNT
|
||||
} port_id_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t buffer[UART_RX_BUFFER_SIZE];
|
||||
volatile uint16_t head;
|
||||
volatile uint16_t tail;
|
||||
volatile uint16_t count;
|
||||
volatile uint16_t overflow_count;
|
||||
} uart_rx_ring_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t buffer[UART_TX_BUFFER_SIZE];
|
||||
volatile uint16_t head;
|
||||
volatile uint16_t tail;
|
||||
volatile uint16_t count;
|
||||
volatile bool is_sending;
|
||||
volatile uint16_t overflow_count;
|
||||
} uart_tx_ring_t;
|
||||
|
||||
typedef struct {
|
||||
UART_HandleTypeDef *huart;
|
||||
const char *name;
|
||||
uart_rx_ring_t rx_ring;
|
||||
uart_tx_ring_t tx_ring;
|
||||
uint8_t rx_tmp;
|
||||
uint32_t rx_count;
|
||||
uint32_t tx_count;
|
||||
uint32_t error_count;
|
||||
bool initialized;
|
||||
} uart_port_context_t;
|
||||
|
||||
void MultiUART_Init(void);
|
||||
|
||||
void MultiUART_FeedByte(port_id_t port_id, uint8_t byte);
|
||||
|
||||
void MultiUART_Task(void);
|
||||
|
||||
void MultiUART_Send(port_id_t port_id, const uint8_t *data, uint16_t len);
|
||||
|
||||
void MultiUART_SendString(port_id_t port_id, const char *str);
|
||||
|
||||
void MultiUART_SendFmt(port_id_t port_id, const char *fmt, ...);
|
||||
|
||||
void MultiUART_TxCpltCallback(port_id_t port_id);
|
||||
|
||||
const char *MultiUART_GetPortName(port_id_t port_id);
|
||||
|
||||
uint16_t MultiUART_GetRxCount(port_id_t port_id);
|
||||
|
||||
uint16_t MultiUART_ReadByte(port_id_t port_id, uint8_t *byte);
|
||||
|
||||
uint16_t MultiUART_GetTxAvailable(port_id_t port_id);
|
||||
|
||||
uint32_t MultiUART_GetOverflowCount(port_id_t port_id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user