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:
wrh
2026-07-22 10:05:47 +08:00
parent 660aaa5a7a
commit 684ad2e20e
11 changed files with 141 additions and 244 deletions
+6 -28
View File
@@ -51,13 +51,6 @@ void chrg_source_standard_output(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
pSW->source.Set_CV_Flag = 1;
pSW->change_flag = 0;
}
// if(pSW->source.Set_CV_Flag==0){
// chrg_set_sou_reg((eIDX_SOU_CH)idx, REG_CURRENT_OUT+1, pSW->source.max_vol);
//#if DEBUG_NORTH
// rt_kprintf("Curr_set%d\r\n",Curr_mA);
//#endif
// pSW->source.Set_CV_Flag = 0;
// }
}
//电源快充
@@ -78,20 +71,7 @@ void chrg_source_parse(rt_uint8_t *frame_data, eIDX_SOU_CH idx,
}
pSW->source.vc.set_voltage = volt_mv;
pSW->source.vc.set_current = Curr_mA;
// #if LCD_OPEN
// // rt_kprintf("volt_mv=%d,volt_mv_Now=%d,compare=%d\r\n",volt_mv,volt_mv_Now,volt_compare);
// if(volt_compare<5000){ //比较设定值与实际值差距,小于2V认为达成设定,允许屏幕开始变换
// number++;
// number = number%10;
// if(number == 9)
// {
// pSW->change_flag = 0;
// }
// }else { //没有达成设定,屏幕不允许变换
// pSW->change_flag = 0x01;
// }
// #endif
if (pSW->source.On_Flag && (volt_mv_Now > 2000)) {
if (pSW->source.On_Flag) {
if ((volt_mv == last_volt_mv[idx])) {
pSW->source.work_mode = SOURCE_WORK_WAIT;
} else {
@@ -145,8 +125,6 @@ void chrg_sink_parse(rt_uint8_t *frame_data, eIDX_SOU_CH idx,
if(pSW->sink.On_work == 1 && pSW->sink.test.test_mode == 0) {
if (volt_mv <= WORK_MIN_VOLT) { // 电压过低,禁止进入工作状态机
// volt_low[idx]++;
/* Treat low voltage as a fault only after voltage was once valid. */
if (volt_set_ok[idx] == 1) {
if (++volt_low[idx] >= 3) {
volt_set_ok[idx] = 0;
@@ -154,16 +132,13 @@ void chrg_sink_parse(rt_uint8_t *frame_data, eIDX_SOU_CH idx,
pSW->sink.work_mode = SINK_WORK_LOW;
}
}
// if(volt_low[idx]>=5) pSW->sink.work_on_step = SINK_WORK_LOW; // 复位工作状态机
}
else{ // 电压稳定时执行工作状态机(继电器/工作模式切换)
volt_low[idx] = 0;
volt_set_ok[idx] = 1;
pSW->change_flag = 0;
/* Avoid unsigned underflow when actual voltage is above target. */
if ((rt_uint32_t)volt_mv + 2000 >= pSW->sink.pro_loadv) {
pSW->sink.work_mode = SINK_WORK_RUNING;
/* Voltage is normal but current is still zero: retry from WAIT. */
if (pSW->Now_current <= 200) {
if (++no_curr[idx] >= 3) {
pSW->sink.work_mode = SINK_WORK_WAIT;
@@ -182,7 +157,6 @@ void chrg_sink_parse(rt_uint8_t *frame_data, eIDX_SOU_CH idx,
volt_low[idx] = 0;
no_curr[idx] = 0;
volt_set_ok[idx] = 0;
// pSW->sink.work_on_step = SINK_WORK_STOP; // 复位工作状态机
}
chrg_sink_work(idx,pSW);
}
@@ -212,7 +186,7 @@ static void chrg_north_handle_Seting_Volt(rt_uint8_t *frame_data, rt_uint16_t fr
struct chrg_north_t chrgnorth = {
.devname = DEV_NAME_NORTH, // 设备名
.tty = RT_NULL, // 串口句柄初始为空
.enable = {1, 0, 0, 0}, // 4个通道使能初始关闭
.enable = {0, 0, 0, 0}, // 4个通道使能初始关闭
.free_flag = 1,
// 通道1(IDX_NOR_CH1)初始化
.sw[IDX_NOR_CH1] = {
@@ -224,6 +198,7 @@ struct chrg_north_t chrgnorth = {
.source = { // 电源侧参数初始化
.On_Flag = 0, // 启动标志初始关闭
.Set_CV_Flag = 1, // 启停控制初始置1
.work_mode = SOURCE_WORK_WAIT,
}, // 关键:补充逗号分隔source和sink
.sink = {
.protocol = 0xFE,
@@ -241,6 +216,7 @@ struct chrg_north_t chrgnorth = {
.source = {
.On_Flag = 0,
.Set_CV_Flag = 1,
.work_mode = SOURCE_WORK_WAIT,
},
.sink = {
.protocol = 0xFE,
@@ -257,6 +233,7 @@ struct chrg_north_t chrgnorth = {
.source = {
.On_Flag = 0,
.Set_CV_Flag = 1,
.work_mode = SOURCE_WORK_WAIT,
},
.sink = {
.protocol = 0xFE,
@@ -273,6 +250,7 @@ struct chrg_north_t chrgnorth = {
.source = {
.On_Flag = 0,
.Set_CV_Flag = 1,
.work_mode = SOURCE_WORK_WAIT,
},
.sink = {
.protocol = 0xFE,