fix: 修复负载电流读取、继电器逻辑与状态机问题
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: 新增电流确认状态变量,优化批量寄存器配置与工作模式判断
This commit is contained in:
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user