feat: 新增电源/负载切换功能,优化通道切换逻辑
1. 新增SINK_WORK_SWITCH和SOURCE_WORK_SWITCH状态,实现切换流程 2. 实现chrg_sink_work_switch和chrg_source_work_switch切换处理函数 3. 修改Keil工程ROM起始地址为0x8000000 4. 开启north线程调试输出,调整初始通道使能状态 5. 简化串口包编码调试打印,优化source初始化寄存器配置 6. 重构modbus通道切换逻辑,支持活跃状态下的角色切换 7. 清理部分冗余调试代码和注释 8. 重构bootloader代码,简化启动流程
This commit is contained in:
@@ -42,13 +42,8 @@ int chrg_north_pkg_encode (eIDX_ID id, rt_uint8_t cmd, rt_uint8_t *data_in,
|
||||
rt_memcpy(&data_out[4], data_in, len_in);
|
||||
}
|
||||
data_out[len_in+4] = 0x2a;//calc_crc8(data_out, len_in+4);
|
||||
// rt_kprintf("pro_data= \n");
|
||||
*len_out = 5+len_in;
|
||||
// for(int i = 0; i < *len_out;i++)
|
||||
// {
|
||||
// rt_kprintf("%02x ",data_out[i]);
|
||||
// }
|
||||
// rt_kprintf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -523,6 +523,24 @@ static int chrg_sink_nor_work_off(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 切换进入负载:停止旧电源后,从负载初始化状态开始运行
|
||||
static int chrg_sink_work_switch(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
||||
{
|
||||
rt_uint16_t reg = REG_WORK;
|
||||
rt_uint16_t value = WORK_STOP;
|
||||
int ret;
|
||||
|
||||
ret = chrg_sou_com_batch_submit(idx, ®, &value, 1);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
pSW->source.On_Flag = 0;
|
||||
pSW->sub = IDX_SET_SINK_CCLINE;
|
||||
pSW->sink.work_mode = SINK_WORK_INIT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
//动态测试启动
|
||||
static int chrg_sink_TEST_DYNA_ON(rt_uint8_t ch, struct chrg_switch_t *pSW)
|
||||
{
|
||||
@@ -598,6 +616,9 @@ int chrg_sink_work(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
||||
case SINK_WORK_STOP:
|
||||
ret = chrg_sink_nor_work_off(idx,pSW);
|
||||
break;
|
||||
case SINK_WORK_SWITCH:
|
||||
ret = chrg_sink_work_switch(idx,pSW);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -208,6 +208,7 @@ enum {
|
||||
SINK_WORK_RUNING,
|
||||
SINK_WORK_LOW,
|
||||
SINK_WORK_STOP,
|
||||
SINK_WORK_SWITCH, // 停止旧电源后进入负载INIT
|
||||
SINK_WORK_ON_TEST_DYNA,
|
||||
SINK_WORK_ON_TEST_SHORT,
|
||||
};
|
||||
|
||||
@@ -20,17 +20,19 @@
|
||||
int chrg_source_init_submit(rt_uint8_t idx, struct chrg_switch_t *pSW)
|
||||
{
|
||||
/* Source启动参数一次入队,最后发送WORK_START使功率板开始输出。 */
|
||||
rt_uint16_t regs[5] = {
|
||||
rt_uint16_t regs[6] = {
|
||||
REG_ELOAD,
|
||||
REG_MODE,
|
||||
0x01,
|
||||
REG_VOLTAGE_OUT + 1,
|
||||
REG_CURRENT_OUT + 1,
|
||||
REG_WORK
|
||||
};
|
||||
rt_uint16_t vals[5] = {
|
||||
rt_uint16_t vals[6] = {
|
||||
ELOAD_SOURCE,
|
||||
pSW->CV_mode,
|
||||
pSW->source.max_vol,
|
||||
0x03,
|
||||
0,
|
||||
pSW->source.protective_curr,
|
||||
WORK_START
|
||||
};
|
||||
@@ -38,7 +40,7 @@ int chrg_source_init_submit(rt_uint8_t idx, struct chrg_switch_t *pSW)
|
||||
if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL)) {
|
||||
return -1;
|
||||
}
|
||||
return chrg_sou_com_batch_submit(idx, regs, vals, 5);
|
||||
return chrg_sou_com_batch_submit(idx, regs, vals, 6);
|
||||
}
|
||||
|
||||
static int chrg_source_work_init(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
||||
@@ -55,7 +57,7 @@ static int chrg_source_work_init(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
||||
|
||||
pSW->source.On_Flag = 1;
|
||||
pSOU->enable[idx] = 1;
|
||||
pNOR->enable[idx] = 1;
|
||||
pNOR->enable[idx] = 1;
|
||||
pSOU->online[idx] = 1;
|
||||
chrg_nor_sw_rel((eIDX_NOR_CH)idx, ID_SOURCE);
|
||||
pSW->source.work_mode = SOURCE_WORK_WAIT;
|
||||
@@ -110,6 +112,24 @@ static int chrg_source_work_stop(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 切换进入电源:关闭旧负载继电器并停止输出,然后进入电源初始化
|
||||
static int chrg_source_work_switch(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
||||
{
|
||||
rt_uint16_t regs[2] = {REG_REL_ON, REG_WORK};
|
||||
rt_uint16_t vals[2] = {ALL_REL_OFF, WORK_STOP};
|
||||
int ret;
|
||||
|
||||
ret = chrg_sou_com_batch_submit(idx, regs, vals, 2);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
pSW->sink.On_work = 0;
|
||||
pSW->sub = IDX_SET_SOURCE_CC_SET;
|
||||
pSW->source.work_mode = SOURCE_WORK_INIT;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int chrg_source_work_state(rt_uint8_t idx, struct chrg_switch_t *pSW)
|
||||
{
|
||||
if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL)) {
|
||||
@@ -128,6 +148,8 @@ int chrg_source_work_state(rt_uint8_t idx, struct chrg_switch_t *pSW)
|
||||
return chrg_source_work_low(idx, pSW);
|
||||
case SOURCE_WORK_STOP:
|
||||
return chrg_source_work_stop(idx, pSW);
|
||||
case SOURCE_WORK_SWITCH:
|
||||
return chrg_source_work_switch(idx, pSW);
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -174,6 +174,7 @@ enum {
|
||||
SOURCE_WORK_RUNING, // 协商电压变化,下发一次新电压
|
||||
SOURCE_WORK_LOW, // 电压过低,停止功率板输出
|
||||
SOURCE_WORK_STOP, // 主动停止并关闭通道
|
||||
SOURCE_WORK_SWITCH, // 停止旧负载后进入电源INIT
|
||||
SOURCE_WORK_ON_TEST_DYNA,
|
||||
SOURCE_WORK_ON_TEST_SHORT,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user