修复了频繁切换电源PD协议会卡死的问题

refactor(chrg): 重构Source协议切换流程,替换CC断开为复位命令

1. 修改apps/chrg/applications/thread/chrg_north.c:新增SRC_CMD_RESET命令的帧长度校验
2. 修改apps/chrg/applications/thread/chrg_comm.h:新增chrg_comm_source_protocol_ack函数声明
3. 修改apps/chrg/applications/thread/chrg_north.h:开启北向UART调试打印
4. 修改apps/chrg/applications/utils/chrg_source.h:新增SRC_CMD_RESET命令码和source_reset函数声明
5. 修改apps/chrg/applications/thread/chrg_roll_nor.h:替换CC断开相关状态为复位状态
6. 修改apps/chrg/applications/utils/chrg_source.c:实现source_reset函数,修复PD参数硬编码问题
7. 修改apps/chrg/applications/thread/chrg_comm.c:新增协议状态缓存,重构协议切换判断逻辑
8. 修改apps/chrg/applications/thread/chrg_roll_nor.c:移除CC断开相关的共享等待逻辑,更新命令处理流程
This commit is contained in:
wrh
2026-08-22 16:55:25 +08:00
parent de45a902fe
commit 72cf1b75fa
8 changed files with 70 additions and 102 deletions
+15 -3
View File
@@ -148,7 +148,7 @@ static int chrg_source_work_protocol_switch(eIDX_SOU_CH idx,
int ret;
if ((pSW->sub != IDX_SET_SOURCE_PD) &&
(pSW->sub != IDX_SET_SOURCE_CC_CLOSE)) {
(pSW->sub != IDX_SET_SOURCE_RESET)) {
return -1;
}
@@ -316,6 +316,18 @@ int source_get_pd (void)
return chrg_north_send(frame, len);
}
int source_reset (void)
{
rt_uint16_t len = 0;
rt_uint8_t data[8] = {0};
rt_uint8_t frame[16] = {0};
data[0] = 0x00;
chrg_north_pkg_encode(ID_SOURCE, SRC_CMD_RESET, data, 1, frame, &len);
return chrg_north_send(frame, len);
}
/*****************************************************************
函数名称: source_set_cc_lvl
函数描述: source 设置 cc 等级
@@ -1017,8 +1029,8 @@ rt_uint8_t pd_fill_single_group_no_src_com(rt_uint8_t *data, rt_uint8_t start_id
data[idx++] = 0x00;
data[idx++] = 0x00;
// 2. 最小电压(高+低,直接取已拆分好的值)
data[idx++] = mm->min_vol >> 8;
data[idx++] = mm->min_vol & 0xFF;
data[idx++] = 0x13;//mm->min_vol >> 8;
data[idx++] = 0x18;//mm->min_vol & 0xFF;
// 3. 最大电压(高+低,直接取已拆分好的值)
data[idx++] = mm->max_vol >> 8;
data[idx++] = mm->max_vol & 0xFF;
@@ -25,6 +25,8 @@ struct chrg_switch_t;
#define SRC_CMD_SET_CC_CHOOSE 0x17
#define SRC_CMD_RESET 0x18
#define SRC_CMD_SET_PROTOCOL 0xD0
#define PROTOCOL_NONE 0x00 // 无快充
@@ -192,6 +194,8 @@ extern int source_get_vc (rt_uint16_t vol, rt_uint16_t cur);
*****************************************************************/
extern int source_get_pd (void);
extern int source_reset (void);
/*****************************************************************
函数名称: source_set_cc_lvl
函数描述: source 设置 cc 等级