短路测试增加先下发V_ON为500mv的逻辑。让充电头一带电就打嗝

切换协议和CC线时,将V_ON设置顺序调整,避免指令被清楚

feat: 发布V1.1.19版本,优化短路测试与电压恢复逻辑

1.  更新所有文件版本号到V1.1.19,固件版本寄存器改为0x0123
2.  新增短路测试最低启动电压宏,设置为500mV,绕过普通V_ON门槛
3.  调整南向COM单次最大发送条数为8条,优化通信批次
4.  重构电压稳定确认逻辑,新增自动停止后恢复确认计数
5.  优化协议软卸载与完整握手流程,统一下发WORK_STOP和V_ON命令
6.  新增修改日志文档,补充本次更新说明与验证项
7.  新增UPK打包规则与YMODEM上位机实现文档
This commit is contained in:
wrh
2026-09-10 16:43:43 +08:00
parent 9a7950d122
commit d231a49771
9 changed files with 279 additions and 57 deletions
+10 -4
View File
@@ -1,7 +1,7 @@
/****************************************************************************
文件名称 : chrg_comm.c
完成日期 :
当前版本号 : V1.1.15
当前版本号 : V1.1.19
主要功能 : 实现对外通讯协议 MODBUS 服务端,以独立线程等待处理响应请求数据。
版本历史 : 创建原始版本
说明 :
@@ -27,7 +27,7 @@
#include "stm32f4xx_hal.h"
#define HOLD_REG_FIRMWARE_VERSION 0x0300U /* 协议板固件版本,只读 */
#define CHRG_FIRMWARE_VERSION 0x011FU /* 当前协议板版本:V1.1.15 */
#define CHRG_FIRMWARE_VERSION 0x0123U /* 当前协议板版本:V1.1.19 */
rt_uint8_t ucDiscInBuf[(TOTAL_DISC_REGS+BITS_UCHAR-1)/BITS_UCHAR];
rt_uint8_t ucCoilBuf[(TOTAL_COIL_REGS+BITS_UCHAR-1)/BITS_UCHAR];
@@ -618,7 +618,7 @@ eMBException funcReadHoldingRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
/*
* 协议板版本号使用独立的只读地址0x0300,不占用现有通道保持寄存器空间。
* 当前版本V1.1.15编码为0x011F,Modbus响应按高字节在前返回01 1F。
* 当前版本V1.1.19编码为0x0123,Modbus响应按高字节在前返回01 23。
* 该特殊地址只支持一次读取一个寄存器,避免与普通连续寄存器混用。
*/
if (regAddress == HOLD_REG_FIRMWARE_VERSION) {
@@ -2589,7 +2589,13 @@ static eMBException chrg_comm_apply_sink_effect(rt_uint8_t ch,
protocol_voltage_only = diff_info.pro_voltage_changed &&
!full_handshake_change && !protocol_current_change;
von_changed = (pReal->sink.volt_on != pShadow->sink.volt_on);
if ((sink_work == 0x01) && (old_on_work == 1U) && von_changed) {
/* 完整握手或协议软卸载会先清理本通道批次,V_ON由对应状态机在
* WORK_STOP之后重新加入;普通参数变化仍在这里立即下发。 */
if ((sink_work == 0x01) && (old_on_work == 1U) && von_changed &&
!full_handshake_change && !protocol_voltage_only &&
!protocol_current_change &&
(pReal->sink.test.test_mode != SINK_TEST_SHORT) &&
(pShadow->sink.test.test_mode != SINK_TEST_SHORT)) {
rt_uint16_t reg = Eload_Start_V_ON;
rt_uint16_t val = (pShadow->sink.volt_on <= 500U) ?
500U : pShadow->sink.volt_on;
+1 -1
View File
@@ -1,7 +1,7 @@
/****************************************************************************
文件名称 : chrg_comm.h
完成日期 :
当前版本号 : V1.1.15
当前版本号 : V1.1.19
主要功能 : 实现对外通讯协议 MODBUS 服务端,以独立线程等待处理响应请求数据。
版本历史 : 创建原始版本
说明 :
+5 -2
View File
@@ -1,7 +1,7 @@
/****************************************************************************
文件名称 : chrg_north.h
完成日期 :
当前版本号 : V1.1.14
当前版本号 : V1.1.19
主要功能 : 实现北向通信交互,包括接收命令解析,发送请求命令,切换通路。以独立线程处理。
版本历史 : 创建原始版本
说明 :
@@ -28,7 +28,10 @@
#endif
/* 南向COM批次中单通道连续收到有效回码后的最大发送条数。 */
#define SOU_COM_BURST_MAX 10U
#define SOU_COM_BURST_MAX 8U
/* 自动停止带载后,电压恢复时需要连续确认的新P1采样帧数。 */
#define SINK_LOAD_RESTART_CONFIRM_COUNT 3U
#define THR_NAME_NORTH "thr.nor"
#define DEV_NAME_NORTH "uart3"
+84 -38
View File
@@ -1,7 +1,7 @@
/****************************************************************************
文件名称 : chrg_sink.c
完成日期 :
当前版本号 : V1.1.14
当前版本号 : V1.1.19
主要功能 : 北向数据sink请求数据填充及发送。
版本历史 : 创建原始版本
说明 :
@@ -41,10 +41,12 @@ static rt_tick_t g_sink_unload_query_tick[TOTAL_SOU_CHS] = {0};
static rt_uint8_t g_sink_unload_confirm_count[TOTAL_SOU_CHS] = {0};
/* 记录各通道短路测试最近一次WORK_START的发送时间。 */
static rt_tick_t g_sink_short_start_tick[TOTAL_SOU_CHS] = {0};
#if SINK_VON_VOLTAGE_SOURCE == SINK_VON_VOLTAGE_FROM_PROTOCOL
/* 只消费新的协议板0x20电压回码,避免同一帧重复计入稳定次数。 */
/* 只消费新的V_On电压采样,避免同一帧重复计入稳定确认。 */
static rt_uint32_t g_sink_von_voltage_seq[TOTAL_SOU_CHS] = {0};
#endif
/* 协议切换期间清零,避免旧电压样本累计成启动确认。 */
static rt_uint8_t g_sink_von_stable_count[TOTAL_SOU_CHS] = {0};
/* 自动停止带载后的恢复确认计数,独立于首次握手的电压确认计数。 */
static rt_uint8_t g_sink_load_restart_confirm_count[TOTAL_SOU_CHS] = {0};
enum {
SINK_UNLOAD_NEXT_RUNNING = 0,
@@ -447,9 +449,15 @@ static int chrg_sink_work_load_stop(eIDX_SOU_CH idx,
if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL)) {
return -1;
}
/* 自动停止优先于同通道残留启动批次,禁止STOP后继续发送WORK_START。 */
if (chrg_sou_com_batch_cancel(idx) != 0) {
return -1;
}
if (chrg_sou_com_batch_submit(idx, &reg, &val, 1U) != 0) {
return -1;
}
g_sink_von_stable_count[idx] = 0U;
g_sink_load_restart_confirm_count[idx] = 0U;
pSW->sink.work_mode = SINK_WORK_LOAD_STANDBY;
return 0;
}
@@ -665,15 +673,23 @@ static int chrg_sink_work_switch(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
*****************************************************************/
static int chrg_sink_work_protocol_unload(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
{
rt_uint16_t reg = REG_WORK;
rt_uint16_t value = WORK_STOP;
rt_uint16_t regs[2] = {REG_WORK, Eload_Start_V_ON};
rt_uint16_t values[2];
if (chrg_sou_com_batch_submit(idx, &reg, &value, 1U) != 0) {
if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL)) {
return -1;
}
values[0] = WORK_STOP;
values[1] = (pSW->sink.volt_on <= 500U) ? 500U : pSW->sink.volt_on;
if (chrg_sou_com_batch_submit(idx, regs, values, 2U) != 0) {
return -1;
}
/* WORK_STOP回码只确认命令接收;还需连续读取两帧合格的实际电流。 */
chrg_sink_unload_confirm_reset(idx);
g_sink_von_stable_count[idx] = 0U;
g_sink_load_restart_confirm_count[idx] = 0U;
pSW->sink.work_mode = SINK_WORK_UNLOAD_WAIT;
return 0;
}
@@ -683,31 +699,35 @@ static int chrg_sink_work_protocol_unload(eIDX_SOU_CH idx, struct chrg_switch_t
函数描述: 执行协议或CC完整重握手前的南向安全断开和副继电器恢复
输入参数: idx:南向功率板通道 pSW:当前通道控制结构体
输出参数: 命令提交成功后进入SINK_WORK_HANDSHAKE_WAIT
返回说明: 0:四条命令提交成功 <0:参数或命令提交失败
其它说明: 命令顺序固定为WORK_STOP、CURRENT=1000mA、ALL_REL_OFF、FU_REL_ON;
WORK_STOP已关闭电子负载,1000mA仅为功率板停止阶段保存的电流设定值;
返回说明: 0:两条命令提交成功 <0:参数或命令提交失败
其它说明: 命令顺序固定为WORK_STOP、Eload_Start_V_ON;
WORK_STOP已关闭电子负载,V_ON随后更新到功率板;
主副继电器全部断开并确认回码后再单独打开副继电器;
北向Sink继电器保持接通,低电流确认完成后才允许重新握手
*****************************************************************/
static int chrg_sink_work_handshake_prepare(eIDX_SOU_CH idx,
struct chrg_switch_t *pSW)
{
rt_uint16_t reg = REG_WORK;
rt_uint16_t value = WORK_STOP;
rt_uint16_t regs[2] = {REG_WORK, Eload_Start_V_ON};
rt_uint16_t values[2];
if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL)) {
return -1;
}
values[0] = WORK_STOP;
values[1] = (pSW->sink.volt_on <= 500U) ? 500U : pSW->sink.volt_on;
/* 新CC/协议事务必须抢占本通道尚未发送的旧启动和设定命令。 */
if (chrg_sou_com_batch_cancel(idx) != 0) {
return -1;
}
if (chrg_sou_com_batch_submit(idx, &reg, &value, 1U) != 0) {
if (chrg_sou_com_batch_submit(idx, regs, values, 2U) != 0) {
return -1;
}
/* 协议或CC切换先停止电子负载,连续2次确认低电流后再操作继电器。 */
chrg_sink_unload_confirm_reset(idx);
g_sink_von_stable_count[idx] = 0U;
g_sink_load_restart_confirm_count[idx] = 0U;
pSW->sink.work_mode = SINK_WORK_HANDSHAKE_WAIT;
return 0;
}
@@ -719,7 +739,7 @@ static int chrg_sink_work_handshake_prepare(eIDX_SOU_CH idx,
full_handshake:RT_TRUE为完整重握手 RT_FALSE为协议参数软卸载
输出参数: 确认成功后将sink.work_mode切换为SINK_WORK_WAIT
返回说明: 0:继续等待或确认成功 <0:状态查询或优先量测请求失败
其它说明: 软卸载只要求WORK_STOP收到匹配回码后建立量测基线;完整重握手
其它说明: 软卸载要求WORK_STOP和V_ON收到匹配回码后建立量测基线;完整重握手
还要求CURRENT=1000mA、ALL_REL_OFF和FU_REL_ON回码成功,但保持北向Sink继电器接通
*****************************************************************/
static int chrg_sink_work_current_wait(eIDX_SOU_CH idx,
@@ -831,13 +851,14 @@ static int chrg_sink_TEST_DYNA_ON(rt_uint8_t ch, struct chrg_switch_t *pSW)
*****************************************************************/
static int chrg_sink_TEST_SHORT_ON(rt_uint8_t ch, struct chrg_switch_t *pSW)
{
rt_uint16_t regs[3] = {ModbusRTU_ShortTest_Hold_Time,ModbusRTU_ShortTest_CMD_MODE_FLAG, REG_WORK};
rt_uint16_t vals[3] = {0,0,0};
rt_uint16_t regs[4] = {Eload_Start_V_ON, ModbusRTU_ShortTest_Hold_Time,
ModbusRTU_ShortTest_CMD_MODE_FLAG, REG_WORK};
rt_uint16_t vals[4] = {SINK_SHORT_TEST_VON_MV, 0, 0, 0};
/* 外部工程固定短路测试保持60秒且不带载。 */
vals[0] = 60000;
vals[1] = ModbusRTU_DYNA_CMD_MODE_RUN_NO_CURR;
vals[2] = WORK_START;
if (chrg_sou_com_batch_submit((eIDX_SOU_CH)ch, regs, vals, 3) == 0) {
vals[1] = 60000;
vals[2] = ModbusRTU_DYNA_CMD_MODE_RUN_NO_CURR;
vals[3] = WORK_START;
if (chrg_sou_com_batch_submit((eIDX_SOU_CH)ch, regs, vals, 4) == 0) {
g_sink_short_start_tick[ch] = rt_tick_get();
return 0;
}
@@ -897,10 +918,10 @@ static rt_uint16_t chrg_sink_von_voltage_get(const struct chrg_switch_t *pSW)
int chrg_sink_volt_judge(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
{
rt_uint8_t stable_confirm_count;
rt_uint32_t voltage_seq;
static rt_uint8_t volt_low[TOTAL_SOU_CHS] = {0};
static rt_uint8_t no_curr[TOTAL_SOU_CHS] = {0};
static rt_uint8_t volt_set_ok[TOTAL_SOU_CHS] = {0};
static rt_uint8_t volt_stable_count[TOTAL_SOU_CHS] = {0};
static rt_tick_t running_start_tick[TOTAL_SOU_CHS] = {0};
rt_uint16_t von_voltage;
@@ -908,18 +929,32 @@ int chrg_sink_volt_judge(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
return -1;
}
#if SINK_VON_VOLTAGE_SOURCE == SINK_VON_VOLTAGE_FROM_PROTOCOL
if (pSW->Sink_voltage_seq == g_sink_von_voltage_seq[idx]) {
voltage_seq = pSW->Sink_voltage_seq;
#else
voltage_seq = chrg_eload_get_sample_seq(idx);
#endif
if (voltage_seq == g_sink_von_voltage_seq[idx]) {
return chrg_sink_work(idx, pSW);
}
g_sink_von_voltage_seq[idx] = voltage_seq;
/* 卸载和协议重配尚未完成时,旧电压只能用于推进安全流程,不能触发WORK_START。 */
if ((pSW->sink.work_mode == SINK_WORK_UNLOAD_WAIT) ||
(pSW->sink.work_mode == SINK_WORK_HANDSHAKE_WAIT) ||
((pSW->sink.work_mode != SINK_WORK_RUNING) &&
(pSW->sink.work_mode != SINK_WORK_LOAD_STANDBY) &&
(pSW->sub != IDX_GET_SINK_VC))) {
g_sink_von_stable_count[idx] = 0U;
g_sink_load_restart_confirm_count[idx] = 0U;
return chrg_sink_work(idx, pSW);
}
g_sink_von_voltage_seq[idx] = pSW->Sink_voltage_seq;
#endif
von_voltage = chrg_sink_von_voltage_get(pSW);
stable_confirm_count = chrg_sink_voltage_confirm_count(
pSW->sink.pro_loadv);
if ((pSW->sink.On_work == 1) && (pSW->sink.test.test_mode == 0)) {
if (von_voltage <= WORK_MIN_VOLT) {
volt_stable_count[idx] = 0;
g_sink_von_stable_count[idx] = 0U;
g_sink_load_restart_confirm_count[idx] = 0U;
if (volt_set_ok[idx] == 1 && ++volt_low[idx] >= 50) {
volt_set_ok[idx] = 0;
no_curr[idx] = 0;
@@ -933,47 +968,58 @@ int chrg_sink_volt_judge(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
pSW->change_flag = 0;
if (pSW->sink.work_mode == SINK_WORK_LOW_MONITOR) {
/* 副继电器恢复后首次重新检测到输入电压,只启动协议重握手。 */
volt_stable_count[idx] = 0;
g_sink_von_stable_count[idx] = 0U;
no_curr[idx] = 0;
pSW->sink.work_mode = SINK_WORK_WAIT;
} else if ((pSW->sink.work_mode == SINK_WORK_LOW) ||
(pSW->sink.work_mode == SINK_WORK_LOW_AUX_WAIT)) {
/* 掉电安全批次完成前,不得进入RUNING。 */
volt_stable_count[idx] = 0;
g_sink_von_stable_count[idx] = 0U;
no_curr[idx] = 0;
} else if (von_voltage > pSW->sink.volt_on) {
if ((pSW->sink.work_mode != SINK_WORK_RUNING) &&
(pSW->sink.work_mode != SINK_WORK_LOAD_STANDBY)) {
if (volt_stable_count[idx] < stable_confirm_count) {
volt_stable_count[idx]++;
if (g_sink_von_stable_count[idx] < stable_confirm_count) {
g_sink_von_stable_count[idx]++;
}
if (volt_stable_count[idx] >= stable_confirm_count) {
if (g_sink_von_stable_count[idx] >= stable_confirm_count) {
/* 连续达到当前目标对应的确认帧数后进入RUNING。 */
volt_stable_count[idx] = 0;
g_sink_von_stable_count[idx] = 0U;
pSW->sink.work_mode = SINK_WORK_RUNING;
running_start_tick[idx] = rt_tick_get();
no_curr[idx] = 0;
}
} else if (pSW->sink.work_mode == SINK_WORK_LOAD_STANDBY) {
volt_stable_count[idx] = 0;
no_curr[idx] = 0;
if (chrg_sink_load_should_start(pSW)) {
/* 因输入电压不足停止带载后,电压恢复时重新进入稳定确认。 */
pSW->sink.work_mode = SINK_WORK_WAIT;
/* 自动停止后只接受新的电压采样;达到恢复确认帧数才允许重启。 */
if (g_sink_load_restart_confirm_count[idx] <
SINK_LOAD_RESTART_CONFIRM_COUNT) {
g_sink_load_restart_confirm_count[idx]++;
}
if (g_sink_load_restart_confirm_count[idx] >=
SINK_LOAD_RESTART_CONFIRM_COUNT) {
g_sink_load_restart_confirm_count[idx] = 0U;
pSW->sink.work_mode = SINK_WORK_RUNING;
running_start_tick[idx] = rt_tick_get();
}
} else {
g_sink_load_restart_confirm_count[idx] = 0U;
}
} else if ((pSW->Now_current > 200) || (pSW->sink.loadc < 200)) {
volt_stable_count[idx] = 0;
g_sink_von_stable_count[idx] = 0U;
no_curr[idx] = 0;
} else if ((rt_tick_t)(rt_tick_get() - running_start_tick[idx]) >=
rt_tick_from_millisecond(SINK_CURRENT_START_GRACE_MS)) {
volt_stable_count[idx] = 0;
g_sink_von_stable_count[idx] = 0U;
if (++no_curr[idx] >= 2) {
pSW->sink.work_mode = SINK_WORK_WAIT;
no_curr[idx] = 0;
}
}
} else {
volt_stable_count[idx] = 0;
g_sink_von_stable_count[idx] = 0U;
g_sink_load_restart_confirm_count[idx] = 0U;
no_curr[idx] = 0;
/* 配置电压源低于负载设置的V_On时,立即停止电子负载。 */
if (pSW->sink.work_mode == SINK_WORK_RUNING) {
@@ -985,7 +1031,7 @@ int chrg_sink_volt_judge(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
volt_low[idx] = 0;
no_curr[idx] = 0;
volt_set_ok[idx] = 0;
volt_stable_count[idx] = 0;
g_sink_von_stable_count[idx] = 0U;
}
return chrg_sink_work(idx, pSW);
}
+5 -3
View File
@@ -1,7 +1,7 @@
/****************************************************************************
文件名称 : chrg_sink.c
完成日期 :
当前版本号 : V1.1.14
当前版本号 : V1.1.19
主要功能 : 北向数据sink请求数据填充及发送,命令字定义。
版本历史 : 创建原始版本
说明 :
@@ -23,6 +23,8 @@ struct chrg_switch_t;
#define SINK_TEST_DYNA 3
/* 短路测试期间按该周期补发WORK_START,防止功率板因超时停止。 */
#define SINK_SHORT_START_INTERVAL_MS 50U
/* 短路测试不受普通V_ON门槛限制,功率板使用最低启动电压。 */
#define SINK_SHORT_TEST_VON_MV 500U
//短路测试结构体
struct test_short {
rt_uint16_t hold_time; // 短路测试时间
@@ -212,8 +214,8 @@ enum {
/* Sink电压稳定确认参数,供chrg_sink_volt_judge使用。 */
#define SINK_VOLT_5V_TARGET_MV 5000U
#define SINK_VOLT_CONFIRM_NORMAL_COUNT 5U
#define SINK_VOLT_CONFIRM_5V_COUNT 15U
#define SINK_VOLT_CONFIRM_NORMAL_COUNT 3U
#define SINK_VOLT_CONFIRM_5V_COUNT 12U
#define SINK_CURRENT_START_GRACE_MS 200U
/* 主继电器闭合后的0V持续监控:由北向轮询线程每轮调用,掉电立即转掉电保护。 */
+21
View File
@@ -0,0 +1,21 @@
*** Using Compiler 'V6.16', folder: 'D:\keil mdk 2\ARM\ARMCLANG\Bin'
Build target 'chrg'
compiling chrg_north_pkg.c...
compiling chrg_vcom.c...
compiling chrg_thread.c...
compiling chrg_lcd.c...
compiling chrg_rel.c...
compiling chrg_eload.c...
compiling chrg_south.c...
compiling chrg_sink.c...
compiling chrg_north.c...
compiling chrg_source.c...
compiling chrg_roll_nor.c...
compiling chrg_roll_sou.c...
compiling chrg_comm.c...
linking...
Program Size: Code=151456 RO-data=15928 RW-data=9356 ZI-data=16052
FromELF: creating hex file...
After Build - User command #1: fromelf --bin .\build\keil\Obj\chrg.axf -o build/chrg.bin
".\build\keil\Obj\chrg.axf" - 0 Error(s), 0 Warning(s).
Build Time Elapsed: 00:00:05