✨ feat(system-monitor): 新增SD卡存储监控功能并优化系统配置
- 新增SD卡存储监控功能,包含写入次数、错误次数、缓冲区满次数、总写入字节数和文件数量等统计指标 - 新增SD卡监控API函数,包括报告写入、报告错误、报告缓冲区满和报告文件创建 - 在data_storage.c中集成SD卡监控功能,在关键操作点添加监控报告 - 新增详细的使用文档《SD_Storage_Monitoring_Guide.md》,说明监控指标、API使用、集成方法和故障诊断 - 优化系统调试输出,在DebugOutput_PrintSystemStats中增加SD卡统计信息显示,包括基本统计、SD卡统计和计算指标(平均写入大小、错误率) - 调整SDIO时钟分频器从2改为1以提高SD卡通信速度 - 调整TIM2中断优先级从12改为3以提高定时器响应优先级 - 更新STM32CubeMX配置文件(.ioc)以反映SDIO时钟分频和TIM2中断优先级的更改 - 注释掉USB连接状态检测代码以简化主循环处理 - 优化ADC数据就绪中断处理,每2次触发一次DMA读取,并在DMA读取超时时报告数据溢出 - 移除ProcessAdcData函数中已注释的RS485发送代码 - 将数据溢出报告从ProcessAdcData函数移至HAL_GPIO_EXTI_Callback函数中的DMA读取超时处理
This commit is contained in:
+52
-13
@@ -175,7 +175,8 @@ static void ProcessAdcData(void)
|
||||
correction_applied = 1;
|
||||
|
||||
// 发送校正后的数据包
|
||||
RS485_SendData((uint8_t*)&g_corrected_packet, sizeof(CorrectedDataPacket_t));
|
||||
// RS485_SendData((uint8_t*)&g_corrected_packet, sizeof(CorrectedDataPacket_t));
|
||||
|
||||
} else {
|
||||
|
||||
// 4b. 校正失败或未启用,使用原始数据
|
||||
@@ -199,10 +200,7 @@ static void ProcessAdcData(void)
|
||||
// 7. 释放已处理的缓冲区
|
||||
LTC2508_ReleaseBuffer(LTC2508_GetCurrentReadBuffer());
|
||||
} else {
|
||||
// 数据来不及处理
|
||||
#if ENABLE_SYSTEM_MONITOR
|
||||
SystemMonitor_ReportDataOverflow();
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,18 +241,53 @@ static void DebugOutput_PrintSystemStats(void)
|
||||
return;
|
||||
}
|
||||
|
||||
char buffer[128];
|
||||
char buffer[256];
|
||||
SystemMonitorStats_t sys_stats;
|
||||
SystemMonitor_GetStats(&sys_stats);
|
||||
|
||||
// 打印基本统计信息
|
||||
snprintf(buffer, sizeof(buffer),
|
||||
"\r\n=== System Stats ===\r\n"
|
||||
"Total Samples: %lu\r\n"
|
||||
"Data Overflow: %lu\r\n",
|
||||
sys_stats.total_samples,
|
||||
sys_stats.data_overflow_count);
|
||||
|
||||
DebugOutput_SendString(buffer);
|
||||
|
||||
// 打印SD卡存储监控信息
|
||||
snprintf(buffer, sizeof(buffer),
|
||||
"=== SD Card Stats ===\r\n"
|
||||
"SD Write Count: %lu\r\n"
|
||||
"SD Write Errors: %lu\r\n"
|
||||
"SD Buffer Full: %lu\r\n"
|
||||
"SD Total Bytes: %lu\r\n"
|
||||
"SD File Count: %lu\r\n",
|
||||
sys_stats.sd_write_count,
|
||||
sys_stats.sd_write_error_count,
|
||||
sys_stats.sd_buffer_full_count,
|
||||
sys_stats.sd_total_bytes_written,
|
||||
sys_stats.sd_file_count);
|
||||
DebugOutput_SendString(buffer);
|
||||
|
||||
// 计算并打印统计指标
|
||||
if (sys_stats.sd_write_count > 0) {
|
||||
uint32_t avg_write_size = sys_stats.sd_total_bytes_written / sys_stats.sd_write_count;
|
||||
snprintf(buffer, sizeof(buffer),
|
||||
"Avg Write Size: %lu bytes\r\n",
|
||||
avg_write_size);
|
||||
DebugOutput_SendString(buffer);
|
||||
}
|
||||
|
||||
if (sys_stats.sd_write_count + sys_stats.sd_write_error_count > 0) {
|
||||
uint32_t total_attempts = sys_stats.sd_write_count + sys_stats.sd_write_error_count;
|
||||
uint32_t error_rate = (sys_stats.sd_write_error_count * 100) / total_attempts;
|
||||
snprintf(buffer, sizeof(buffer),
|
||||
"Write Error Rate: %lu%%\r\n",
|
||||
error_rate);
|
||||
DebugOutput_SendString(buffer);
|
||||
}
|
||||
|
||||
DebugOutput_SendString("====================\r\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -500,10 +533,10 @@ int main(void)
|
||||
uint32_t current_tick = HAL_GetTick();
|
||||
|
||||
// USB连接状态检测 (每500ms检测一次)
|
||||
if (current_tick - g_last_usb_check >= 500) {
|
||||
HandleUSBConnectionChange();
|
||||
g_last_usb_check = current_tick;
|
||||
}
|
||||
// if (current_tick - g_last_usb_check >= 500) {
|
||||
// HandleUSBConnectionChange();
|
||||
// g_last_usb_check = current_tick;
|
||||
// }
|
||||
|
||||
// 处理数据存储后台任务 (轮询方式)
|
||||
if (g_recording_enabled) {
|
||||
@@ -584,12 +617,18 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
||||
if(LTC2508_IsInited() == 0) return;
|
||||
|
||||
cnt ++;
|
||||
// if(cnt % 5 == 0)
|
||||
if(cnt % 2 == 0)
|
||||
{
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET);
|
||||
if (GPIO_Pin == ADC_DRY_Pin) {
|
||||
// ADC数据就绪,触发DMA读取
|
||||
LTC2508_TriggerDmaRead();
|
||||
if(LTC2508_ERROR_TIMEOUT == LTC2508_TriggerDmaRead())
|
||||
{
|
||||
// 数据来不及处理
|
||||
#if ENABLE_SYSTEM_MONITOR
|
||||
SystemMonitor_ReportDataOverflow();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
// HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);
|
||||
}
|
||||
|
||||
+1
-1
@@ -46,7 +46,7 @@ void MX_SDIO_SD_Init(void)
|
||||
hsd.Init.ClockPowerSave = SDIO_CLOCK_POWER_SAVE_DISABLE;
|
||||
hsd.Init.BusWide = SDIO_BUS_WIDE_1B;
|
||||
hsd.Init.HardwareFlowControl = SDIO_HARDWARE_FLOW_CONTROL_DISABLE;
|
||||
hsd.Init.ClockDiv = 2;
|
||||
hsd.Init.ClockDiv = 1;
|
||||
/* USER CODE BEGIN SDIO_Init 2 */
|
||||
|
||||
/* USER CODE END SDIO_Init 2 */
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
||||
__HAL_RCC_TIM2_CLK_ENABLE();
|
||||
|
||||
/* TIM2 interrupt Init */
|
||||
HAL_NVIC_SetPriority(TIM2_IRQn, 12, 0);
|
||||
HAL_NVIC_SetPriority(TIM2_IRQn, 3, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM2_IRQn);
|
||||
/* USER CODE BEGIN TIM2_MspInit 1 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user