1. 删除chrg_roll_nor.h中的chrg_roll_trim_set声明 2. 从chrg_north.h中移除trim_step和north_mode成员变量 3. 在chrg_roll_sou.h中新增chrg_sou_trim_submit函数声明 4. 重构chrg_comm.c的校准处理逻辑: - 移除旧的通道关闭逻辑和本地寄存器操作 - 新增校准模式合法性校验 - 调用南向模块提交校准指令 5. 从chrg_roll_nor.c中删除全部校准相关代码 6. 在chrg_roll_sou.c中实现完整的校准指令组包和提交逻辑 7. 重构boot目录下的main.c,新增完整的系统初始化和跳转流程
152 lines
5.9 KiB
C
152 lines
5.9 KiB
C
/****************************************************************************
|
|
文件名称 : chrg_north.h
|
|
完成日期 :
|
|
当前版本号 : V1.0
|
|
主要功能 : 实现北向通信交互,包括接收命令解析,发送请求命令,切换通路。以独立线程处理。
|
|
版本历史 : 创建原始版本
|
|
说明 :
|
|
******************************************************************************/
|
|
|
|
#ifndef __CHRG_NORTH_H__
|
|
#define __CHRG_NORTH_H__
|
|
|
|
#include <rtthread.h>
|
|
#include "chrg_source.h"
|
|
#include "chrg_tty.h"
|
|
#include "chrg_sink.h"
|
|
#include "chrg_def.h"
|
|
|
|
#define THR_NAME_NORTH "thr.nor"
|
|
#define DEV_NAME_NORTH "uart3"
|
|
|
|
#define LEN_FRAME_HEAD (3) // [帧长, 0x00, id]
|
|
#define MIN_FRAME_LENGTH (5) // 帧最短5字节
|
|
#define WORK_MIN_VOLT 3000 // 工作电压下限,单位mV
|
|
#define DEBUG_NORTH 0x01 // 0 = 关闭,1 = 开启
|
|
#define LCD_OPEN 0x01 // 0为关闭屏幕显示 1为打开
|
|
#define TRIM_NORTH 0x00 // 0 = 关闭, 1 = 开启
|
|
#define SINK_TEST_DEBUG 0x00 // 0 = 关闭,1 = 开启
|
|
#define PRO_TEST_DEBUG 0x00 //
|
|
#define DEBUG_SOUTH 0x00 // 0 = 关闭,1 = 开启
|
|
// 北向4通路索引 U14 ->
|
|
typedef enum {
|
|
IDX_NOR_CH1 = IDX_CH1, // J3
|
|
IDX_NOR_CH2 = IDX_CH2, // J4
|
|
IDX_NOR_CH3 = IDX_CH3, // J9
|
|
IDX_NOR_CH4 = IDX_CH4, // J10
|
|
|
|
TOTAL_NOR_CHS
|
|
} eIDX_NOR_CH;
|
|
|
|
|
|
struct chrg_switch_t {
|
|
eIDX_ID id;
|
|
struct chrg_src_t source;
|
|
struct chrg_sink_t sink;
|
|
rt_uint8_t protoCmd; // 协议类型
|
|
rt_uint8_t sub; //状态机步骤
|
|
rt_uint8_t show_step; // 显示步骤标志位,0-各项参数,1-显示电压电流,
|
|
rt_uint8_t continue_flag;
|
|
rt_uint8_t CV_mode; //恒压恒流
|
|
rt_uint8_t change_flag; //正在调整功率标志位
|
|
rt_uint16_t Now_voltage; // 当前电压 mV
|
|
rt_uint16_t Now_current; // 当前电流 mA
|
|
rt_uint16_t VZ;
|
|
rt_uint16_t VF;
|
|
};
|
|
//校准结构体
|
|
//#define ModbusRTU_Trim_Start 0x01 //进入校准模式
|
|
//#defin ModbusRTU_Trim_Stop 0x02 //退出校准模式
|
|
#define ModbusRTU_Volt_CAL_K_H 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_H 0x2F //2F-30 电流校准K值
|
|
#define ModbusRTU_Current_CAL_K_L 0x30
|
|
#define ModbusRTU_Current_CAL_B 0x31 //31 电流校准B值
|
|
|
|
#define ModbusRTU_SourceCurrent_CAL_K_H 0x32 //32-33 电流校准K值
|
|
#define ModbusRTU_SourceCurrent_CAL_K_L 0x33
|
|
#define ModbusRTU_SourceCurrent_CAL_B 0x34 //34 电流校准B值
|
|
|
|
#define ModbusRTU_Trim_Zero_CAL 0x35 //35 校准零点,写入后会将电压电流都校准到0,读取时会返回当前的零点值
|
|
|
|
#define ModbusRTU_Trim_CRC_CAL 0x36 //36 校准CRC校验,写入后会将之前的校准数据生效,读取时会返回当前的CRC校验值
|
|
|
|
#define ModbusRTU_CAL_WriteEnable_ADD 0x37 //使能写入FLASH的地址
|
|
#define ModbusRTU_CAL_WriteValue 0x4361 //写入FALSH的魔数
|
|
#define ModbusRTU_CAL_WriteRecovery 0x38 //使能写入出厂数据区域;0x5763
|
|
#define ModbusRTU_CAL_WriteRecovery_Value 0x5763 //写入FALSH的魔数
|
|
#define ModbusRTU_CAL_ReadRecovery 0x39 //使能读出;将出厂数据读到当前的bank中,并更新6个参数
|
|
|
|
#define MODE_VOLT_CAL 0x01
|
|
#define MODE_CURR_CAL 0x02
|
|
#define MODE_SOURCE_CURR_CAL 0x03
|
|
#define MODE_ZERO_CAL 0x04
|
|
struct chrg_trim {
|
|
rt_uint16_t trim_volt_k_H; // 校准电压值高16位 mV
|
|
rt_uint16_t trim_volt_k_L; // 校准电压值低16位 mV
|
|
rt_int16_t trim_volt_b; // 校准电压值b mV
|
|
rt_uint16_t trim_curr_k_H; // 校准电流值高16位 mA
|
|
rt_uint16_t trim_curr_k_L; // 校准电流值低16位 mA
|
|
rt_int16_t trim_curr_b; // 校准电流值b mA
|
|
rt_uint16_t trim_source_curr_k_H; // 校准电源电流值高16位 mA
|
|
rt_uint16_t trim_source_curr_k_L; // 校准电源电流值低16位 mA
|
|
rt_int16_t trim_source_curr_b; // 校准电源电流值b mA
|
|
rt_int16_t trim_zero; // 校准飘零值 mV/mA
|
|
rt_uint8_t trim_mode; // 校准模式, 0-默认值,1-校准电压,2-校准电流,3-校准电源电流
|
|
rt_uint8_t trim_enable_flag; //0就是默认写用户区,1则写出场数据区
|
|
};
|
|
|
|
struct chrg_north_t {
|
|
const char *devname;
|
|
|
|
struct chrg_tty_t *tty;
|
|
struct rt_ringbuffer *rb;
|
|
struct pickup_info_t frame;
|
|
struct chrg_trim trim[TOTAL_NOR_CHS];
|
|
rt_uint8_t rx_buf[SIZE_BUF_TTY];
|
|
rt_uint8_t free_flag;
|
|
rt_uint8_t enable[TOTAL_NOR_CHS]; // 通路使能
|
|
rt_uint8_t manual; // 手动插入命令
|
|
eIDX_NOR_CH idx; // 当前通路
|
|
struct chrg_switch_t sw[TOTAL_NOR_CHS];
|
|
};
|
|
|
|
extern struct chrg_north_t chrgnorth;
|
|
|
|
/*****************************************************************
|
|
函数名称: chrg_north_switch
|
|
函数描述: 北向通道选择
|
|
输入参数: ch: 北向通道
|
|
输出参数: -
|
|
返回说明: <0: 错误
|
|
其它说明: -
|
|
*****************************************************************/
|
|
extern int chrg_north_switch (eIDX_NOR_CH ch);
|
|
|
|
/*****************************************************************
|
|
函数名称: chrg_north_send
|
|
函数描述: 北向通道数据发送
|
|
输入参数: *data: 数据 length: 数据长度
|
|
输出参数: -
|
|
返回说明: <0: 错误 >0:发送数据长度
|
|
其它说明: -
|
|
*****************************************************************/
|
|
extern int chrg_north_send (rt_uint8_t *data, rt_size_t length);
|
|
|
|
/*****************************************************************
|
|
函数名称: chrg_north_thread_entry
|
|
函数描述: 北向通道数据接收线程体
|
|
输入参数: *data: 本线程信息
|
|
输出参数: -
|
|
返回说明: -
|
|
其它说明: -
|
|
*****************************************************************/
|
|
extern void chrg_north_thread_entry (void *data);
|
|
extern rt_uint8_t On_Flag2;
|
|
extern rt_bool_t Set_Pro_Flag;
|
|
#endif
|
|
|
|
|