重构充电协议模块,统一源载参数管理与流程
1. apps/chrg/applications/utils/chrg_def.h: 移除vc_pd_t结构体中mm数组下标,改为单实例 2. apps/chrg/applications/utils/chrg_north_pkg.c: 修正CRC校验调用,调整pd_get参数访问方式 3. apps/chrg/applications/utils/chrg_source.h: 重构src_vc_t和chrg_src_t结构体,移除冗余字段,新增set_volt/set_curr和pd_set单实例 4. apps/chrg/applications/thread/chrg_roll_nor.c: 修正CC选择变量名,新增PD数据获取流程 5. apps/chrg/applications/thread/chrg_lcd.c: 重构LCD解析逻辑,区分源载电压处理,新增工作状态触发 6. apps/chrg/applications/thread/chrg_north.c: 新增协议电压规则修正函数,重构源参数控制逻辑 7. apps/chrg/applications/thread/chrg_comm.c: 新增pd_changed参数差异标志,重构源参数读写与差异比较逻辑 8. apps/chrg/applications/utils/chrg_source.c: 重构源工作状态机,新增电压补偿逻辑,重构PD协议填充函数 9. docs\2026-07-29-self-loop-aging-test-plan.md: 新增四通道自举老化测试计划文档
This commit is contained in:
@@ -57,7 +57,7 @@ static rt_uint8_t g_shadow_dirty[TOTAL_NOR_CHS] = {0}; /* 0=已生效 1=待生
|
||||
|
||||
/*
|
||||
* Source和Sink共用的参数差异结果。前五项是两个角色都具备的控制属性,
|
||||
* 后三项只用于Sink快充协议配置;Source比较时保持为RT_FALSE。
|
||||
* pd_changed用于Source完整协议参数比较,后三项用于Sink快充协议配置。
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
@@ -66,6 +66,7 @@ typedef struct
|
||||
rt_bool_t cv_changed;
|
||||
rt_bool_t voltage_changed;
|
||||
rt_bool_t current_changed;
|
||||
rt_bool_t pd_changed;
|
||||
rt_bool_t group_changed;
|
||||
rt_bool_t pro_voltage_changed;
|
||||
rt_bool_t pro_current_changed;
|
||||
@@ -872,22 +873,24 @@ static rt_uint16_t src_proto_lookup(rt_uint16_t reg_val)
|
||||
*****************************************************************/
|
||||
static rt_uint16_t src_type_lookup(rt_uint16_t reg_val,struct chrg_switch_t *pSW)
|
||||
{
|
||||
struct vc_pd_t *pPD = &pSW->source.pd_set;
|
||||
|
||||
switch(reg_val){
|
||||
case 0:
|
||||
pSW->source.src = 0;
|
||||
pSW->source.pps = 0;
|
||||
pPD->src_type = TYPE_SRC_PDO;
|
||||
pPD->pps_type = TYPE_PPS_SPRPPS;
|
||||
break;
|
||||
case 1:
|
||||
pSW->source.src = 0;
|
||||
pSW->source.pps = 1;
|
||||
pPD->src_type = TYPE_SRC_PDO;
|
||||
pPD->pps_type = TYPE_PPS_EPR;
|
||||
break;
|
||||
case 2:
|
||||
pSW->source.src = 3;
|
||||
pSW->source.pps = 0;
|
||||
pPD->src_type = TYPE_SRC_APDO;
|
||||
pPD->pps_type = TYPE_PPS_SPRPPS;
|
||||
break;
|
||||
case 3:
|
||||
pSW->source.src = 3;
|
||||
pSW->source.pps = 1;
|
||||
pPD->src_type = TYPE_SRC_APDO;
|
||||
pPD->pps_type = TYPE_PPS_EPR;
|
||||
break;
|
||||
default:
|
||||
return 1;
|
||||
@@ -1127,13 +1130,13 @@ eMBException funcWriteMultipleHoldingRegister (rt_uint8_t *reqFrame, rt_uint16_t
|
||||
switch (sout_reg)
|
||||
{
|
||||
case REG_VOLTAGE_OUT + 1:
|
||||
pSW->source.vc.set_voltage = sou_value;
|
||||
pSW->source.set_volt = sou_value;
|
||||
pSW->sink.loadv = sou_value;
|
||||
chrg_set_sou_reg(ch, sout_reg, sou_value);
|
||||
rt_kprintf("voltage=%d", sou_value);
|
||||
break;
|
||||
case REG_CURRENT_OUT + 1:
|
||||
pSW->source.vc.set_current = sou_value;
|
||||
pSW->source.set_curr = sou_value;
|
||||
pSW->sink.loadc = sou_value;
|
||||
chrg_set_sou_reg(ch, sout_reg, sou_value);
|
||||
break;
|
||||
@@ -2223,21 +2226,21 @@ static void chrg_mb_write_src(rt_uint8_t ch, rt_uint16_t reg_offset, rt_uint16_t
|
||||
// rt_kprintf("[SRC CH%d] Mode=%d\n", ch + 1, sou_value);
|
||||
break;
|
||||
case SRC_REG_MIN_VOLT: // 0x03: 最小电压 (mV)
|
||||
pSW->source.min_vol = sou_value;
|
||||
pSW->source.pd_set.mm.min_vol = sou_value;
|
||||
//rt_kprintf("[SRC CH%d] MinVolt=%d mV\n", ch + 1, sou_value);
|
||||
break;
|
||||
case SRC_REG_MAX_VOLT: // 0x04: 最大电压 (mV)
|
||||
pSW->source.vc.set_voltage = sou_value;
|
||||
pSW->source.pd_set.mm.max_vol = sou_value;
|
||||
// rt_kprintf("[SRC CH%d] MaxVolt=%d mV\n", ch + 1, sou_value);
|
||||
break;
|
||||
|
||||
case SRC_REG_MAX_CURR: // 0x05: 最大电流 (mA)
|
||||
pSW->source.vc.set_current = sou_value;
|
||||
pSW->source.pd_set.mm.max_cur = sou_value;
|
||||
//rt_kprintf("[SRC CH%d] MaxCurr=%d mA\n", ch + 1, sou_value);
|
||||
break;
|
||||
|
||||
case SRC_REG_CC_SEL: // 0x06: CC选择
|
||||
pSW->source.cc_set = (rt_uint8_t)sou_value;
|
||||
pSW->source.CC_Set = (rt_uint8_t)sou_value;
|
||||
//rt_kprintf("[SRC CH%d] CC_SEL=%d\n", ch + 1, sou_value);
|
||||
break;
|
||||
|
||||
@@ -2258,8 +2261,8 @@ static void chrg_mb_write_src(rt_uint8_t ch, rt_uint16_t reg_offset, rt_uint16_t
|
||||
输入参数: role:当前角色 pReal:正在运行的参数 pShadow:待生效参数
|
||||
输出参数: pDiff:各公共属性及Sink专用协议属性的变化标志
|
||||
返回说明: -
|
||||
其它说明: 本函数只计算差异,不修改状态、不发送命令;Source的电压电流
|
||||
使用vc.set_voltage/set_current,Sink使用loadv/loadc
|
||||
其它说明: 本函数只计算差异,不修改状态、不发送命令;Source直接比较
|
||||
完整pd_set,并从pd_set.mm提取标准协议电压电流差异
|
||||
*****************************************************************/
|
||||
static void chrg_comm_get_param_diff(eIDX_ID role,
|
||||
const struct chrg_switch_t *pReal,
|
||||
@@ -2276,11 +2279,16 @@ static void chrg_comm_get_param_diff(eIDX_ID role,
|
||||
pDiff->protocol_changed =
|
||||
(pReal->source.protocol != pShadow->source.protocol);
|
||||
pDiff->cc_changed =
|
||||
(pReal->source.cc_set != pShadow->source.cc_set);
|
||||
(pReal->source.CC_Set != pShadow->source.CC_Set);
|
||||
/* 两个数组均来自静态零初始化结构,填充前未定义字节保持为0。 */
|
||||
pDiff->pd_changed = (rt_memcmp(&pReal->source.pd_set,
|
||||
&pShadow->source.pd_set, sizeof(pReal->source.pd_set)) != 0);
|
||||
pDiff->voltage_changed =
|
||||
(pReal->source.vc.set_voltage != pShadow->source.vc.set_voltage);
|
||||
(pReal->source.pd_set.mm.max_vol !=
|
||||
pShadow->source.pd_set.mm.max_vol);
|
||||
pDiff->current_changed =
|
||||
(pReal->source.vc.set_current != pShadow->source.vc.set_current);
|
||||
(pReal->source.pd_set.mm.max_cur !=
|
||||
pShadow->source.pd_set.mm.max_cur);
|
||||
} else if (role == ID_SINK) {
|
||||
pDiff->protocol_changed =
|
||||
(pReal->sink.protocol != pShadow->sink.protocol);
|
||||
@@ -2373,26 +2381,50 @@ static eMBException chrg_comm_apply_sink_effect(rt_uint8_t ch,
|
||||
输入参数: ch:通道 pReal:运行参数 pShadow:待生效影子参数
|
||||
输出参数: 更新pReal、Source状态和必要的南向寄存器
|
||||
返回说明: MB_EX_NONE:成功 MB_EX_SLAVE_BUSY:命令提交失败
|
||||
其它说明: 快充协议只重置北向sub并进入WAIT;标准协议直接更新CV、电压和电流
|
||||
其它说明: 只复制Source配置字段,避免影子结构覆盖北向实时set_volt/set_curr;
|
||||
快充参数变化进入WAIT,标准协议电压统一交给RUNING状态下发
|
||||
*****************************************************************/
|
||||
static eMBException chrg_comm_apply_source_effect(rt_uint8_t ch,
|
||||
struct chrg_switch_t *pReal, const struct chrg_switch_t *pShadow)
|
||||
{
|
||||
chrg_param_diff_t diff_info;
|
||||
rt_bool_t north_config_changed;
|
||||
struct vc_pd_t old_pd_set;
|
||||
eSRC_PRO old_protocol = pReal->source.protocol;
|
||||
rt_uint8_t old_cc_set = pReal->source.CC_Set;
|
||||
rt_uint8_t old_now_state = pReal->source.Now_State;
|
||||
rt_uint8_t old_work_mode = pReal->source.work_mode;
|
||||
rt_uint8_t old_cv_mode = pReal->CV_mode;
|
||||
rt_uint16_t old_voltage = pReal->source.vc.set_voltage;
|
||||
rt_uint16_t old_current = pReal->source.vc.set_current;
|
||||
rt_uint8_t old_proto_cmd = pReal->protoCmd;
|
||||
rt_uint8_t old_sub = pReal->sub;
|
||||
rt_uint16_t old_set_volt = pReal->source.set_volt;
|
||||
rt_uint16_t old_set_curr = pReal->source.set_curr;
|
||||
rt_uint16_t source_work = pShadow->source.Now_State;
|
||||
rt_uint16_t regs[3];
|
||||
rt_uint16_t vals[3];
|
||||
rt_uint16_t regs[2];
|
||||
rt_uint16_t vals[2];
|
||||
rt_uint16_t clear_reg;
|
||||
rt_uint16_t clear_val;
|
||||
rt_uint16_t target_curr;
|
||||
rt_uint8_t count = 0;
|
||||
|
||||
chrg_comm_get_param_diff(ID_SOURCE, pReal, pShadow, &diff_info);
|
||||
rt_memcpy(pReal, pShadow, sizeof(struct chrg_switch_t));
|
||||
rt_memcpy(&old_pd_set, &pReal->source.pd_set, sizeof(old_pd_set));
|
||||
north_config_changed = diff_info.protocol_changed ||
|
||||
diff_info.cc_changed || diff_info.pd_changed;
|
||||
target_curr = pShadow->source.pd_set.mm.max_cur;
|
||||
|
||||
/* 影子区只拥有COM配置;北向解析产生的运行目标和回读数据继续由pReal持有。 */
|
||||
pReal->CV_mode = pShadow->CV_mode;
|
||||
pReal->protoCmd = pShadow->protoCmd;
|
||||
pReal->source.protocol = pShadow->source.protocol;
|
||||
pReal->source.CC_Set = pShadow->source.CC_Set;
|
||||
pReal->source.Now_State = pShadow->source.Now_State;
|
||||
rt_memcpy(&pReal->source.pd_set, &pShadow->source.pd_set,
|
||||
sizeof(pReal->source.pd_set));
|
||||
|
||||
if (source_work == 0x01) {
|
||||
if (pReal->source.On_Flag == 0) {
|
||||
/* 首次启动仍需初始化功率板、继电器和WORK_START。 */
|
||||
/* 新命令要求运行时直接置位,不依赖旧工作状态。 */
|
||||
pReal->sub = IDX_SET_SOURCE_CC_SET;
|
||||
pReal->source.On_Flag = 1;
|
||||
pReal->source.work_mode = SOURCE_WORK_INIT;
|
||||
@@ -2400,40 +2432,48 @@ static eMBException chrg_comm_apply_source_effect(rt_uint8_t ch,
|
||||
MB_EX_NONE : MB_EX_SLAVE_BUSY;
|
||||
}
|
||||
|
||||
/* 协议或CC变化时,从CC设置开始重新执行北向配置链路。 */
|
||||
if (diff_info.protocol_changed || diff_info.cc_changed) {
|
||||
/* 协议、CC或任一pd_set字段变化时,重新执行北向配置链路。 */
|
||||
if (north_config_changed) {
|
||||
pReal->sub = IDX_SET_SOURCE_CC_SET;
|
||||
}
|
||||
|
||||
pReal->source.work_mode = SOURCE_WORK_WAIT;
|
||||
if (diff_info.protocol_changed || diff_info.cc_changed) {
|
||||
/* 协议或CC切换前先清零南向输出,帮助功率板退出旧协议状态,
|
||||
* 后续北向轮询再按CC、协议、VC顺序完成新协议握手。 */
|
||||
clear_reg = REG_VOLTAGE_OUT + 1;
|
||||
clear_val = 0;
|
||||
if (chrg_sou_com_batch_submit((eIDX_SOU_CH)ch,
|
||||
&clear_reg, &clear_val, 1) != 0) {
|
||||
goto source_effect_submit_failed;
|
||||
}
|
||||
pReal->source.set_volt = 0;
|
||||
}
|
||||
|
||||
if (pReal->source.protocol != PRO_NONE) {
|
||||
/* 快充目标值由北向协商回码决定,COM生效阶段不直接写功率板。 */
|
||||
/* 快充只更新协议配置并等待协商回码,不直接改功率板输出。 */
|
||||
return MB_EX_NONE;
|
||||
}
|
||||
|
||||
/* 从快充切到标准协议时强制同步全部直接控制参数。 */
|
||||
/* 标准协议的模式和电流可直接提交,电压只能由RUNING状态写入。 */
|
||||
if (diff_info.protocol_changed || diff_info.cv_changed) {
|
||||
regs[count] = REG_MODE;
|
||||
vals[count++] = pReal->CV_mode;
|
||||
}
|
||||
if (diff_info.protocol_changed || diff_info.voltage_changed) {
|
||||
regs[count] = REG_VOLTAGE_OUT + 1;
|
||||
vals[count++] = pReal->source.vc.set_voltage;
|
||||
}
|
||||
if (diff_info.protocol_changed || diff_info.current_changed) {
|
||||
regs[count] = REG_CURRENT_OUT + 1;
|
||||
vals[count++] = pReal->source.vc.set_current;
|
||||
vals[count++] = target_curr;
|
||||
}
|
||||
|
||||
if ((count > 0) && (chrg_sou_com_batch_submit((eIDX_SOU_CH)ch,
|
||||
regs, vals, count) != 0)) {
|
||||
pReal->CV_mode = old_cv_mode;
|
||||
pReal->source.vc.set_voltage = old_voltage;
|
||||
pReal->source.vc.set_current = old_current;
|
||||
return MB_EX_SLAVE_BUSY;
|
||||
goto source_effect_submit_failed;
|
||||
}
|
||||
pReal->source.work_mode = SOURCE_WORK_RUNING;
|
||||
|
||||
/* COM只更新标准协议配置并保持WAIT;下一帧北向解析负责比较
|
||||
* pd_set目标与set_volt,再决定是否进入RUNING写电压。 */
|
||||
pReal->source.set_curr = target_curr;
|
||||
pReal->source.work_mode = SOURCE_WORK_WAIT;
|
||||
return MB_EX_NONE;
|
||||
}
|
||||
|
||||
@@ -2441,6 +2481,21 @@ static eMBException chrg_comm_apply_source_effect(rt_uint8_t ch,
|
||||
pReal->source.work_mode = SOURCE_WORK_STOP;
|
||||
return (chrg_source_work_state(ch, pReal) == 0) ?
|
||||
MB_EX_NONE : MB_EX_SLAVE_BUSY;
|
||||
|
||||
source_effect_submit_failed:
|
||||
/* 南向命令提交失败必须恢复差异基准,保证下一次PARAM_EFFECT仍会重发。 */
|
||||
pReal->CV_mode = old_cv_mode;
|
||||
pReal->protoCmd = old_proto_cmd;
|
||||
pReal->sub = old_sub;
|
||||
pReal->source.protocol = old_protocol;
|
||||
pReal->source.CC_Set = old_cc_set;
|
||||
pReal->source.Now_State = old_now_state;
|
||||
pReal->source.work_mode = old_work_mode;
|
||||
pReal->source.set_volt = old_set_volt;
|
||||
pReal->source.set_curr = old_set_curr;
|
||||
rt_memcpy(&pReal->source.pd_set, &old_pd_set,
|
||||
sizeof(pReal->source.pd_set));
|
||||
return MB_EX_SLAVE_BUSY;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
|
||||
Reference in New Issue
Block a user