refactor(chrg): 重构北向轮询与状态机代码,补充注释与函数文档
1. apps/chrg/applications/thread/chrg_roll_nor.c: 新增chrg_roll_nor_cmd、chrg_roll_nor_set函数注释,补充线程判断逻辑注释 2. apps/chrg/applications/thread/chrg_comm.c: 完善modbus写入寄存器的注释,补充角色切换逻辑说明 3. apps/chrg/applications/utils/chrg_source.c: 为所有电源状态机函数补充详细中文注释与函数说明 4. apps/chrg/applications/thread/chrg_north.c: 删除冗余全局变量与函数,补充帧处理、解析函数注释,修正初始化注释 5. apps/chrg/applications/utils/chrg_sink.c: 删除大量废弃测试代码,为所有负载状态机函数补充详细中文注释与函数说明
This commit is contained in:
@@ -1867,7 +1867,11 @@ static eMBException chrg_mb_write_sys(rt_uint8_t ch, rt_uint16_t reg_offset, rt_
|
||||
struct chrg_thread_t *pTHR_NOR = &chrgthr[IDX_THR_ROLL_NOR];
|
||||
rt_mutex_take(pTHR_NOR->mutex, RT_WAITING_FOREVER);
|
||||
|
||||
/* 保存复制前的真实角色,复制后据此判断是否需要先停后切。 */
|
||||
/*
|
||||
* pReal保存当前正在运行的真实状态,pSW指向COM影子配置。
|
||||
* 必须在rt_memcpy之前保存old_id,否则复制后会丢失旧角色,
|
||||
* 无法判断本次生效是普通参数更新还是Source/Sink角色切换。
|
||||
*/
|
||||
eIDX_ID old_id = pReal->id;
|
||||
|
||||
g_shadow_dirty[ch] = 0;
|
||||
@@ -1878,6 +1882,7 @@ static eMBException chrg_mb_write_sys(rt_uint8_t ch, rt_uint16_t reg_offset, rt_
|
||||
rt_uint16_t old_loadv = pReal->sink.loadv;
|
||||
rt_uint16_t old_loadc = pReal->sink.loadc;
|
||||
//rt_uint8_t old_sink_test = pReal->sink.test.test_mode;
|
||||
/* COM参数统一生效;复制完成后的id就是本次请求的目标角色。 */
|
||||
rt_memcpy(pReal, &g_shadow_sw[ch], sizeof(struct chrg_switch_t));
|
||||
eIDX_ID new_id = pReal->id;
|
||||
|
||||
@@ -1885,7 +1890,11 @@ static eMBException chrg_mb_write_sys(rt_uint8_t ch, rt_uint16_t reg_offset, rt_
|
||||
{
|
||||
int switch_ret;
|
||||
|
||||
/* 复制后按新角色选择状态机,保证id与work_mode归属一致。 */
|
||||
/*
|
||||
* SWITCH表示“切换进入new_id对应角色”,因此必须按new_id
|
||||
* 选择状态机,保证ID_SOURCE只使用Source状态机,ID_SINK
|
||||
* 只使用Sink状态机。SWITCH内部先停止旧角色,再转入INIT。
|
||||
*/
|
||||
if (new_id == ID_SOURCE) {
|
||||
pReal->source.work_mode = SOURCE_WORK_SWITCH;
|
||||
switch_ret = chrg_source_work_state(ch, pReal);
|
||||
@@ -1894,12 +1903,17 @@ static eMBException chrg_mb_write_sys(rt_uint8_t ch, rt_uint16_t reg_offset, rt_
|
||||
switch_ret = chrg_sink_work((eIDX_SOU_CH)ch, pReal);
|
||||
}
|
||||
|
||||
/* 入队失败时保留影子待生效标志,让COM返回忙并允许重试。 */
|
||||
if (switch_ret != 0) {
|
||||
g_shadow_dirty[ch] = 1;
|
||||
rt_mutex_release(pTHR_NOR->mutex);
|
||||
return MB_EX_SLAVE_BUSY;
|
||||
}
|
||||
|
||||
/*
|
||||
* 角色切换路径已经完成状态安排,必须直接返回,避免继续执行
|
||||
* 下方同角色启动/停止逻辑并再次覆盖INIT状态。
|
||||
*/
|
||||
rt_mutex_release(pTHR_NOR->mutex);
|
||||
return MB_EX_NONE;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user