From 58774a203872d3eba50fda83ed9764764198367a Mon Sep 17 00:00:00 2001 From: wangfq Date: Fri, 26 Jun 2026 09:46:58 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=B8=8A=E6=8A=A5=E9=A2=91=E7=8E=87?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=BB=8Eraw=20CAPVD=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E5=AE=9E=E9=99=85=E7=BA=BF=E5=9C=88=E9=A2=91=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit uart_report_packet_loop_acs 和 CMD_DBN_GET_MCJQ_PARAM 两处, loop_CAPVD 需经公式转换为实际频率后再上报: freq = sclk_freq * input_div * LPCNT / CAPVD 使用 uint64_t 先乘后除避免整数截断 --- .../at32f421_freertos_demo/src/main.c | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/vd960Loop/utilities/at32f421_freertos_demo/src/main.c b/vd960Loop/utilities/at32f421_freertos_demo/src/main.c index 55cb91a..a942f28 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/src/main.c +++ b/vd960Loop/utilities/at32f421_freertos_demo/src/main.c @@ -445,9 +445,14 @@ void uart_report_packet_loop_acs(uint8_t flag) g_pkg_uart_report.pkg[i++] = (g_loop_cng_info.loop_cng[j].loopFreq_Level << 6) | (1 << 4) | (unit->loop_SensLevel & 0x03); g_pkg_uart_report.pkg[i++] = 0 | ((!unit->loop_LOOP_OK) << 3) | (unit->loop_VD_FLAG << 2) | (_misc); - g_pkg_uart_report.pkg[i++] = (uint8_t)(unit->loop_CAPVD & 0xFF); - g_pkg_uart_report.pkg[i++] = (uint8_t)((unit->loop_CAPVD >> 8) & 0xFF); - g_pkg_uart_report.pkg[i++] = (uint8_t)((unit->loop_CAPVD >> 16) & 0xFF); + // 上报频率 = sclk_freq * input_div * LPCNT / CAPVD (先乘后除避免精度损失) + uint32_t _frequent = 0; + if (unit->loop_LPCNT > 0 && unit->loop_CAPVD > 0) { + _frequent = (uint32_t)((uint64_t)g_crm_clocks_freq_struct.sclk_freq * g_input_div * unit->loop_LPCNT / unit->loop_CAPVD); + } + g_pkg_uart_report.pkg[i++] = (uint8_t)(_frequent & 0xFF); + g_pkg_uart_report.pkg[i++] = (uint8_t)((_frequent >> 8) & 0xFF); + g_pkg_uart_report.pkg[i++] = (uint8_t)((_frequent >> 16) & 0xFF); uint32_t variation = (unit->loop_Origin > unit->loop_CAPVD) ? (unit->loop_Origin - unit->loop_CAPVD) : (unit->loop_CAPVD - unit->loop_Origin); @@ -759,9 +764,15 @@ void manage_dbn_ble_default(uint8_t *pkg, uint8_t len) tmp_ble_buf[i++] = (_cng->output_mode) | (_cng->loopSafe_Timeout << 3); tmp_ble_buf[i++] = _cng->exist_mode; tmp_ble_buf[i++] = _cng->direction_mode; - tmp_ble_buf[i++] = (uint8_t)(g_loop_states.loop_unit[j].loop_CAPVD & 0xFF); - tmp_ble_buf[i++] = (uint8_t)((g_loop_states.loop_unit[j].loop_CAPVD >> 8) & 0xFF); - tmp_ble_buf[i++] = (uint8_t)((g_loop_states.loop_unit[j].loop_CAPVD >> 16) & 0xFF); + // 上报频率 = sclk_freq * input_div * LPCNT / CAPVD (先乘后除避免精度损失) + uint32_t _freq = 0; + if (g_loop_states.loop_unit[j].loop_LPCNT > 0 && g_loop_states.loop_unit[j].loop_CAPVD > 0) { + _freq = (uint32_t)((uint64_t)g_crm_clocks_freq_struct.sclk_freq * g_input_div + * g_loop_states.loop_unit[j].loop_LPCNT / g_loop_states.loop_unit[j].loop_CAPVD); + } + tmp_ble_buf[i++] = (uint8_t)(_freq & 0xFF); + tmp_ble_buf[i++] = (uint8_t)((_freq >> 8) & 0xFF); + tmp_ble_buf[i++] = (uint8_t)((_freq >> 16) & 0xFF); _cng++; }