feat: 保存已验证的CH390网络打通基线

This commit is contained in:
2026-04-17 07:09:55 +08:00
parent 59eecf428f
commit 6aba77df9a
44 changed files with 6428 additions and 3372 deletions
+30 -130
View File
@@ -1,151 +1,51 @@
/**
* @file uart_trans.h
* @brief UART transparent transmission module for TCP2UART
*
* - UART2 <-> TCP Server (via StreamBuffer)
* - UART3 <-> TCP Client (via StreamBuffer)
* - DMA + IDLE interrupt for efficient reception
*/
#ifndef UART_TRANS_H
#define UART_TRANS_H
#ifndef __UART_TRANS_H__
#define __UART_TRANS_H__
#include <stdint.h>
#include <stdbool.h>
#include <stdint.h>
#include "FreeRTOS.h"
#ifdef __cplusplus
extern "C" {
#endif
/* UART channel definitions */
typedef enum {
UART_CHANNEL_SERVER = 0, /* UART2 - TCP Server channel */
UART_CHANNEL_CLIENT = 1, /* UART3 - TCP Client channel */
UART_CHANNEL_U0 = 0,
UART_CHANNEL_U1 = 1,
UART_CHANNEL_MAX
} uart_channel_t;
/* DMA buffer sizes */
#define UART_RX_DMA_BUFFER_SIZE 128
#define UART_TX_DMA_BUFFER_SIZE 128
/* UART configuration */
typedef struct {
uint32_t baudrate;
uint8_t data_bits; /* 8 or 9 */
uint8_t stop_bits; /* 1 or 2 */
uint8_t parity; /* 0=None, 1=Odd, 2=Even */
} uart_config_t;
uint8_t src_id;
uint8_t dst_mask;
uint16_t payload_len;
uint8_t payload[512];
} uart_mux_frame_t;
/* Default configurations */
#define UART_DEFAULT_BAUDRATE 115200
#define UART_DEFAULT_DATA_BITS 8
#define UART_DEFAULT_STOP_BITS 1
#define UART_DEFAULT_PARITY 0
#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
/* UART statistics */
typedef struct {
uint32_t rx_bytes;
uint32_t tx_bytes;
uint32_t rx_packets;
uint32_t tx_packets;
uint32_t errors;
} uart_stats_t;
/**
* @brief Initialize UART transparent transmission module
* @return 0 on success, negative on error
*/
int uart_trans_init(void);
/**
* @brief Configure UART channel parameters
* @param channel UART channel (SERVER or CLIENT)
* @param config UART configuration
* @return 0 on success, negative on error
*/
int uart_trans_config(uart_channel_t channel, const uart_config_t *config);
/**
* @brief Start UART reception (enable DMA + IDLE interrupt)
* @param channel UART channel
* @return 0 on success, negative on error
*/
int uart_trans_start(uart_channel_t channel);
/**
* @brief Stop UART reception
* @param channel UART channel
* @return 0 on success, negative on error
*/
int uart_trans_stop(uart_channel_t channel);
/**
* @brief Set StreamBuffer handles for TCP integration
* @param channel UART channel
* @param rx_stream StreamBuffer to receive data from TCP (for UART TX)
* @param tx_stream StreamBuffer to send data to TCP (from UART RX)
*/
void uart_trans_set_streams(uart_channel_t channel,
void *rx_stream,
void *tx_stream);
/**
* @brief Get UART statistics
* @param channel UART channel
* @param stats Pointer to statistics structure
*/
void uart_trans_get_stats(uart_channel_t channel, uart_stats_t *stats);
/**
* @brief Reset UART statistics
* @param channel UART channel
*/
void uart_trans_reset_stats(uart_channel_t channel);
/**
* @brief UART IDLE interrupt handler - call from stm32f1xx_it.c
* @param channel UART channel
*
* Usage in stm32f1xx_it.c USART2_IRQHandler:
* if (__HAL_UART_GET_FLAG(&huart2, UART_FLAG_IDLE)) {
* __HAL_UART_CLEAR_IDLEFLAG(&huart2);
* uart_trans_idle_handler(UART_CHANNEL_SERVER);
* }
*/
void uart_trans_idle_handler(uart_channel_t channel);
/**
* @brief UART DMA RX half complete callback - call from HAL callback
* @param channel UART channel
*/
void uart_trans_rx_half_cplt_handler(uart_channel_t channel);
/**
* @brief UART DMA RX complete callback - call from HAL callback
* @param channel UART channel
*/
void uart_trans_rx_cplt_handler(uart_channel_t channel);
/**
* @brief UART DMA TX complete callback - call from HAL callback
* @param channel UART channel
*/
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);
/**
* @brief Server transparent transmission task (UART2 <-> TCP Server)
* @param argument Task argument (unused)
*/
void uart_server_trans_task(void *argument);
/**
* @brief Client transparent transmission task (UART3 <-> TCP Client)
* @param argument Task argument (unused)
*/
void uart_client_trans_task(void *argument);
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 /* __UART_TRANS_H__ */
#endif