STM_ATEM/User/rs485_driver.c
zhoujie 5419e33397 feat(monitor): 增强系统监控与数据存储功能
- 新增数据存储缓冲区可用性检查,防止缓冲区满时数据丢失
- 新增会话文件夹管理功能,每次上电自动创建新的数据存储文件夹
- 新增监控状态定期保存功能,将系统统计信息写入MONITOR.TXT文件
- 新增数据丢弃统计,记录因缓冲区满而未存储的数据包数量
- 优化数据输出模式配置,支持串口输出和存储到卡的独立控制
- 优化USB连接处理逻辑,增加系统稳定性检查

🐛 fix(interrupt): 调整中断优先级配置

- 提高USART1中断优先级(从6调整为2),确保串口通信及时响应
- 调整DMA2_Stream5中断优先级(从0调整为5),优化数据传输调度
- 修复RS485驱动中的忙标志逻辑,改为阻塞式传输以提高可靠性

♻️ refactor(config): 优化系统配置和存储设置

- 重构宏定义配置,统一系统监控开关,分离数据输出模式控制
- 将SD卡最大扇区大小从512调整为4096,优化大文件存储性能
- 增加堆栈大小配置(从0x800调整为0x1000),提高系统稳定性
- 优化USB存储读写超时设置,使用最大超时值确保操作完成

📝 docs(comments): 更新代码注释和文档

- 更新数据存储模块的注释,说明新的会话文件夹管理机制
- 在main.c中添加数据输出模式选择的详细说明注释
- 更新系统监控统计输出格式,包含新增的数据丢弃统计项
2026-02-07 13:02:59 +08:00

59 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "rs485_driver.h"
#include <string.h>
static UART_HandleTypeDef *g_huart_485 = NULL;
static GPIO_TypeDef* g_de_re_port = NULL;
static uint16_t g_de_re_pin = 0;
volatile uint8_t g_rs485_tx_busy = 0;
void RS485_Init(UART_HandleTypeDef *huart, GPIO_TypeDef* de_re_port, uint16_t de_re_pin)
{
g_huart_485 = huart;
g_de_re_port = de_re_port;
g_de_re_pin = de_re_pin;
g_rs485_tx_busy = 0;
HAL_GPIO_WritePin(g_de_re_port, g_de_re_pin, GPIO_PIN_RESET); // 初始为接收模式
}
HAL_StatusTypeDef RS485_SendData(uint8_t *pData, uint16_t Size)
{
HAL_StatusTypeDef ret;
// if (g_rs485_tx_busy)
// {
// return HAL_BUSY;
// }
// g_rs485_tx_busy = 1;
HAL_GPIO_WritePin(g_de_re_port, g_de_re_pin, GPIO_PIN_SET); // 设置为发送模式
ret = HAL_UART_Transmit(g_huart_485, pData, Size, 0xffff);
// 注意:不能在这里立即切换回接收模式!
// DMA传输是非阻塞的需要在传输完成回调中切换
if (ret != HAL_OK)
{
// 如果启动DMA失败需要清除忙标志并切换回接收模式
HAL_GPIO_WritePin(g_de_re_port, g_de_re_pin, GPIO_PIN_RESET);
// g_rs485_tx_busy = 0;
}
// 等待数据传输完成
// while(g_rs485_tx_busy)
{
;
}
return ret;
}
// UART DMA传输完成回调函数
void RS485_TxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart == g_huart_485)
{
// DMA传输完成后切换回接收模式
// HAL_GPIO_WritePin(g_de_re_port, g_de_re_pin, GPIO_PIN_RESET);
// g_rs485_tx_busy = 0;
}
}