chore: 整理代码并更新文档
1. 新增并替换通信协议文档,删除旧版V2.0协议文档 2. 重构充电源逻辑,移除Set_CV_Flag相关变量和代码 3. 优化充电源关闭流程,修正寄存器配置逻辑 4. 完善Modbus输入寄存器回调和功能码处理逻辑 5. 调整输入寄存器映射表,简化寄存器定义 6. 为USB设备队列内存添加对齐宏定义 7. 新增南向电源Modbus寄存器头文档
This commit is contained in:
@@ -221,6 +221,16 @@ static eMBException mb_error (eMBErrorCode eErrorCode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//extern eMBErrorCode Modbus_Protocal_Set(rt_uint16_t Role_value,rt_uint16_t src,rt_uint16_t pps,rt_uint16_t pro_value,rt_uint16_t volt_value,rt_uint16_t curr_value);
|
//extern eMBErrorCode Modbus_Protocal_Set(rt_uint16_t Role_value,rt_uint16_t src,rt_uint16_t pps,rt_uint16_t pro_value,rt_uint16_t volt_value,rt_uint16_t curr_value);
|
||||||
|
/*****************************************************************
|
||||||
|
函数名称: mb_reg_input_cb
|
||||||
|
函数描述: Modbus输入寄存器读取回调函数
|
||||||
|
输入参数: pucRegBuffer:输入寄存器返回数据缓冲区
|
||||||
|
usAddress:输入寄存器起始地址
|
||||||
|
usNRegs:需要读取的输入寄存器数量
|
||||||
|
输出参数: pucRegBuffer:按Modbus高字节在前格式填充寄存器数据
|
||||||
|
返回说明: MB_ENOERR:读取成功 MB_ENOREG:地址范围错误
|
||||||
|
其它说明: 只读usRegInBuf,不处理写操作;每个输入寄存器转换为两个字节
|
||||||
|
*****************************************************************/
|
||||||
eMBErrorCode mb_reg_input_cb (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress, rt_uint16_t usNRegs)
|
eMBErrorCode mb_reg_input_cb (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress, rt_uint16_t usNRegs)
|
||||||
{
|
{
|
||||||
eMBErrorCode eStatus = MB_ENOERR;
|
eMBErrorCode eStatus = MB_ENOERR;
|
||||||
@@ -566,11 +576,12 @@ eMBException funcReadHoldingRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
|||||||
|
|
||||||
/*****************************************************************
|
/*****************************************************************
|
||||||
函数名称: funcReadInputRegister
|
函数名称: funcReadInputRegister
|
||||||
函数描述: 读输入寄存器
|
函数描述: 处理Modbus功能码0x04,读取输入寄存器
|
||||||
输入参数: reqFrame: 请求数据 reqLen: 请求长度 resFrame:响应数据 resLen:响应长度
|
输入参数: reqFrame: 请求数据 reqLen: 请求长度 resFrame:响应数据 resLen:响应长度
|
||||||
输出参数: -
|
输出参数: resFrame:输入寄存器响应帧 resLen:响应帧长度
|
||||||
返回说明: -
|
返回说明: MB_EX_NONE:读取成功 其他:Modbus异常码
|
||||||
其它说明: -
|
其它说明: 请求地址和数量校验方式与功能码0x03保持一致;输入寄存器
|
||||||
|
数据从usRegInBuf读取,响应数据按高字节在前返回
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
eMBException funcReadInputRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
eMBException funcReadInputRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||||
rt_uint8_t *resFrame, rt_uint16_t *resLen)
|
rt_uint8_t *resFrame, rt_uint16_t *resLen)
|
||||||
@@ -594,13 +605,14 @@ eMBException funcReadInputRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
|||||||
resFrame[1] = MB_READ_INPUT_REGISTER;
|
resFrame[1] = MB_READ_INPUT_REGISTER;
|
||||||
resFrame[2] = cntReg * 2;
|
resFrame[2] = cntReg * 2;
|
||||||
|
|
||||||
eRegStatus = mb_reg_discrete_cb(&resFrame[3], regAddress, cntReg);
|
eRegStatus = mb_reg_input_cb(&resFrame[3], regAddress, cntReg);
|
||||||
if (eRegStatus != MB_ENOERR) {
|
if (eRegStatus != MB_ENOERR) {
|
||||||
eStatus = mb_error(eRegStatus);
|
eStatus = mb_error(eRegStatus);
|
||||||
} else {
|
} else {
|
||||||
*resLen = 3+cntReg*2;
|
*resLen = 3+cntReg*2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
rt_kprintf("------COM READ INPUT addr=%d count=%d-------\n", regAddress, cntReg);
|
||||||
return eStatus;
|
return eStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -801,6 +813,7 @@ typedef struct {
|
|||||||
} SrcProtoMap_t;
|
} SrcProtoMap_t;
|
||||||
|
|
||||||
static const SrcProtoMap_t src_proto_map[] = {
|
static const SrcProtoMap_t src_proto_map[] = {
|
||||||
|
{0x20, PRO_NONE}, // 标准协议(无快充)
|
||||||
{0x2A, PRO_PD0PSS}, // PD
|
{0x2A, PRO_PD0PSS}, // PD
|
||||||
{0x22, PRO_FCP}, // FCP
|
{0x22, PRO_FCP}, // FCP
|
||||||
{0x23, PRO_SCPB}, // SCPB
|
{0x23, PRO_SCPB}, // SCPB
|
||||||
|
|||||||
@@ -28,100 +28,133 @@
|
|||||||
#define SOURCE_VOLT_RETRY_FRAMES 3U
|
#define SOURCE_VOLT_RETRY_FRAMES 3U
|
||||||
|
|
||||||
/*****************************************************************
|
/*****************************************************************
|
||||||
函数名称: chrg_source_standard_output
|
函数名称: chrg_source_voltage_control
|
||||||
功能描述: 南向功率源标准输出控制函数
|
函数描述: 统一处理Source目标电压、误差判断和状态机切换
|
||||||
函数描述: 根据CV标志位,分别设置电源输出电压或输出电流,实现标准模式下的恒压/恒流输出
|
输入参数: idx:当前通道 pSW:通道控制结构体 volt_mv:目标电压(mV)
|
||||||
输入参数:
|
curr_ma:目标电流(mA)
|
||||||
idx :功率通道编号
|
输出参数: 更新source.vc及source.work_mode
|
||||||
pSW :北向通道控制结构体指针,包含电压/电流设定值、CV控制标志等参数
|
返回说明: 0:状态处理成功 <0:参数错误或命令提交失败
|
||||||
输出参数:
|
其它说明: 目标电压变化时立即进入RUNING;实际电压与目标值的绝对误差
|
||||||
pSW :更新CV控制标志位
|
小于等于200mV时进入WAIT;连续3次超过误差范围时重发
|
||||||
返回说明: 无返回值
|
|
||||||
*****************************************************************/
|
*****************************************************************/
|
||||||
void chrg_source_standard_output(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
static int chrg_source_voltage_control(eIDX_SOU_CH idx,
|
||||||
|
struct chrg_switch_t *pSW,
|
||||||
|
rt_uint16_t volt_mv,
|
||||||
|
rt_uint16_t curr_ma)
|
||||||
{
|
{
|
||||||
if(pSW->source.Set_CV_Flag) {
|
|
||||||
chrg_set_sou_reg((eIDX_SOU_CH)idx, REG_VOLTAGE_OUT+1, pSW->source.max_vol);
|
|
||||||
#if DEBUG_NORTH
|
|
||||||
rt_kprintf("Volt_Set%d\r\n",pSW->source.vc.set_voltage);
|
|
||||||
#endif
|
|
||||||
pSW->source.Set_CV_Flag = 1;
|
|
||||||
pSW->change_flag = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*****************************************************************
|
|
||||||
函数名称: chrg_source_parse
|
|
||||||
函数描述: 解析北向电源板电压电流回码并驱动Source状态机
|
|
||||||
输入参数: frame_data:完整北向回码 idx:当前通道 pSW:通道控制结构体
|
|
||||||
pNOR:北向总控结构体
|
|
||||||
输出参数: 更新电压、电流、source.work_mode及电压重试计数
|
|
||||||
返回说明: -
|
|
||||||
其它说明: frame_data[4~7]为实测值,[8~11]为协议协商目标值;
|
|
||||||
新目标立即进入RUNING;实际误差连续3帧超过200mV时重发
|
|
||||||
*****************************************************************/
|
|
||||||
void chrg_source_parse(rt_uint8_t *frame_data, eIDX_SOU_CH idx,
|
|
||||||
struct chrg_switch_t *pSW, struct chrg_north_t *pNOR)
|
|
||||||
{
|
|
||||||
rt_uint16_t volt_mv;
|
|
||||||
rt_uint16_t curr_ma;
|
|
||||||
rt_uint16_t volt_error;
|
rt_uint16_t volt_error;
|
||||||
static rt_uint16_t last_volt_mv[TOTAL_SOU_CHS] = {0};
|
static rt_uint16_t last_volt_mv[TOTAL_SOU_CHS] = {0};
|
||||||
static rt_uint8_t last_volt_valid[TOTAL_SOU_CHS] = {0};
|
static rt_uint8_t last_volt_valid[TOTAL_SOU_CHS] = {0};
|
||||||
|
static rt_uint8_t last_protocol[TOTAL_SOU_CHS] = {0};
|
||||||
static rt_uint8_t volt_retry_count[TOTAL_SOU_CHS] = {0};
|
static rt_uint8_t volt_retry_count[TOTAL_SOU_CHS] = {0};
|
||||||
rt_bool_t need_set = RT_FALSE;
|
rt_bool_t need_set = RT_FALSE;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL) ||
|
if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL)) {
|
||||||
(frame_data == RT_NULL)) {
|
return -1;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
volt_mv = (frame_data[8] << 8) | frame_data[9];
|
|
||||||
curr_ma = (frame_data[10] << 8) | frame_data[11];
|
/* 保存本次目标值,RUNING状态只使用其中的目标电压下发命令。 */
|
||||||
/* 保存北向协议板返回的实测值和协商目标值。 */
|
|
||||||
pSW->source.vc.set_voltage = volt_mv;
|
pSW->source.vc.set_voltage = volt_mv;
|
||||||
pSW->source.vc.set_current = curr_ma;
|
pSW->source.vc.set_current = curr_ma;
|
||||||
|
|
||||||
if (!pSW->source.On_Flag) {
|
if (!pSW->source.On_Flag) {
|
||||||
/* 关机后清除历史值,确保下次启动至少下发一次目标电压。 */
|
/* 关机后清除历史缓存,下一次启动必须重新设置目标电压。 */
|
||||||
last_volt_valid[idx] = 0;
|
last_volt_valid[idx] = 0;
|
||||||
volt_retry_count[idx] = 0;
|
volt_retry_count[idx] = 0;
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 使用绝对误差,避免无符号减法在实际电压较小时发生下溢。 */
|
/* 使用绝对误差,避免实际电压低于目标值时发生无符号下溢。 */
|
||||||
volt_error = (pSW->Now_voltage >= volt_mv) ?
|
volt_error = (pSW->Now_voltage >= volt_mv) ?
|
||||||
(pSW->Now_voltage - volt_mv) :
|
(pSW->Now_voltage - volt_mv) :
|
||||||
(volt_mv - pSW->Now_voltage);
|
(volt_mv - pSW->Now_voltage);
|
||||||
|
|
||||||
if (!last_volt_valid[idx] || (volt_mv != last_volt_mv[idx])) {
|
if (!last_volt_valid[idx] ||
|
||||||
/* 首次设置或目标变化,立即进入RUNING下发新电压。 */
|
(last_protocol[idx] != (rt_uint8_t)pSW->source.protocol) ||
|
||||||
|
(volt_mv != last_volt_mv[idx])) {
|
||||||
|
/* 首次设置、协议切换或目标变化时立即下发新电压。 */
|
||||||
need_set = RT_TRUE;
|
need_set = RT_TRUE;
|
||||||
} else if (volt_error <= SOURCE_VOLT_ERROR_MV) {
|
} else if (volt_error <= SOURCE_VOLT_ERROR_MV) {
|
||||||
/* 实际电压已进入允许范围,清除连续失败计数。 */
|
/* 实际电压误差不超过200mV即可视为设置成功。 */
|
||||||
volt_retry_count[idx] = 0;
|
volt_retry_count[idx] = 0;
|
||||||
} else {
|
} else {
|
||||||
/* 给功率板三个反馈周期的稳定时间,避免每帧重复写电压。 */
|
/* 给功率板三个反馈周期的稳定时间,避免每帧重复写电压。 */
|
||||||
if (volt_retry_count[idx] < SOURCE_VOLT_RETRY_FRAMES) {
|
if (volt_retry_count[idx] < SOURCE_VOLT_RETRY_FRAMES) {
|
||||||
volt_retry_count[idx]++;
|
volt_retry_count[idx]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (volt_retry_count[idx] >= SOURCE_VOLT_RETRY_FRAMES) {
|
if (volt_retry_count[idx] >= SOURCE_VOLT_RETRY_FRAMES) {
|
||||||
need_set = RT_TRUE;
|
need_set = RT_TRUE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 解析函数只决定状态,具体寄存器操作仍由Source状态机执行。 */
|
|
||||||
pSW->source.work_mode = need_set ?
|
pSW->source.work_mode = need_set ?
|
||||||
SOURCE_WORK_RUNING : SOURCE_WORK_WAIT;
|
SOURCE_WORK_RUNING : SOURCE_WORK_WAIT;
|
||||||
|
|
||||||
ret = chrg_source_work_state(idx, pSW);
|
ret = chrg_source_work_state(idx, pSW);
|
||||||
if ((ret == 0) && need_set) {
|
if ((ret == 0) && need_set) {
|
||||||
/* 成功入队后更新缓存;重发成功后重新开始计算连续超差帧数。 */
|
/* 只有命令成功提交后才更新缓存,失败时下一次继续重试。 */
|
||||||
last_volt_mv[idx] = volt_mv;
|
last_volt_mv[idx] = volt_mv;
|
||||||
|
last_protocol[idx] = (rt_uint8_t)pSW->source.protocol;
|
||||||
last_volt_valid[idx] = 1;
|
last_volt_valid[idx] = 1;
|
||||||
volt_retry_count[idx] = 0;
|
volt_retry_count[idx] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************
|
||||||
|
函数名称: chrg_source_standard_output
|
||||||
|
函数描述: 使用COM配置值驱动标准协议电源输出
|
||||||
|
输入参数: idx:当前通道 pSW:通道控制结构体
|
||||||
|
输出参数: 更新source.vc及source.work_mode
|
||||||
|
返回说明: 无返回值
|
||||||
|
其它说明: 外部协议值0x20映射为PRO_NONE;本函数不解析北向协议返回
|
||||||
|
数据,目标电压和保护电流直接使用COM配置值
|
||||||
|
*****************************************************************/
|
||||||
|
void chrg_source_standard_output(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
||||||
|
{
|
||||||
|
if (pSW == RT_NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
(void)chrg_source_voltage_control(idx, pSW,
|
||||||
|
pSW->source.max_vol, pSW->source.protective_curr);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*****************************************************************
|
||||||
|
函数名称: chrg_source_parse
|
||||||
|
函数描述: 按电源协议类型处理目标电压并驱动Source状态机
|
||||||
|
输入参数: frame_data:完整北向回码 idx:当前通道 pSW:通道控制结构体
|
||||||
|
pNOR:北向总控结构体
|
||||||
|
输出参数: 更新电压、电流、source.work_mode及电压重试计数
|
||||||
|
返回说明: -
|
||||||
|
其它说明: 标准协议不解析frame_data,直接使用COM配置值;快充协议读取
|
||||||
|
frame_data[8~11]中的协商目标值。新目标立即进入RUNING,
|
||||||
|
实际误差连续3帧超过200mV时重发
|
||||||
|
*****************************************************************/
|
||||||
|
void chrg_source_parse(rt_uint8_t *frame_data, eIDX_SOU_CH idx,
|
||||||
|
struct chrg_switch_t *pSW, struct chrg_north_t *pNOR)
|
||||||
|
{
|
||||||
|
rt_uint16_t volt_mv;
|
||||||
|
rt_uint16_t curr_ma;
|
||||||
|
|
||||||
|
if ((idx >= TOTAL_SOU_CHS) || (pSW == RT_NULL)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* 标准协议使用COM设定值,不读取北向协议返回帧。 */
|
||||||
|
if (pSW->source.protocol == PRO_NONE) {
|
||||||
|
chrg_source_standard_output(idx, pSW);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (frame_data == RT_NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
volt_mv = (frame_data[8] << 8) | frame_data[9];
|
||||||
|
curr_ma = (frame_data[10] << 8) | frame_data[11];
|
||||||
|
/* 快充只负责解析北向协商结果,后续控制逻辑与标准协议共用。 */
|
||||||
|
(void)chrg_source_voltage_control(idx, pSW, volt_mv, curr_ma);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*****************************************************************
|
/*****************************************************************
|
||||||
@@ -138,7 +171,7 @@ void chrg_source_setting(rt_uint8_t *frame_data, eIDX_SOU_CH idx,
|
|||||||
{
|
{
|
||||||
//执行输出调整
|
//执行输出调整
|
||||||
if (pSW->source.On_Flag == 1) {
|
if (pSW->source.On_Flag == 1) {
|
||||||
if(pSW->source.protocol==0x00){//标准下输出设定值
|
if(pSW->source.protocol == PRO_NONE){//标准下输出设定值
|
||||||
chrg_source_standard_output(idx, pSW);
|
chrg_source_standard_output(idx, pSW);
|
||||||
}
|
}
|
||||||
else{ //快充部分按协商结果输出
|
else{ //快充部分按协商结果输出
|
||||||
@@ -258,7 +291,6 @@ struct chrg_north_t chrgnorth = {
|
|||||||
.id = ID_SINK, // 初始为负载模式
|
.id = ID_SINK, // 初始为负载模式
|
||||||
.source = { // 电源侧参数初始化
|
.source = { // 电源侧参数初始化
|
||||||
.On_Flag = 0, // 启动标志初始关闭
|
.On_Flag = 0, // 启动标志初始关闭
|
||||||
.Set_CV_Flag = 1, // 启停控制初始置1
|
|
||||||
.work_mode = SOURCE_WORK_WAIT, // 上电保持等待,禁止自动执行Source INIT
|
.work_mode = SOURCE_WORK_WAIT, // 上电保持等待,禁止自动执行Source INIT
|
||||||
}, // 关键:补充逗号分隔source和sink
|
}, // 关键:补充逗号分隔source和sink
|
||||||
.sink = {
|
.sink = {
|
||||||
@@ -276,7 +308,6 @@ struct chrg_north_t chrgnorth = {
|
|||||||
.change_flag = 0,
|
.change_flag = 0,
|
||||||
.source = {
|
.source = {
|
||||||
.On_Flag = 0,
|
.On_Flag = 0,
|
||||||
.Set_CV_Flag = 1,
|
|
||||||
.work_mode = SOURCE_WORK_WAIT, // 上电保持等待,禁止自动执行Source INIT
|
.work_mode = SOURCE_WORK_WAIT, // 上电保持等待,禁止自动执行Source INIT
|
||||||
},
|
},
|
||||||
.sink = {
|
.sink = {
|
||||||
@@ -293,7 +324,6 @@ struct chrg_north_t chrgnorth = {
|
|||||||
.change_flag = 0,
|
.change_flag = 0,
|
||||||
.source = {
|
.source = {
|
||||||
.On_Flag = 0,
|
.On_Flag = 0,
|
||||||
.Set_CV_Flag = 1,
|
|
||||||
.work_mode = SOURCE_WORK_WAIT, // 上电保持等待,禁止自动执行Source INIT
|
.work_mode = SOURCE_WORK_WAIT, // 上电保持等待,禁止自动执行Source INIT
|
||||||
},
|
},
|
||||||
.sink = {
|
.sink = {
|
||||||
@@ -310,7 +340,6 @@ struct chrg_north_t chrgnorth = {
|
|||||||
.change_flag = 0,
|
.change_flag = 0,
|
||||||
.source = {
|
.source = {
|
||||||
.On_Flag = 0,
|
.On_Flag = 0,
|
||||||
.Set_CV_Flag = 1,
|
|
||||||
.work_mode = SOURCE_WORK_WAIT, // 上电保持等待,禁止自动执行Source INIT
|
.work_mode = SOURCE_WORK_WAIT, // 上电保持等待,禁止自动执行Source INIT
|
||||||
},
|
},
|
||||||
.sink = {
|
.sink = {
|
||||||
|
|||||||
@@ -93,60 +93,17 @@ enum {
|
|||||||
TOTAL_COIL_REGS // 继电器总数(24个)
|
TOTAL_COIL_REGS // 继电器总数(24个)
|
||||||
};
|
};
|
||||||
|
|
||||||
#define TOTAL_INPUT_CH_REGS (10) // 单通道 输入寄存器
|
#define TOTAL_INPUT_CH_REGS (50) // 单通道输入寄存器,通道地址步长为50
|
||||||
|
#define TOTAL_INPUT_REGS TOTAL_INPUT_CH_REGS * 4
|
||||||
// 输入寄存器列表
|
// 输入寄存器列表
|
||||||
|
// 每个通道占用50个地址,当前实际使用前4个寄存器,其余地址预留。
|
||||||
enum {
|
enum {
|
||||||
INPUT_REG_CH0_STA1 = INPUT_REG_START, // 通道0 工作状态1 定义同源载
|
INPUT_REG_CH0_STA1 = INPUT_REG_START, // 通道0 工作状态1 定义同源载
|
||||||
INPUT_REG_CH0_STA2, // 通道0 工作状态2 定义同源载
|
INPUT_REG_CH0_STA2, // 通道0 工作状态2 定义同源载
|
||||||
INPUT_REG_CH0_FAULT1, // 通道0 故障状态1 定义同源载
|
INPUT_REG_CH0_FAULT1, // 通道0 故障状态1 定义同源载
|
||||||
INPUT_REG_CH0_FAULT2, // 通道0 故障状态2 定义同源载
|
INPUT_REG_CH0_FAULT2 // 通道0 故障状态2 定义同源载
|
||||||
INPUT_REG_04, // 输入寄存器04
|
|
||||||
INPUT_REG_05, // 输入寄存器05
|
|
||||||
INPUT_REG_06, // 输入寄存器06
|
|
||||||
INPUT_REG_07, // 输入寄存器07
|
|
||||||
INPUT_REG_08, // 输入寄存器08
|
|
||||||
INPUT_REG_09, // 输入寄存器09
|
|
||||||
// add more TOTAL_INPUT_CH_REGS
|
|
||||||
|
|
||||||
INPUT_REG_CH1_STA1, // 通道1 工作状态1
|
|
||||||
INPUT_REG_CH1_STA2, // 通道1 工作状态2
|
|
||||||
INPUT_REG_CH1_FAULT1, // 通道1 故障状态1
|
|
||||||
INPUT_REG_CH1_FAULT2, // 通道1 故障状态2
|
|
||||||
INPUT_REG_14, // 输入寄存器14
|
|
||||||
INPUT_REG_15, // 输入寄存器15
|
|
||||||
INPUT_REG_16, // 输入寄存器16
|
|
||||||
INPUT_REG_17, // 输入寄存器17
|
|
||||||
INPUT_REG_18, // 输入寄存器18
|
|
||||||
INPUT_REG_19, // 输入寄存器19
|
|
||||||
|
|
||||||
INPUT_REG_CH2_STA1, // 通道2 工作状态1
|
|
||||||
INPUT_REG_CH2_STA2, // 通道2 工作状态2
|
|
||||||
INPUT_REG_CH2_FAULT1, // 通道2 故障状态1
|
|
||||||
INPUT_REG_CH2_FAULT2, // 通道2 故障状态2
|
|
||||||
INPUT_REG_24, // 输入寄存器24
|
|
||||||
INPUT_REG_25, // 输入寄存器25
|
|
||||||
INPUT_REG_26, // 输入寄存器26
|
|
||||||
INPUT_REG_27, // 输入寄存器27
|
|
||||||
INPUT_REG_28, // 输入寄存器28
|
|
||||||
INPUT_REG_29, // 输入寄存器29
|
|
||||||
|
|
||||||
INPUT_REG_CH3_STA1, // 通道3 工作状态1
|
|
||||||
INPUT_REG_CH3_STA2, // 通道3 工作状态2
|
|
||||||
INPUT_REG_CH3_FAULT1, // 通道3 故障状态1
|
|
||||||
INPUT_REG_CH3_FAULT2, // 通道3 故障状态2
|
|
||||||
INPUT_REG_34, // 输入寄存器34
|
|
||||||
INPUT_REG_35, // 输入寄存器35
|
|
||||||
INPUT_REG_36, // 输入寄存器36
|
|
||||||
INPUT_REG_37, // 输入寄存器37
|
|
||||||
INPUT_REG_38, // 输入寄存器38
|
|
||||||
INPUT_REG_39, // 输入寄存器39
|
|
||||||
INPUT_REG_40, // 输入寄存器40
|
|
||||||
|
|
||||||
|
|
||||||
TOTAL_INPUT_REGS // 输入寄存器总数
|
|
||||||
};
|
};
|
||||||
//AI修改,不一定准确
|
|
||||||
// ======================== 新寄存器映射 (基于0x06/0x10标准Modbus功能码) ========================
|
// ======================== 新寄存器映射 (基于0x06/0x10标准Modbus功能码) ========================
|
||||||
// 地址空间规划:
|
// 地址空间规划:
|
||||||
// 负载(Sink): 0x0000 + 通道号×29 + 参数偏移 (4通道×29=116个, 0x0000~0x0073)
|
// 负载(Sink): 0x0000 + 通道号×29 + 参数偏移 (4通道×29=116个, 0x0000~0x0073)
|
||||||
|
|||||||
@@ -228,7 +228,6 @@ static int chrg_sink_nor_work_off(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pSW->sink.On_work = 0;
|
pSW->sink.On_work = 0;
|
||||||
pSOU->enable[idx] = 0;
|
|
||||||
pSOU->online[idx] = 0;
|
pSOU->online[idx] = 0;
|
||||||
pNOR->enable[idx] = 0;
|
pNOR->enable[idx] = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,6 @@ static int chrg_source_work_stop(eIDX_SOU_CH idx, struct chrg_switch_t *pSW)
|
|||||||
}
|
}
|
||||||
|
|
||||||
pSW->source.On_Flag = 0;
|
pSW->source.On_Flag = 0;
|
||||||
pSOU->enable[idx] = 0;
|
|
||||||
pNOR->enable[idx] = 0;
|
pNOR->enable[idx] = 0;
|
||||||
pSOU->online[idx] = 0;
|
pSOU->online[idx] = 0;
|
||||||
chrg_nor_sw_rel((eIDX_NOR_CH)idx, 0);
|
chrg_nor_sw_rel((eIDX_NOR_CH)idx, 0);
|
||||||
|
|||||||
@@ -156,7 +156,6 @@ struct chrg_src_t {
|
|||||||
rt_uint16_t protective_curr; // 保护电流
|
rt_uint16_t protective_curr; // 保护电流
|
||||||
rt_uint8_t Now_State; // 当前状态
|
rt_uint8_t Now_State; // 当前状态
|
||||||
rt_uint8_t On_Flag; // 启动总标志(0/1)
|
rt_uint8_t On_Flag; // 启动总标志(0/1)
|
||||||
rt_uint8_t Set_CV_Flag; // 电压/电流切换标志(0/1)
|
|
||||||
rt_uint8_t LCD_Set_Pro_Flag; // LCD设置协议标志位
|
rt_uint8_t LCD_Set_Pro_Flag; // LCD设置协议标志位
|
||||||
rt_uint8_t change_sink_Flag; // 从source切换到sink标志位
|
rt_uint8_t change_sink_Flag; // 从source切换到sink标志位
|
||||||
rt_uint8_t work_mode;
|
rt_uint8_t work_mode;
|
||||||
|
|||||||
Binary file not shown.
@@ -0,0 +1,190 @@
|
|||||||
|
#ifndef __DigtalPower_ModbusRTU_REG_List_H__
|
||||||
|
#define __DigtalPower_ModbusRTU_REG_List_H__
|
||||||
|
|
||||||
|
#include "USART1_Modbus_RTU.h"
|
||||||
|
#include "dac.h"
|
||||||
|
|
||||||
|
#define ModbusRTU_SW_Version 0x0301; //01是电源代号,02是负载代号,03是非节能源载代号,04是节能电源代号;低字节01是版本号,V0.1
|
||||||
|
|
||||||
|
//ModbusRTU 从站地址//工作状态及运行参数显示
|
||||||
|
#define ModbusRTU_Power_Status 0x00 //R,工作状态指示,00 预充电;01就绪/停止 02 缓启动;03 运行;04 故障:03 03 00 00 00 01 85 E8
|
||||||
|
#define ModbusRTU_Relay_Status 0x01 //bit0=0 主继电器断开 bit0=1 主继电器闭合;;;bit1=0 滤波继电器断开 bit1=1 滤波继电器闭合
|
||||||
|
#define ModbusRTU_Fault_Status 0x02 //故障状态寄存器
|
||||||
|
#define ModbusRTU_Flash_Status 0x03 //flash存储状态
|
||||||
|
#define ModbusRTU_Role_ModeFlag 0x04 //0x04 源载指令,默认是电子负载,1是supply,2是eload
|
||||||
|
|
||||||
|
//故障寄存器
|
||||||
|
/*****************************故障类型*****************/
|
||||||
|
#define F_NOERR 0x0000//无故障
|
||||||
|
#define F_SW_VIN_UVP 0x0001//输入欠压
|
||||||
|
#define F_SW_VIN_OVP 0x0002//输入过压
|
||||||
|
#define F_SW_VOUT_UVP 0x0004//输出欠压
|
||||||
|
#define F_SW_VOUT_OVP 0x0008//输出过压
|
||||||
|
#define F_SW_IOUT_OCP 0x0010//输出过流
|
||||||
|
#define F_SW_SHORT 0x0020//输出短路
|
||||||
|
#define F_SW_OTP 0x0040//过温保护
|
||||||
|
|
||||||
|
//电源控制指令
|
||||||
|
#define ModbusRTU_PowerCmd 0x05 //05 W 0x01 开机,0x02 关机,0x03故障复位;0xAA 存储数据到flash;0xBB 恢复默认参数
|
||||||
|
#define ModbusRTU_WorkMode 0x06 //06 WR 0x01 恒压,0x02 恒流,0x03开环,04 恒功率,05恒阻
|
||||||
|
#define ModbusRTU_Volt 0x07 //07-08 WR 设置输出电压 uint32,0.001V, 0~60V,默认5V,查询电压也是这个指令
|
||||||
|
#define ModbusRTU_Current 0x09 //09-0A WR 设置输出电流 uint32 ,0.001A,, 0~60A,默认值1A,查询电压也是这个指令
|
||||||
|
|
||||||
|
#define ModbusRTU_ShortTest_VoltShort 0x0B //无论short测试成功或者失败,都给出短路恒流值的时候的电压
|
||||||
|
#define ModbusRTU_ShortTest_CurrentShort 0x0C //无论测试成功或者失败,都给出短路恒流值的时候的电压
|
||||||
|
#define ModbusRTU_OCPTest_VoltOCP 0x0D //无论short测试成功或者失败,都给出短路恒流值的时候的电压
|
||||||
|
#define ModbusRTU_OCPTest_CurrentOCP 0x0E //无论测试成功或者失败,都给出短路恒流值的时候的电压
|
||||||
|
|
||||||
|
#define ModbusRTU_DUT_Vpkp 0x0F //量测正峰值
|
||||||
|
#define ModbusRTU_DUT_Vpkn 0x10 //量测负峰值
|
||||||
|
#define ModbusRTU_DUT_Vpp 0x11 //量测峰峰值
|
||||||
|
//纹波寄存器
|
||||||
|
#define ModbusRTU_Ripple_Value 0x12 //读取纹波
|
||||||
|
|
||||||
|
#define ModbusRTU_Temp 0x1A //WR 11,当前内部温度读取点
|
||||||
|
#define ModbusADDR_SW_Version 0x1B //10,12地址,读取版本号,03代表buckboost半桥,01是版本号
|
||||||
|
#define ModbusADDR_SlaveID_Modify 0x1C //11,13地址,修订SlaveID
|
||||||
|
|
||||||
|
|
||||||
|
#define Line_Compensation 0X1D //1F 14d地址,线损补偿,正负5V,1mv,精度0.001,放大1000倍,5000
|
||||||
|
|
||||||
|
#define Eload_Start_VON 0x20 //10 16寄存器存储电子负载启动电压,负载检测到电压值为启动电压,才开启电子负载;
|
||||||
|
#define Eload_Stop_Volt 0x21 //11 17寄存器存储电子负载关闭电压;
|
||||||
|
#define Eload_Slew_Rate 0x22 //12 18寄存器存储电子负载上升斜率参数;
|
||||||
|
|
||||||
|
#define ModbusRTU_CPower 0x24 //36-37 功率值
|
||||||
|
#define ModbusRTU_CResistor 0x26 //38 电阻值
|
||||||
|
|
||||||
|
//6.3.1电源控制参数
|
||||||
|
#define ModbusRTU_VoltLimit 0x28 //0x29 40-41 0x2A 42寄存器输出电压限值,默认是6.0V,可以微调到6.5V;
|
||||||
|
#define ModbusRTU_CurrentLimit_H 0x2A //42~43WR 输出电流限值
|
||||||
|
#define ModbusRTU_CurrentLimit_L 0x2B //42~43WR 输出电流限值
|
||||||
|
|
||||||
|
#define ModbusRTU_Volt_CAL_K 0x2C //2C~2D 电压校准K值,被放大Q16倍,再移动16回去;使用两个字节
|
||||||
|
#define ModbusRTU_Volt_CAL_K_L 0x2D
|
||||||
|
#define ModbusRTU_Volt_CAL_B 0x2E //2E 电压校准B值
|
||||||
|
#define ModbusRTU_Current_CAL_K 0x2F //2F-30 电流校准K值
|
||||||
|
#define ModbusRTU_Current_CAL_K_L 0x30
|
||||||
|
|
||||||
|
#define ModbusRTU_Current_CAL_B 0x31 //31 电流校准B值
|
||||||
|
|
||||||
|
#define ModbusRTU_SourceCurrent_CAL_K 0x32 //32-33 电流校准K值
|
||||||
|
#define ModbusRTU_SourceCurrent_CAL_K_L 0x33
|
||||||
|
|
||||||
|
#define ModbusRTU_SourceCurrent_CAL_B 0x34 //34 电流校准B值
|
||||||
|
|
||||||
|
#define ModbusRTU_SourceSink_Current_Offset 0x35 //电源的电流上报offset
|
||||||
|
//#define ModbusRTU_Sink_Current_Offset 0x33 //负载的电流上报offset
|
||||||
|
|
||||||
|
#define ModbusRTU_CALI_CRC 0x36 //校准偏移6参数的校验值;使用CRC16-Modbus校验;
|
||||||
|
|
||||||
|
|
||||||
|
#define ModbusRTU_CAL_WriteEnable 0x37 //使能写入FLASH;下次调用使用这个参数;是个魔数:0x4361 (C+a)
|
||||||
|
#define ModbusRTU_CAL_WriteRecovery 0x38 //使能写入出厂数据区域;0x5763
|
||||||
|
#define ModbusRTU_CAL_ReadRecovery 0x39 //使能读出;将出厂数据读到当前的bank中,并更新6个参数
|
||||||
|
|
||||||
|
//short测试
|
||||||
|
#define ModbusRTU_ShortTest_CMD_MODE_FLAG 0x40 //16位;0x0101; 01启动,低字节的01,保持电流,为0是释放电流; 20260601新增一个低字节的bit7=0用于是恢复以前的状态,bit7=1是将卸载电流归零;
|
||||||
|
#define ModbusRTU_ShortTest_Hold_Time 0x41 //单位是ms,最大65535ms,给0是立即释放,给一个时间值,是保持这个时间不变;
|
||||||
|
//#define ModbusRTU_ShortTest_CurrentShort 0x42 //无论测试成功或者失败,都给出短路恒流值的时候的电压
|
||||||
|
|
||||||
|
//OCP测试
|
||||||
|
#define ModbusRTU_OCPTest_CMD_MODE_FLAG 0x43 //16位;0x0101; 01启动,低字节的01,保持电流,为0是释放电流; 20260601新增一个低字节的bit7=0用于是恢复以前的状态,bit7=1是将卸载电流归零;
|
||||||
|
#define ModbusRTU_OCPTest_StartCurrent 0x44 //起始电流
|
||||||
|
#define ModbusRTU_OCPTest_StopCurrent 0x45 //终止电流
|
||||||
|
#define ModbusRTU_OCPTest_StepCurrent 0x46 //每一步的电流
|
||||||
|
#define ModbusRTU_OCPTest_Step_Hold_Time 0x47 //每一步的保持时间;默认10ms;范围1ms到100ms;
|
||||||
|
#define ModbusRTU_OCPTest_Vtrig_Stop 0x48 //达到触发OCP流点的电压值;
|
||||||
|
#define ModbusRTU_OCPTest_Hold_Time 0x49
|
||||||
|
//#define ModbusRTU_OCPTest_VoltOCP 0x49 //无论short测试成功或者失败,都给出短路恒流值的时候的电压
|
||||||
|
//#define ModbusRTU_OCPTest_CurrentOCP 0x4A //无论测试成功或者失败,都给出短路恒流值的时候的电压
|
||||||
|
|
||||||
|
//DYNA 电子负载的动态测试模式,也叫动态负载或瞬态测试。在该模式下,负载会按设定的斜率、频率和占空比,在两个电流值(如高负载和低负载)之间周期性跳变,用来测试电源的瞬态响应、恢复时间等特性。
|
||||||
|
#define ModbusRTU_DYNA_CMD_MODE_FLAG 0x4B //动态测试 CMD启动、退出、 以及模式:Continuous、PULSE、Toggle;LSB8 BIT7 短路测试时候的电流:保持/归零;bit1 过流; bit0 成功/失败
|
||||||
|
#define ModbusRTU_DYNA_L1 0x4C //动态测试电流1
|
||||||
|
#define ModbusRTU_DYNA_L2 0x4D //动态测试电流2
|
||||||
|
#define ModbusRTU_DYNA_T1 0x4E //动态测试电流1的时间
|
||||||
|
#define ModbusRTU_DYNA_T2 0x4F //动态测试电流2的时间
|
||||||
|
#define ModbusRTU_DYNA_Rise_Slew_Rate 0x50 //动态测试上升斜率
|
||||||
|
#define ModbusRTU_DYNA_Fall_Slew_Rate 0x51 //动态测试下降斜率
|
||||||
|
|
||||||
|
|
||||||
|
#define ModbusRTU_DUT_ValueReset 0x5D //复位数值
|
||||||
|
|
||||||
|
#define ModbusRTU_SYS_Reset 0x61 //系统复位指令,如果异常过压,通常发指令,让系统复位
|
||||||
|
|
||||||
|
//#define ModbusRTU_Volt_Kp 0x30 //48-49 RW 电压环kp
|
||||||
|
//#define ModbusRTU_Volt_Ki 0x32 //50-51WR 电压环ki
|
||||||
|
//#define ModbusRTU_Curr_Kp 0x34 //52-53WR 电流环kp
|
||||||
|
//#define ModbusRTU_Curr_Ki 0x36 //54-55WR 电流环ki
|
||||||
|
|
||||||
|
//#define ModbusRTU_CP_Kp 0x38 //56-57 RW 功率环kp
|
||||||
|
//#define ModbusRTU_CP_Ki 0x3A //58-59 WR 功率环ki
|
||||||
|
//#define ModbusRTU_CR_Kp 0x3C //60-61 WR 电阻环kp
|
||||||
|
//#define ModbusRTU_CR_Ki 0x3E //62-63 WR 电阻环ki
|
||||||
|
|
||||||
|
//112,0x70寄存器,改为当前内部温度读取点;
|
||||||
|
|
||||||
|
#define ModbusRTU_TempLimit 0x71 //WR 温度限值
|
||||||
|
#define ModbusRTU_FANSpeed 0x72 //风速控制,上位机可以设定;自动模式下,温度高于一个值,最大风速跑,低于则最小风速跑
|
||||||
|
|
||||||
|
#define SMU_Relay_ON 0x0001 //源载主继电器
|
||||||
|
#define SMU_EL_PB15_EMI_Bypass_ON 0x0002 //旁路滤波继电器
|
||||||
|
//定义电流保护值的关系:Y(VDAC) = K*X(I-real)+B
|
||||||
|
#define Init_OCP_VALUE 12000 //12A
|
||||||
|
//正向:
|
||||||
|
#define K_COEFF_FWD_Q16 (9960)
|
||||||
|
#define B_Intercept_FWD (1846)
|
||||||
|
//反向:
|
||||||
|
#define K_COEFF_REV_Q16 (-9960)
|
||||||
|
#define B_Intercept_REV (1846)
|
||||||
|
|
||||||
|
//结构体
|
||||||
|
//6.2.1工作状态及运行参数显示 PowerStatusAndParaShow
|
||||||
|
typedef struct {
|
||||||
|
uint16_t Power_Status;
|
||||||
|
uint16_t Relay_Status;
|
||||||
|
uint16_t Fault_Status;
|
||||||
|
uint16_t Flash_Status;
|
||||||
|
uint32_t InputVolt;
|
||||||
|
uint32_t InputCurr;
|
||||||
|
uint32_t OutputVolt;
|
||||||
|
uint32_t OutputCurr;
|
||||||
|
uint32_t OutputPower;
|
||||||
|
uint16_t statusRsv1; //预留位
|
||||||
|
uint16_t statusRsv2;
|
||||||
|
}S_PowerStatusAndParaShow;
|
||||||
|
|
||||||
|
extern S_PowerStatusAndParaShow PowerStatusAndParaShow;
|
||||||
|
|
||||||
|
//6.2.2电源控制指令PowerControlCmd
|
||||||
|
typedef struct{
|
||||||
|
uint16_t PowerCmd;
|
||||||
|
uint16_t WorkMode;
|
||||||
|
uint32_t Vout;
|
||||||
|
uint32_t Iout;
|
||||||
|
uint8_t Remote_Power_ON_Flag; //开关机指示
|
||||||
|
uint8_t Remote_Power_Reset_Flag; //复位指示
|
||||||
|
}S_PowerControlCmd;
|
||||||
|
|
||||||
|
extern S_PowerControlCmd PowerControlCmd;
|
||||||
|
|
||||||
|
|
||||||
|
//6.3.1电源控制参数
|
||||||
|
typedef struct{
|
||||||
|
uint32_t VoutLimit;
|
||||||
|
uint32_t IoutLimit;
|
||||||
|
uint16_t DutyLimit;
|
||||||
|
uint16_t FrequnceLimit;
|
||||||
|
float VoltKp;
|
||||||
|
float VoltKi;
|
||||||
|
float CurrKp;
|
||||||
|
float CurrKi;
|
||||||
|
}S_PowerControlPara;
|
||||||
|
|
||||||
|
extern uint8_t Power_OnOff_Flag,Power_OnOff_Flag;
|
||||||
|
|
||||||
|
extern S_PowerControlPara PowerControlPara;
|
||||||
|
//Modbus 参数初始化
|
||||||
|
extern void Modbus_Para_Init(void);
|
||||||
|
#endif
|
||||||
Binary file not shown.
@@ -2237,6 +2237,7 @@ static struct rt_thread usb_thread;
|
|||||||
/* internal of the message queue: every message is associated with a pointer,
|
/* internal of the message queue: every message is associated with a pointer,
|
||||||
* so in order to recveive USBD_MQ_MAX_MSG messages, we have to allocate more
|
* so in order to recveive USBD_MQ_MAX_MSG messages, we have to allocate more
|
||||||
* than USBD_MQ_MSG_SZ*USBD_MQ_MAX_MSG memory. */
|
* than USBD_MQ_MSG_SZ*USBD_MQ_MAX_MSG memory. */
|
||||||
|
rt_align(RT_ALIGN_SIZE)
|
||||||
static rt_uint8_t usb_mq_pool[(USBD_MQ_MSG_SZ+sizeof(void*))*USBD_MQ_MAX_MSG];
|
static rt_uint8_t usb_mq_pool[(USBD_MQ_MSG_SZ+sizeof(void*))*USBD_MQ_MAX_MSG];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user