From 1d7a6493cee196e586c1c6704c256961f0505e54 Mon Sep 17 00:00:00 2001 From: wrh Date: Sun, 9 Aug 2026 15:50:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E8=B4=9F=E8=BD=BD?= =?UTF-8?q?=E7=94=B5=E6=B5=81=E8=AF=BB=E5=8F=96=E3=80=81=E7=BB=A7=E7=94=B5?= =?UTF-8?q?=E5=99=A8=E9=80=BB=E8=BE=91=E4=B8=8E=E7=8A=B6=E6=80=81=E6=9C=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. apps/chrg/applications/thread/chrg_north.c: 注释掉IDX_SET_SINK_CC_BEFORE_PD状态赋值 2. apps/chrg/applications/utils/chrg_eload.c: 调整真实电流读取位置,避免被覆盖 3. apps/chrg/applications/thread/chrg_roll_sou.c: 启用并调整继电器切换延时,修复继电器控制逻辑 4. apps/chrg/applications/utils/chrg_sink.c: 新增电流确认状态变量,优化批量寄存器配置与工作模式判断 --- apps/chrg/applications/thread/chrg_north.c | 2 +- apps/chrg/applications/thread/chrg_roll_sou.c | 12 ++++-- apps/chrg/applications/utils/chrg_eload.c | 3 +- apps/chrg/applications/utils/chrg_sink.c | 42 ++++++++++--------- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/apps/chrg/applications/thread/chrg_north.c b/apps/chrg/applications/thread/chrg_north.c index b60fdd2..3c5622d 100644 --- a/apps/chrg/applications/thread/chrg_north.c +++ b/apps/chrg/applications/thread/chrg_north.c @@ -236,7 +236,7 @@ void chrg_sink_parse(rt_uint8_t *frame_data, eIDX_SOU_CH idx, * 当前回码不计入稳定电压次数,防止跳过协议设置直接带载。 */ volt_stable_count[idx] = 0; no_curr[idx] = 0; - pSW->sub = IDX_SET_SINK_CC_BEFORE_PD; + //pSW->sub = IDX_SET_SINK_CC_BEFORE_PD; 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)) { diff --git a/apps/chrg/applications/thread/chrg_roll_sou.c b/apps/chrg/applications/thread/chrg_roll_sou.c index 7d5ede4..c9c26e7 100644 --- a/apps/chrg/applications/thread/chrg_roll_sou.c +++ b/apps/chrg/applications/thread/chrg_roll_sou.c @@ -25,7 +25,7 @@ #define SOU_MUTEX_TIMEOUT_MS 100 #define SOU_RESPONSE_TIMEOUT_MS 20 #define SOU_COM_MAX_ATTEMPTS 3 -/* #define SOU_REL_SWITCH_DELAY_MS 150U */ // 暂时关闭主副继电器切换延时 +#define SOU_REL_SWITCH_DELAY_MS 100U #define SOU_CHANNEL_BIT(ch) ((rt_uint8_t)(1U << (ch))) chrg_rollsou_com_t g_sou_com_batch = {0}; @@ -566,16 +566,20 @@ static int sou_com_batch_complete(rt_uint8_t ch, rt_uint16_t reg, rt_uint16_t va } pBatch->cur_idx++; -#if 0 /* 暂时关闭副继电器与主继电器之间的固定延时;需要恢复时重新启用本段。 */ - if ((reg == REG_REL_ON) && (value == FU_REL_ON) && + if ((reg == REG_REL_ON) && (value == ALL_REL_OFF) && + (pBatch->cur_idx < pBatch->reg_cnt) && + (pBatch->reg_list[pBatch->cur_idx] == REG_REL_ON) && + (pBatch->val_list[pBatch->cur_idx] == FU_REL_ON)) { + pBatch->next_send_tick = rt_tick_get() + + rt_tick_from_millisecond(SOU_REL_SWITCH_DELAY_MS); + } else if ((reg == REG_REL_ON) && (value == FU_REL_ON) && (pBatch->cur_idx < pBatch->reg_cnt) && (pBatch->reg_list[pBatch->cur_idx] == REG_REL_ON) && (pBatch->val_list[pBatch->cur_idx] == ALL_REL_ON)) { pBatch->next_send_tick = rt_tick_get() + rt_tick_from_millisecond(SOU_REL_SWITCH_DELAY_MS); } -#endif if (pBatch->cur_idx >= pBatch->reg_cnt) { pBatch->pending = RT_FALSE; pBatch->result = 1; diff --git a/apps/chrg/applications/utils/chrg_eload.c b/apps/chrg/applications/utils/chrg_eload.c index 227f01e..2356154 100644 --- a/apps/chrg/applications/utils/chrg_eload.c +++ b/apps/chrg/applications/utils/chrg_eload.c @@ -335,6 +335,8 @@ int chrg_eload_parse (rt_uint8_t idx, rt_uint8_t pt, rt_uint8_t *data, rt_uint16 pLOAD->vpkn = swap_u16(pP1->Vpkn); pLOAD->vpp = swap_u16(pP1->Vpp); pLOAD->Ripple = swap_u16(pP1->Ripple); + /* 保留功率板返回的真实电流,供卸载保护判断使用。 */ + pSW->Now_current = pLOAD->current; /* * 低于2V时直接清零量测结果。只清理量测字段,保留工作状态、 * 故障、模式及测试结果,避免影响通道状态判断。 @@ -350,7 +352,6 @@ int chrg_eload_parse (rt_uint8_t idx, rt_uint8_t pt, rt_uint8_t *data, rt_uint16 pSW->VF = 0; } pSW->Now_voltage = pLOAD->voltage; - pSW->Now_current = pLOAD->current; /* 电压、电流均更新完成后再发布序号,避免状态机读取到半更新数据。 */ g_eload_sample_seq[idx]++; #if LCD_OPEN diff --git a/apps/chrg/applications/utils/chrg_sink.c b/apps/chrg/applications/utils/chrg_sink.c index 7f694dd..efcc815 100644 --- a/apps/chrg/applications/utils/chrg_sink.c +++ b/apps/chrg/applications/utils/chrg_sink.c @@ -27,6 +27,7 @@ /* 卸载确认只接受停止批次成功后产生的新P1量测。 */ static rt_uint32_t g_sink_unload_sample_seq[TOTAL_SOU_CHS] = {0}; static rt_bool_t g_sink_unload_batch_confirmed[TOTAL_SOU_CHS] = {RT_FALSE}; +static rt_bool_t g_sink_unload_current_confirmed[TOTAL_SOU_CHS] = {RT_FALSE}; 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}; @@ -66,6 +67,7 @@ static void chrg_sink_unload_confirm_reset(eIDX_SOU_CH idx) } g_sink_unload_sample_seq[idx] = 0U; g_sink_unload_batch_confirmed[idx] = RT_FALSE; + g_sink_unload_current_confirmed[idx] = RT_FALSE; g_sink_unload_query_tick[idx] = 0U; g_sink_unload_confirm_count[idx] = 0U; } @@ -85,7 +87,7 @@ rt_bool_t chrg_sink_handshake_north_ready(eIDX_SOU_CH idx) if (idx >= TOTAL_SOU_CHS) { return RT_FALSE; } - return g_sink_unload_batch_confirmed[idx]; + return g_sink_unload_current_confirmed[idx]; } /***************************************************************** @@ -320,8 +322,8 @@ static int chrg_sink_work_init_aux_wait(eIDX_SOU_CH idx, *****************************************************************/ static int chrg_sink_work_volt_runing(eIDX_SOU_CH idx, struct chrg_switch_t *pSW) { - rt_uint16_t regs[3] = {REG_REL_ON, 0, REG_WORK}; - rt_uint16_t vals[3] = {ALL_REL_ON, 0, WORK_START}; + rt_uint16_t regs[4] = {REG_REL_ON, REG_REL_ON, 0, REG_WORK}; + rt_uint16_t vals[4] = {FU_REL_ON, ALL_REL_ON, 0, WORK_START}; int ret; if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL)) { @@ -345,13 +347,13 @@ static int chrg_sink_work_volt_runing(eIDX_SOU_CH idx, struct chrg_switch_t *pSW } if (pSW->CV_mode == MODE_CONSTANT_VOLTAGE) { - regs[1] = REG_VOLTAGE_OUT + 1; - vals[1] = pSW->sink.loadv; + regs[2] = REG_VOLTAGE_OUT + 1; + vals[2] = pSW->sink.loadv; } else { - regs[1] = REG_CURRENT_OUT + 1; - vals[1] = pSW->sink.loadc; + regs[2] = REG_CURRENT_OUT + 1; + vals[2] = pSW->sink.loadc; } - return chrg_sou_com_batch_submit(idx, regs, vals, 3U); + return chrg_sou_com_batch_submit(idx, regs, vals, 4U); } /***************************************************************** @@ -368,8 +370,8 @@ static int chrg_sink_work_volt_runing(eIDX_SOU_CH idx, struct chrg_switch_t *pSW static int chrg_sink_work_soft_resume(eIDX_SOU_CH idx, struct chrg_switch_t *pSW) { - rt_uint16_t regs[3] = {REG_REL_ON, 0, REG_WORK}; - rt_uint16_t vals[3] = {ALL_REL_ON, 0, WORK_START}; + rt_uint16_t regs[4] = {REG_REL_ON, REG_REL_ON, 0, REG_WORK}; + rt_uint16_t vals[4] = {FU_REL_ON, ALL_REL_ON, 0, WORK_START}; int ret; if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL)) { @@ -388,13 +390,13 @@ static int chrg_sink_work_soft_resume(eIDX_SOU_CH idx, return ret; } if (pSW->CV_mode == MODE_CONSTANT_VOLTAGE) { - regs[1] = REG_VOLTAGE_OUT + 1; - vals[1] = pSW->sink.loadv; + regs[2] = REG_VOLTAGE_OUT + 1; + vals[2] = pSW->sink.loadv; } else { - regs[1] = REG_CURRENT_OUT + 1; - vals[1] = pSW->sink.loadc; + regs[2] = REG_CURRENT_OUT + 1; + vals[2] = pSW->sink.loadc; } - if (chrg_sou_com_batch_submit(idx, regs, vals, 3U) != 0) { + if (chrg_sou_com_batch_submit(idx, regs, vals, 4U) != 0) { return -1; } pSW->sink.work_mode = SINK_WORK_SOFT_RUNNING; @@ -439,15 +441,16 @@ static int chrg_sink_work_load_stop(eIDX_SOU_CH idx, static int chrg_sink_work_load_resume(eIDX_SOU_CH idx, struct chrg_switch_t *pSW) { - rt_uint16_t regs[3] = {REG_REL_ON, REG_CURRENT_OUT + 1, REG_WORK}; - rt_uint16_t vals[3] = {ALL_REL_ON, 0, WORK_START}; + rt_uint16_t regs[4] = {REG_REL_ON, REG_REL_ON, + REG_CURRENT_OUT + 1, REG_WORK}; + rt_uint16_t vals[4] = {FU_REL_ON, ALL_REL_ON, 0, WORK_START}; if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL) || !chrg_sink_load_should_start(pSW)) { return -1; } - vals[1] = pSW->sink.loadc; - if (chrg_sou_com_batch_submit(idx, regs, vals, 3U) != 0) { + vals[2] = pSW->sink.loadc; + if (chrg_sou_com_batch_submit(idx, regs, vals, 4U) != 0) { return -1; } pSW->sink.work_mode = SINK_WORK_SOFT_RUNNING; @@ -705,6 +708,7 @@ static int chrg_sink_work_current_wait(eIDX_SOU_CH idx, g_sink_unload_confirm_count[idx]++; if (g_sink_unload_confirm_count[idx] >= SINK_UNLOAD_CONFIRM_COUNT) { g_sink_unload_batch_confirmed[idx] = RT_FALSE; + g_sink_unload_current_confirmed[idx] = RT_TRUE; g_sink_unload_confirm_count[idx] = 0U; pSW->sink.work_mode = full_handshake ? SINK_WORK_WAIT : SINK_WORK_SOFT_RESUME_WAIT;