Files
433_STM32/Core/Inc/uart3_passthrough.h

207 lines
6.5 KiB
C
Raw Normal View History

/**
******************************************************************************
* @file uart3_passthrough.h
* @brief UART3透传引擎模块头文件
* @author Application Layer
* @version 1.0
******************************************************************************
* @attention
* UART3智能数据路由与透传功能开发计划 3.2
*
*
* UART3接收的透传数据转发至UART1
*
* 3.2.2
* - passthrough_node_t:
* - passthrough_queue_t:
* - passthrough_context_t:
*
* D定义
* - PASSTHROUGH_NODE_SIZE: 128
* - PASSTHROUGH_MAX_NODES: 4
* - PASSTHROUGH_TOTAL_BUFFER: 512
******************************************************************************
*/
#ifndef __UART3_PASSTHROUGH_H
#define __UART3_PASSTHROUGH_H
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stdbool.h>
/*==============================================================================
*
* D配置参数
*============================================================================*/
/**
* @brief
*/
#ifndef PASSTHROUGH_NODE_SIZE
#define PASSTHROUGH_NODE_SIZE 128
#endif
/**
* @brief
*/
#ifndef PASSTHROUGH_MAX_NODES
#define PASSTHROUGH_MAX_NODES 4
#endif
/**
* @brief
*/
#ifndef PASSTHROUGH_TOTAL_BUFFER
#define PASSTHROUGH_TOTAL_BUFFER (PASSTHROUGH_NODE_SIZE * PASSTHROUGH_MAX_NODES)
#endif
/*==============================================================================
*
* 3.2.2
*============================================================================*/
/**
* @brief
* @note
*/
typedef struct {
uint8_t data[PASSTHROUGH_NODE_SIZE]; /**< 数据缓冲区 */
uint16_t length; /**< 有效数据长度 */
uint16_t offset; /**< 已发送偏移 */
bool valid; /**< 节点是否有效 */
} passthrough_node_t;
/*==============================================================================
*
* 3.2.2
*============================================================================*/
/**
* @brief
* @note FIFO队列
*/
typedef struct {
passthrough_node_t nodes[PASSTHROUGH_MAX_NODES]; /**< 节点数组 */
uint8_t write_index; /**< 写入位置 */
uint8_t read_index; /**< 读取位置 */
volatile uint16_t pending_count; /**< 待发送字节总数 */
} passthrough_queue_t;
/*==============================================================================
*
* 3.2.1
*============================================================================*/
/**
* @brief
* @note
*/
typedef struct {
uint32_t total_bytes_sent; /**< 累计发送字节数 */
uint32_t total_packets; /**< 累计发送数据包数 */
uint32_t overflow_count; /**< 缓冲区溢出次数 */
uint32_t busy_count; /**< UART1忙等待次数 */
} passthrough_stats_t;
/*==============================================================================
*
* 3.2.2
*============================================================================*/
/**
* @brief
* @note
*/
typedef struct {
passthrough_queue_t queue; /**< 透传队列 */
passthrough_stats_t stats; /**< 透传统计 */
bool initialized; /**< 初始化标志 */
} passthrough_context_t;
/*==============================================================================
*
* 3.2.2
*============================================================================*/
extern passthrough_context_t g_passthrough_ctx;
/*==============================================================================
*
* 3.2.1
*============================================================================*/
/**
* @brief
* @note
* @param
* @retval
*/
void Passthrough_Init(void);
/**
* @brief
* @note
* @param byte:
* @retval bool: true=false=
*/
bool Passthrough_PushByte(uint8_t byte);
/**
* @brief
* @note
* @param data:
* @param length:
* @retval uint16_t:
*/
uint16_t Passthrough_PushBuffer(const uint8_t *data, uint16_t length);
/**
* @brief
* @note
* @param
* @retval
*/
void Passthrough_Task(void);
/**
* @brief UART1发送完成回调
* @note HAL_UART_TxCpltCallback中调用
* @param
* @retval
*/
void Passthrough_OnTxComplete(void);
/**
* @brief UART1是否可发送
* @note UART1发送缓冲区是否有空间
* @param
* @retval bool: true=false=
*/
bool Passthrough_CanSend(void);
/**
* @brief
* @note
* @param stats:
* @retval
*/
void Passthrough_GetStats(passthrough_stats_t *stats);
/**
* @brief
* @note
* @param
* @retval
*/
void Passthrough_ResetStats(void);
/**
* @brief
* @note
* @param
* @retval uint16_t:
*/
uint16_t Passthrough_GetPendingCount(void);
#ifdef __cplusplus
}
#endif
#endif