From b49797ecc6de018523098dc4ef156fa9e64a055f Mon Sep 17 00:00:00 2001 From: wangfq Date: Fri, 3 Jul 2026 10:27:56 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20report=5Fcounter=20=E6=B8=85=E9=9B=B6?= =?UTF-8?q?=E5=AF=BC=E8=87=B4=E8=BD=A6=E9=97=B4=E8=B7=9D/=E9=80=9A?= =?UTF-8?q?=E8=BF=87=E6=97=B6=E9=97=B4=E4=B8=8B=E6=BA=A2=20(0xFFFFFFxx)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 根因: report_counter 清零后 last_exit_tick/passtime_start 存旧值, 再次进场时差值下溢 uint32_t → 0xFFFFFFF7 修复: - Loop154_States 新增 last_report_tick, report_counter 自由运行不复位 - report_misc: 增量判断 (report_counter - last_report_tick) >= _interval - TMR6 ISR: 用 last_report_tick 实现 UART 期间推迟上报, 不再清零 - 删掉所有 g_loop_states.report_counter = 0 --- vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h | 3 ++- vd960Loop/utilities/at32f421_freertos_demo/src/main.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h b/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h index 0c086b3..a779b36 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h +++ b/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h @@ -190,7 +190,8 @@ typedef struct { * 全局状态 *===========================================================================*/ typedef struct { - uint32_t report_counter; // 上报间隔计数器 (50ms tick) + uint32_t report_counter; // 上报间隔计数器 (50ms tick, 自由运行不复位) + uint32_t last_report_tick; // 上次上报时刻, 用于增量判断 uint8_t report_misc_round; // 空闲轮转: 0=MISC_TYPE_TIME, 1=CUT, 2=FLOW, 3=RELAY Loop154_Unit loop_unit[LOOP_CAPTURE_MAX]; } Loop154_States; diff --git a/vd960Loop/utilities/at32f421_freertos_demo/src/main.c b/vd960Loop/utilities/at32f421_freertos_demo/src/main.c index 4a3dcfa..44ecbed 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/src/main.c +++ b/vd960Loop/utilities/at32f421_freertos_demo/src/main.c @@ -429,7 +429,7 @@ void uart_report_packet_loop_acs(uint8_t flag) } else { _interval = REPORT_IDLE_TICKS; // 12×50ms = 600ms } - if (g_loop_states.report_counter < _interval) return; + if ((g_loop_states.report_counter - g_loop_states.last_report_tick) < _interval) return; /*--- 3. 确定本轮杂项类型 ---*/ if (_flag_event) { @@ -526,7 +526,7 @@ void uart_report_packet_loop_acs(uint8_t flag) g_pkg_uart_report.pkg[i++] = _sum & 0xFF; usart1_sendstring(g_pkg_uart_report.pkg, i); - g_loop_states.report_counter = 0; + g_loop_states.last_report_tick = g_loop_states.report_counter; } @@ -1062,7 +1062,7 @@ void TMR6_GLOBAL_IRQHandler(void) } } - g_loop_states.report_counter = 0; + g_loop_states.last_report_tick = g_loop_states.report_counter; }