Compare commits
14 Commits
7c32dae073
...
c184bd3407
Author | SHA1 | Date |
---|---|---|
|
c184bd3407 | |
|
55811f0946 | |
|
d6f0e84c3f | |
|
d0a9e1f573 | |
|
3ee2cccf2d | |
|
2b428a8e35 | |
|
bccfc0c450 | |
|
688f925657 | |
|
8053971109 | |
|
c31fddb450 | |
|
557fb2777e | |
|
0fcdfa75d3 | |
|
eca3fd058a | |
|
8cd729d904 |
34
.mxproject
34
.mxproject
File diff suppressed because one or more lines are too long
|
@ -28,6 +28,18 @@
|
|||
"other.h": "c",
|
||||
"hy_protocol.h": "c",
|
||||
"cfg_protocol.h": "c",
|
||||
"chargcontrolenum.h": "c"
|
||||
"chargcontrolenum.h": "c",
|
||||
"chargcontroltypes.h": "c",
|
||||
"fm_rtc.h": "c",
|
||||
"interruptsend.h": "c",
|
||||
"rtc.h": "c",
|
||||
"soe.h": "c",
|
||||
"hd_rtc.h": "c",
|
||||
"flash.h": "c",
|
||||
"configparameter.h": "c",
|
||||
"usart.h": "c",
|
||||
"w25qxx.h": "c",
|
||||
"w25q256.h": "c",
|
||||
"gpio.h": "c"
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "bl_chargControl.h"
|
||||
|
||||
#include "capture.h"
|
||||
|
||||
void chargControl(void);
|
||||
|
||||
|
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
#ifndef APP_COMM_H_
|
||||
#define APP_COMM_H_
|
||||
|
||||
#include "comm_types.h"
|
||||
#include "bl_comm.h"
|
||||
|
||||
|
||||
void uart_comm(void);
|
||||
|
||||
|
||||
#endif
|
|
@ -1,8 +0,0 @@
|
|||
|
||||
#include "comm.h"
|
||||
|
||||
void uart_comm(void)
|
||||
{
|
||||
GW485_comm();
|
||||
BAT485_comm();
|
||||
}
|
|
@ -4,13 +4,70 @@
|
|||
#include "Init.h"
|
||||
#include "task.h"
|
||||
#include "pDebug.h"
|
||||
#include "parameter.h"
|
||||
#include "FM_TIM.h"
|
||||
#include "inFlash.h"
|
||||
|
||||
|
||||
void startInfo(void)
|
||||
{
|
||||
log_info("uniqueDeviceID : 0x%x%x%x%x%x%x%x \n", g_cfgParameter.uniqueDeviceID[0]
|
||||
, g_cfgParameter.uniqueDeviceID[1]
|
||||
, g_cfgParameter.uniqueDeviceID[2]
|
||||
, g_cfgParameter.uniqueDeviceID[3]
|
||||
, g_cfgParameter.uniqueDeviceID[4]
|
||||
, g_cfgParameter.uniqueDeviceID[5]
|
||||
, g_cfgParameter.uniqueDeviceID[6]);
|
||||
log_info("gw485_Baud : %d \n", g_cfgParameter.gw485_Baud);
|
||||
log_info("bat485_Baud : %d \n", g_cfgParameter.bat485_Baud);
|
||||
log_info("powerBoxType : 0x%x \n", g_cfgParameter.powerBoxType);
|
||||
log_info("constantVoltageV : %f \n", g_cfgParameter.constantVoltageV);
|
||||
log_info("floatI : %f \n", g_cfgParameter.floatI);
|
||||
log_info("startSolarOpenCircuitV : %f \n", g_cfgParameter.startSolarOpenCircuitV);
|
||||
log_info("stopSolarOutputCircuitV : %f \n", g_cfgParameter.stopSolarOutputCircuitV);
|
||||
log_info("checkCanStartTime : %d \n", g_cfgParameter.checkCanStartTime);
|
||||
log_info("shortCircuitJudgmentDelay : %d \n", g_cfgParameter.shortCircuitJudgmentDelay);
|
||||
log_info("inputPowerLowJudgmentDelay : %d \n", g_cfgParameter.inputPowerLowJudgmentDelay);
|
||||
log_info("inputPowerLowAgainOutputDelay : %d \n", g_cfgParameter.inputPowerLowAgainOutputDelay);
|
||||
log_info("firstStageProtectionDelay : %d \n", g_cfgParameter.firstStageProtectionDelay);
|
||||
log_info("firstStageProtectionValue : %d \n", g_cfgParameter.firstStageProtectionValue);
|
||||
log_info("firstStageProtectionCurr : %f \n", g_cfgParameter.firstStageProtectionCurr);
|
||||
log_info("secondStageProtectionDelay : %d \n", g_cfgParameter.secondStageProtectionDelay);
|
||||
log_info("secondStageProtectionCurr : %f \n", g_cfgParameter.secondStageProtectionCurr);
|
||||
log_info("thirdStageProtectionDelay : %d \n", g_cfgParameter.thirdStageProtectionDelay);
|
||||
log_info("thirdStageProtectionCurr : %f \n", g_cfgParameter.thirdStageProtectionCurr);
|
||||
log_info("inputPowerLowDetectionDelay : %d \n", g_cfgParameter.inputPowerLowDetectionDelay);
|
||||
log_info("inputPowerLowDetectionVolt : %f \n", g_cfgParameter.inputPowerLowDetectionVolt);
|
||||
log_info("maxOpenSolarOutputCircuitV : %f \n", g_cfgParameter.maxOpenSolarOutputCircuitV);
|
||||
log_info("maxChargCurr : %f \n", g_cfgParameter.maxChargCurr);
|
||||
log_info("minCheckLoopImpedanceChargCurr : %f \n", g_cfgParameter.minCheckLoopImpedanceChargCurr);
|
||||
log_info("fullPowerOutputTemperature : %f \n", g_cfgParameter.fullPowerOutputTemperature);
|
||||
log_info("reducePowerOutputTemperature : %f \n", g_cfgParameter.reducePowerOutputTemperature);
|
||||
log_info("stopPowerOutputTemperature : %f \n", g_cfgParameter.stopPowerOutputTemperature);
|
||||
log_info("constantVoltageChargeV : %f \n", g_cfgParameter.constantVoltageChargeV);
|
||||
log_info("FloatChargeV : %f \n", g_cfgParameter.FloatChargeV);
|
||||
log_info("collectOpenCircuitVoltageTime : %d \n", g_cfgParameter.collectOpenCircuitVoltageTime);
|
||||
log_info("Access_Node_Type : %x \n", g_cfgParameter.Access_Node_Type);
|
||||
log_info("Communication_Methods : %x \n", g_cfgParameter.Communication_Methods);
|
||||
log_info("startFlagSL : 0x%x%x \n", g_cfgParameter.startFlagSL[0], g_cfgParameter.startFlagSL[1]);
|
||||
log_info("endFlagSL : 0x%x \n", g_cfgParameter.endFlagSL);
|
||||
|
||||
log_info("loopImpedance : %f \n", getLoopImpedance());
|
||||
}
|
||||
|
||||
|
||||
void start(void)
|
||||
{
|
||||
Init();
|
||||
task_Init();
|
||||
|
||||
debug("start\n");
|
||||
startInfo();
|
||||
|
||||
// HAL_Delay(5000);
|
||||
// while (1) {
|
||||
// cfgTest();
|
||||
// HAL_Delay(1000);
|
||||
// }
|
||||
|
||||
TimeSliceOffset_Start();
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
|
||||
#ifndef BL_PARAMETER_H_
|
||||
#define BL_PARAMETER_H_
|
||||
#ifndef BL_INIT_H_
|
||||
#define BL_INIT_H_
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
#ifndef BL_SOE_
|
||||
#define BL_SOE_
|
||||
|
||||
#include "chargControlTypes.h"
|
||||
#include "inFlash.h"
|
||||
#include "comm_types.h"
|
||||
#include "flash.h"
|
||||
|
||||
|
||||
|
||||
void eventsOrderRecordStartInit(void);
|
||||
void setEventsOrderRecord(void);
|
||||
void readEventsOrderRecord(uint16_t offset, uint8_t *data);
|
||||
void insertEventsOrderRecord(eventsOrderRecordMode mode);
|
||||
|
||||
uint16_t getSoeDataInfoSize(void);
|
||||
|
||||
|
||||
#endif
|
|
@ -20,6 +20,8 @@ uint8_t getExcessiveLoad(void);
|
|||
void setExcessiveLoadFlag(BOOL state);
|
||||
BOOL getExcessiveLoadFlag(void);
|
||||
|
||||
void setSoftShortCircuit(uint16_t disChargCurrAdcNum);
|
||||
|
||||
void setPowerOutput(BOOL state);
|
||||
|
||||
void checkAbnormal(void);
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
#ifndef BL_CHARG_CONTROL_H_
|
||||
#define BL_CHARG_CONTROL_H_
|
||||
|
||||
#include "chargControlEnum.h"
|
||||
#include "chargControlTypes.h"
|
||||
#include "FM_TIM.h"
|
||||
#include "comm_types.h"
|
||||
|
||||
#define PI_CONTROL_MAX 0.1f
|
||||
#define PI_CONTROL_MIN -0.1f
|
||||
|
||||
BOOL getChargControlFlag(void);
|
||||
void setChargControlFlag(BOOL state);
|
||||
void bl_chargControl(void);
|
||||
|
|
|
@ -9,10 +9,10 @@
|
|||
#define buffLen 100
|
||||
extern uint8_t rs485_buff[buffLen];
|
||||
|
||||
void GW485_comm(void);
|
||||
void BAT485_comm(void);
|
||||
|
||||
void gw485_RxIt(void);
|
||||
void bat485_RxIt(void);
|
||||
|
||||
void gw485_TxIt(void);
|
||||
void bat485_TxIt(void);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,45 @@
|
|||
|
||||
#ifndef BL_USART_H_
|
||||
#define BL_USART_H_
|
||||
|
||||
|
||||
#include "comm_types.h"
|
||||
#include "chargControlTypes.h"
|
||||
#include "uart_dev.h"
|
||||
|
||||
|
||||
|
||||
/* SL协议读取寄存器最大地址 */
|
||||
#define maxReadRegAddrMacro 0x0120
|
||||
/* SL协议读取寄存器最小地址 */
|
||||
#define minReadRegAddrMacro 0x0100
|
||||
/* SL协议读取寄存器最大长度 */
|
||||
#define maxReadRegAddrNumMacro 10
|
||||
|
||||
|
||||
/* SL协议写入寄存器最大地址 */
|
||||
#define maxWriteRegAddrMacro 0x0120
|
||||
/* SL协议写入寄存器最小地址 */
|
||||
#define minWriteRegAddrMacro 0x0100
|
||||
/* SL协议写入寄存器最大长度 */
|
||||
#define maxWriteRegAddrNumMacro 10
|
||||
|
||||
/* SL协议寄存器长度 */
|
||||
#define RegAddrNumMacro 32
|
||||
|
||||
/* SL协议下发配置文件内容最长长度 */
|
||||
#define maxDistributionCfgLen 230
|
||||
/* SL协议读取配置文件内容最长长度 */
|
||||
#define maxReadCfgLen 32
|
||||
|
||||
|
||||
#define floatMagnification 10.0f
|
||||
|
||||
|
||||
uint16_t checkModebusCrc(uint8_t *arr_buff, uint8_t len);
|
||||
|
||||
void gw485DataAnalysis(device_handle device);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
#ifndef BL_CFG_PROTOCOL_H_
|
||||
#define BL_CFG_PROTOCOL_H_
|
||||
|
||||
#include "comm_types.h"
|
||||
|
||||
void inConfigBuff(uint8_t c);
|
||||
void zeroConfigBuff(void);
|
||||
uint16_t checkModebusCrc(uint8_t *arr_buff, uint8_t len);
|
||||
void read_and_process_config_data(void);
|
||||
|
||||
#endif
|
|
@ -1,14 +0,0 @@
|
|||
|
||||
#ifndef BL_HY_PROTOCOL_H_
|
||||
#define BL_HY_PROTOCOL_H_
|
||||
|
||||
#include "uart_dev.h"
|
||||
|
||||
BOOL getHYconfigModeState(void);
|
||||
void setHYconfigModeState(BOOL state);
|
||||
|
||||
void HY_read_and_process_uart_data(device_handle device);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -4,88 +4,127 @@
|
|||
|
||||
#include "flash.h"
|
||||
#include "stm32g431xx.h"
|
||||
#include "chargControlTypes.h"
|
||||
#include "bl_usart.h"
|
||||
|
||||
#pragma pack(push, 1)
|
||||
|
||||
/* 高字节在前,低字节在后 */
|
||||
typedef struct _recv_config_info{
|
||||
uint8_t start_Flag[2]; /* 开始标志 */
|
||||
/* SL */
|
||||
uint8_t address[7]; /* 地址 */
|
||||
// uint8_t Access_Node_Type[2]; /* 接入节点类型 */
|
||||
// uint8_t Communication_Methods[2]; /* 通信方式 */
|
||||
uint8_t gw485_Baud[4]; /* 串口波特率 */
|
||||
uint8_t bat485_Baud[4]; /* 串口波特率,为0代表bms不支持通信 */
|
||||
// /* 高字节在前,低字节在后 */
|
||||
// typedef struct _recv_config_info{
|
||||
// uint8_t start_Flag[2]; /* 开始标志 */
|
||||
// /* SL */
|
||||
// uint8_t address[7]; /* 地址 */
|
||||
// // uint8_t Access_Node_Type[2]; /* 接入节点类型 */
|
||||
// // uint8_t Communication_Methods[2]; /* 通信方式 */
|
||||
// uint8_t gw485_Baud[4]; /* 串口波特率 */
|
||||
// uint8_t bat485_Baud[4]; /* 串口波特率,为0代表bms不支持通信 */
|
||||
|
||||
/* HY */
|
||||
uint8_t hardwareID[6]; /* 硬件ID */
|
||||
uint8_t communicationID[4]; /* 通信ID */
|
||||
uint8_t protocolType; /* 协议类型; 0x01表示:汇源协议(波特率9600) 0x02表示:南瑞协议(波特率115200)*/
|
||||
// /* HY */
|
||||
// uint8_t hardwareID[6]; /* 硬件ID */
|
||||
// uint8_t communicationID[4]; /* 通信ID */
|
||||
// uint8_t protocolType; /* 协议类型; 0x01表示:汇源协议(波特率9600) 0x02表示:南瑞协议(波特率115200)*/
|
||||
|
||||
|
||||
uint8_t CommunicationProtocolType; /* 0x00:SL
|
||||
0x01:HY*/
|
||||
uint8_t onlyPower; /* 是否只充当电源板:0x00:不是
|
||||
0x01:是*/
|
||||
// uint8_t CommunicationProtocolType; /* 0x00:SL
|
||||
// 0x01:HY*/
|
||||
// uint8_t onlyPower; /* 是否只充当电源板:0x00:不是
|
||||
// 0x01:是*/
|
||||
|
||||
uint8_t ConstantVoltageV[2]; /* 高于该(电压 / 100)且电流大于FloatI * 100进行恒压充电 */
|
||||
uint8_t FloatI[2]; /* 高于该(电压 / 100)且电流低于FloatI * 100进行浮充充电 */
|
||||
uint8_t startSolarOpenCircuitV[2]; /* 高于该(电压 / 100)开始充电 */
|
||||
uint8_t stopSolarOpenCircuitV[2]; /* 太阳能板开路电压高于该电压停止充电 (V) */
|
||||
uint8_t constantVoltageChargeV[2]; /* 恒压充电时的输出电压 (V) */
|
||||
uint8_t FloatChargeV[2]; /* 浮充充电时的输出电压 (V) */
|
||||
uint8_t HighSideMosTemperature_stop[2]; /* 当上桥温度达到该值时,停止输出 (°C) */
|
||||
uint8_t HighSideMosTemperature_end[2]; /* 当上桥温度上升到该值时,降低功率运行 (°C) */
|
||||
uint8_t HighSideMosTemperature_start[2];/* 当上桥温度降低到该值时,按照正常情况输出 (°C) */
|
||||
// uint8_t ConstantVoltageV[2]; /* 高于该(电压 / 100)且电流大于FloatI * 100进行恒压充电 */
|
||||
// uint8_t FloatI[2]; /* 高于该(电压 / 100)且电流低于FloatI * 100进行浮充充电 */
|
||||
// uint8_t startSolarOpenCircuitV[2]; /* 高于该(电压 / 100)开始充电 */
|
||||
// uint8_t stopSolarOpenCircuitV[2]; /* 太阳能板开路电压高于该电压停止充电 (V) */
|
||||
// uint8_t constantVoltageChargeV[2]; /* 恒压充电时的输出电压 (V) */
|
||||
// uint8_t FloatChargeV[2]; /* 浮充充电时的输出电压 (V) */
|
||||
// uint8_t HighSideMosTemperature_stop[2]; /* 当上桥温度达到该值时,停止输出 (°C) */
|
||||
// uint8_t HighSideMosTemperature_end[2]; /* 当上桥温度上升到该值时,降低功率运行 (°C) */
|
||||
// uint8_t HighSideMosTemperature_start[2];/* 当上桥温度降低到该值时,按照正常情况输出 (°C) */
|
||||
|
||||
// uint8_t checkSolarOpenCircuitVTime[2]; /* 启动任务中太阳能板开路电压检测间隔时间 (S) */
|
||||
// uint8_t sensorEnableBroadcastTime[2]; /* 传感器运行再次注册的间隔 (S) */
|
||||
uint8_t outputAgainFlagTime[2]; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */
|
||||
uint8_t excessiveLoadFlagTime[2]; /* 出现过载后,在该间隔时间中多次(2次)出现过载,则关闭输出 (S) */
|
||||
uint8_t eLAgainTime[2]; /* 出现过载过载保护后,在该间隔段时间后,再次尝试输出 (S) */
|
||||
uint8_t crc[2]; /* 校验 */
|
||||
uint8_t end_Flag; /* 结束标志 */
|
||||
}recv_config_info;
|
||||
#define RECV_CONFIG_INFO sizeof(recv_config_info)
|
||||
// // uint8_t checkSolarOpenCircuitVTime[2]; /* 启动任务中太阳能板开路电压检测间隔时间 (S) */
|
||||
// // uint8_t sensorEnableBroadcastTime[2]; /* 传感器运行再次注册的间隔 (S) */
|
||||
// uint8_t outputAgainFlagTime[2]; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */
|
||||
// uint8_t excessiveLoadFlagTime[2]; /* 出现过载后,在该间隔时间中多次(2次)出现过载,则关闭输出 (S) */
|
||||
// uint8_t eLAgainTime[2]; /* 出现过载过载保护后,在该间隔段时间后,再次尝试输出 (S) */
|
||||
// uint8_t crc[2]; /* 校验 */
|
||||
// uint8_t end_Flag; /* 结束标志 */
|
||||
// }recv_config_info;
|
||||
// #define RECV_CONFIG_INFO sizeof(recv_config_info)
|
||||
|
||||
typedef struct _config_info{
|
||||
/* SL */
|
||||
uint8_t address[7]; /* 地址 */
|
||||
// uint16_t Access_Node_Type; /* 接入节点类型 */
|
||||
// uint16_t Communication_Methods; /* 通信方式 */
|
||||
uint32_t gw485_Baud; /* 串口波特率,为0代表bms不支持通信 */
|
||||
uint32_t bat485_Baud; /* 串口波特率 */
|
||||
// /* SL */
|
||||
// uint8_t address[7]; /* 地址 */
|
||||
// // uint16_t Access_Node_Type; /* 接入节点类型 */
|
||||
// // uint16_t Communication_Methods; /* 通信方式 */
|
||||
// uint32_t gw485_Baud; /* 串口波特率,为0代表bms不支持通信 */
|
||||
// uint32_t bat485_Baud; /* 串口波特率 */
|
||||
|
||||
/* HY */
|
||||
uint8_t hardwareID[6]; /* 硬件ID */
|
||||
uint8_t communicationID[4]; /* 通信ID */
|
||||
uint8_t protocolType; /* 协议类型; 0x01表示:汇源协议(波特率9600) 0x02表示:南瑞协议(波特率115200)*/
|
||||
// /* HY */
|
||||
// uint8_t hardwareID[6]; /* 硬件ID */
|
||||
// uint8_t communicationID[4]; /* 通信ID */
|
||||
// uint8_t protocolType; /* 协议类型; 0x01表示:汇源协议(波特率9600) 0x02表示:南瑞协议(波特率115200)*/
|
||||
|
||||
uint8_t CommunicationProtocolType; /* 0x00:SL
|
||||
0x01:HY*/
|
||||
uint8_t onlyPower; /* 是否只充当电源板:0x00:不是
|
||||
0x01:是*/
|
||||
// uint8_t CommunicationProtocolType; /* 0x00:SL
|
||||
// 0x01:HY*/
|
||||
// uint8_t onlyPower; /* 是否只充当电源板:0x00:不是
|
||||
// 0x01:是*/
|
||||
|
||||
float constantVoltageV; /* 电压高于ConstantVoltageV且电流大于FloatI + 0.1)进行恒压充电 */
|
||||
float floatI; /* 电压高于ConstantVoltageV且电流低于FloatI进行浮充充电 */
|
||||
float startSolarOpenCircuitV; /* 太阳能板开路电压高于该电压开始充电 */
|
||||
float stopSolarOpenCircuitV; /* 太阳能板开路电压高于该电压 停止充电 */
|
||||
float constantVoltageChargeV; /* 恒压充电时的输出电压 */
|
||||
float FloatChargeV; /* 浮充电压 */
|
||||
float HighSideMosTemperature_stop; /* 当上桥温度达到该值时,停止输出 */
|
||||
float HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 */
|
||||
float HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 */
|
||||
// float constantVoltageV; /* 电压高于ConstantVoltageV且电流大于FloatI + 0.1)进行恒压充电 */
|
||||
// float floatI; /* 电压高于ConstantVoltageV且电流低于FloatI进行浮充充电 */
|
||||
// float startSolarOpenCircuitV; /* 太阳能板开路电压高于该电压开始充电 */
|
||||
// float stopSolarOpenCircuitV; /* 太阳能板开路电压高于该电压 停止充电 */
|
||||
// float constantVoltageChargeV; /* 恒压充电时的输出电压 */
|
||||
// float FloatChargeV; /* 浮充电压 */
|
||||
// float HighSideMosTemperature_stop; /* 当上桥温度达到该值时,停止输出 */
|
||||
// float HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 */
|
||||
// float HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 */
|
||||
|
||||
// uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测时间 */
|
||||
// uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 */
|
||||
uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 */
|
||||
uint16_t excessiveLoadFlagTime; /* 出现过载后,在该段时间中再次出现过载,则关闭输出 */
|
||||
uint16_t eLAgainTime; /* 出现过载过载保护后,该段时间后,再次尝试输出 */
|
||||
// // uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测时间 */
|
||||
// // uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 */
|
||||
// uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 */
|
||||
// uint16_t excessiveLoadFlagTime; /* 出现过载后,在该段时间中再次出现过载,则关闭输出 */
|
||||
// uint16_t eLAgainTime; /* 出现过载过载保护后,该段时间后,再次尝试输出 */
|
||||
|
||||
uint16_t crc; /* 校验 */
|
||||
uint8_t uniqueDeviceID[7]; /* 设备唯一ID */
|
||||
uint32_t gw485_Baud; /* 串口波特率 */
|
||||
uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */
|
||||
uint8_t powerBoxType; /* 是否只充当电源板:0x00:不是;0x01:是*/
|
||||
float constantVoltageV; /* 恒压充电阈值电压(V) */
|
||||
float floatI; /* 浮充充电阈值电流(A) */
|
||||
float startSolarOpenCircuitV; /* 启动充电太阳能板开路电压(V) */
|
||||
float stopSolarOutputCircuitV; /* 停止充电太阳能板输出电压(V) */
|
||||
uint16_t checkCanStartTime; /* 检测能否启动间隔时间(S) */
|
||||
uint16_t shortCircuitJudgmentDelay; /* 短路判断延时(S) */
|
||||
uint16_t inputPowerLowJudgmentDelay; /* 前端输入功率不足判断延时(S) */
|
||||
uint16_t inputPowerLowAgainOutputDelay; /* 前端输入功率不足再次输出延时(S) */
|
||||
uint16_t firstStageProtectionDelay; /* 第一段保护延时(10uS) */
|
||||
float firstStageProtectionCurr; /* 第一段保护电流(A) */
|
||||
uint16_t secondStageProtectionDelay; /* 第二段保护延时(100uS) */
|
||||
float secondStageProtectionCurr; /* 第二段保护电流(A) */
|
||||
uint32_t thirdStageProtectionDelay; /* 第三段保护延时(100uS) */
|
||||
float thirdStageProtectionCurr; /* 第三段保护电流(A) */
|
||||
uint16_t inputPowerLowDetectionDelay; /* 前端输入功率不足检测延时(100uS) */
|
||||
float inputPowerLowDetectionVolt; /* 前端输入功率不足检测电压(V) */
|
||||
float maxOpenSolarOutputCircuitV; /* 最大太阳能板输出电压(V) */
|
||||
float maxChargCurr; /* 最大充电电流(A) */
|
||||
float minCheckLoopImpedanceChargCurr; /* 检测回路阻抗时的最小充电电流(A) */
|
||||
float fullPowerOutputTemperature; /* 满功率输出温度(℃) */
|
||||
float reducePowerOutputTemperature; /* 降功率输出温度(℃) */
|
||||
float stopPowerOutputTemperature; /* 停止输出温度(℃) */
|
||||
float constantVoltageChargeV; /* 恒压充电时的输出电压(V) */
|
||||
float FloatChargeV; /* 浮充充电时的输出电压(V) */
|
||||
uint16_t collectOpenCircuitVoltageTime; /* 充电时采集开路电压的间隔时间 */
|
||||
|
||||
uint16_t crc; /* 校验 */
|
||||
}config_info;
|
||||
|
||||
#define CONFIG_INFO_SIZE (sizeof(config_info))
|
||||
// typedef struct _other_info {
|
||||
// float loopImpedance;
|
||||
// float totalElectricityConsumption;
|
||||
// float totalChargCapacity;
|
||||
// float lastTime;
|
||||
// }other_info;
|
||||
// #define OTHER_INFO_SIZE (sizeof(other_info))
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#define CONFIG_SAVE_addr (0)
|
||||
|
@ -94,17 +133,32 @@ typedef struct _config_info{
|
|||
#define LoopImpedance_SAVE_addr (CONFIG_INFO_SIZE + CONFIG_INFO_SIZE + 10)
|
||||
#define totalElectricityConsumption_SAVE_addr (CONFIG_INFO_SIZE + CONFIG_INFO_SIZE + 20)
|
||||
#define totalChargCapacity_SAVE_addr (CONFIG_INFO_SIZE + CONFIG_INFO_SIZE + 30)
|
||||
#define time_SAVE_addr (CONFIG_INFO_SIZE + CONFIG_INFO_SIZE + 40)
|
||||
|
||||
// #define LoopImpedance_SAVE_addr (4096)
|
||||
// #define totalElectricityConsumption_SAVE_addr (LoopImpedance_SAVE_addr + 4)
|
||||
// #define totalChargCapacity_SAVE_addr (LoopImpedance_SAVE_addr + 8)
|
||||
// #define time_SAVE_addr (LoopImpedance_SAVE_addr + 12)
|
||||
|
||||
|
||||
// void save_config_info(config_info *save_config_info);
|
||||
void read_config_info(config_info *output_config_info);
|
||||
void saveConfigInfo(config_info *config_info);
|
||||
void config_info_start(void);
|
||||
void readFlashContent(config_info *configInfo);
|
||||
void cfgTest(void);
|
||||
|
||||
void saveLoopImpedance(float *loopImpedance);
|
||||
void readLoopImpedance(float *loopImpedance);
|
||||
void saveLoopImpedance();
|
||||
BOOL readLoopImpedance();
|
||||
void savetotalElectricityConsumption(float *totalElectricityConsumption);
|
||||
void readtotalElectricityConsumption(float *totalElectricityConsumption);
|
||||
void savetotalChargCapacity(float *totalChargCapacity);
|
||||
void readtotalChargCapacity(float *totalChargCapacity);
|
||||
void saveTime(timeInfo *time);
|
||||
void readTime(timeInfo *time);
|
||||
// void saveOtherInfo(other_info *otherInfo);
|
||||
// void readOtherInfo(other_info *otherInfo);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
|
||||
#ifndef BL_INTERRUPT_SEND_H_
|
||||
#define BL_INTERRUPT_SEND_H_
|
||||
|
||||
#include "uart_dev.h"
|
||||
#include "comm_types.h"
|
||||
#include "chargControlTypes.h"
|
||||
|
||||
|
||||
void setIdleStateGw(void);
|
||||
void setIdleStateBat(void);
|
||||
void setGwState(void);
|
||||
void setBatState(void);
|
||||
|
||||
void setSendOverStateGw(void);
|
||||
void setSendOverStateBat(void);
|
||||
|
||||
void send_init(void);
|
||||
void check_sendState(void);
|
||||
void uart_interruptSend(device_handle device, uint8_t buff[], uint8_t len);
|
||||
|
||||
uint8_t *getInsertData(void);
|
||||
void uart_insertDataSend(device_handle device, uint8_t len);
|
||||
|
||||
#endif
|
|
@ -3,52 +3,51 @@
|
|||
|
||||
#include "main.h"
|
||||
#include "comm_types.h"
|
||||
|
||||
#define softVer "SV01_24101501"
|
||||
#include "chargControlTypes.h"
|
||||
#include "configParameter.h"
|
||||
|
||||
// #pragma pack(push,1)
|
||||
|
||||
/* 主要有配置文件读取出来的数据 */
|
||||
typedef struct _config_parameter{
|
||||
float constantVoltageV; /* 电压高于ConstantVoltageV且电流大于(FloatI + 0.1)进行恒压充电
|
||||
电压低于该(ConstantVoltageV - 0.2) 进行恒流充电 (V) */
|
||||
float floatI; /* 电压高于该ConstantVoltageV且电流低于FloatI进行浮充充电 (A) */
|
||||
float startSolarOpenCircuitV; /* 太阳能板开路电压高于该电压开始充电 (V) */
|
||||
float stopSolarOpenCircuitV; /* 太阳能板开路电压高于该电压停止充电 (V) */
|
||||
float constantVoltageChargeV; /* 恒压充电时的输出电压 (V) */
|
||||
float FloatV; /* 浮充充电时的输出电压 (V) */
|
||||
float loopImpedance; /* 回路阻抗大小 (mΩ) */
|
||||
float HighSideMosTemperature_stop; /* 当上桥温度达到该值时,停止输出 (°C) */
|
||||
float HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 (°C) */
|
||||
float HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 (°C) */
|
||||
uint8_t uniqueDeviceID[7]; /* 设备唯一ID */
|
||||
|
||||
uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 (S) */
|
||||
// uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测间隔时间 (S) */
|
||||
uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */
|
||||
uint16_t excessiveLoadFlagTime; /* 出现过载后,在该间隔时间中多次(2次)出现过载,则关闭输出 (S) */
|
||||
uint16_t eLAgainTime; /* 出现过载过载保护后,在该间隔段时间后,再次尝试输出 (S) */
|
||||
uint32_t collectOpenCircuitVoltageTime; /* 充电时开路电压采集时间间隔 */
|
||||
uint32_t gw485_Baud; /* 串口波特率 */
|
||||
uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */
|
||||
uint8_t powerBoxType; /* 是否只充当电源板:0x00:不是;0x01:是*/
|
||||
float constantVoltageV; /* 恒压充电阈值电压(V) */
|
||||
float floatI; /* 浮充充电阈值电流(A) */
|
||||
float startSolarOpenCircuitV; /* 启动充电太阳能板开路电压(V) */
|
||||
float stopSolarOutputCircuitV; /* 停止充电太阳能板输出电压(V) */
|
||||
uint16_t checkCanStartTime; /* 检测能否启动间隔时间(S) */
|
||||
uint16_t shortCircuitJudgmentDelay; /* 短路判断延时(S) */
|
||||
uint16_t inputPowerLowJudgmentDelay; /* 前端输入功率不足判断延时(S) */
|
||||
uint16_t inputPowerLowAgainOutputDelay; /* 前端输入功率不足再次输出延时(S) */
|
||||
uint16_t firstStageProtectionDelay; /* 第一段保护延时(10uS) */
|
||||
float firstStageProtectionCurr; /* 第一段保护电流(A) */
|
||||
uint16_t firstStageProtectionValue; /* 第一段保护ADC值 */
|
||||
uint16_t secondStageProtectionDelay; /* 第二段保护延时(100uS) */
|
||||
float secondStageProtectionCurr; /* 第二段保护电流(A) */
|
||||
uint16_t thirdStageProtectionDelay; /* 第三段保护延时(100uS) */
|
||||
float thirdStageProtectionCurr; /* 第三段保护电流(A) */
|
||||
uint16_t inputPowerLowDetectionDelay; /* 前端输入功率不足检测延时(100uS) */
|
||||
float inputPowerLowDetectionVolt; /* 前端输入功率不足检测电压(V) */
|
||||
float maxOpenSolarOutputCircuitV; /* 最大太阳能板输出电压(V) */
|
||||
float maxChargCurr; /* 最大充电电流(A) */
|
||||
float minCheckLoopImpedanceChargCurr; /* 检测回路阻抗时的最小充电电流(A) */
|
||||
float fullPowerOutputTemperature; /* 满功率输出温度(℃) */
|
||||
float reducePowerOutputTemperature; /* 降功率输出温度(℃) */
|
||||
float stopPowerOutputTemperature; /* 停止输出温度(℃) */
|
||||
float constantVoltageChargeV; /* 恒压充电时的输出电压(V) */
|
||||
float FloatChargeV; /* 浮充充电时的输出电压(V) */
|
||||
uint16_t collectOpenCircuitVoltageTime; /* 充电时采集开路电压的间隔时间 */
|
||||
|
||||
/* SL */
|
||||
uint16_t Access_Node_Type; /* 接入节点类型 */
|
||||
uint16_t Communication_Methods; /* 通信方式 */
|
||||
uint16_t Registration_Status; /* 注册状态 */
|
||||
uint8_t address[7]; /* 地址 */
|
||||
uint8_t startFlagSL[2]; /* 起始标志 */
|
||||
uint8_t endFlagSL; /* 结束标志 */
|
||||
|
||||
/* HY */
|
||||
uint8_t hardwareID[6]; /* 硬件ID */
|
||||
uint8_t communicationID[4]; /* 通信ID */
|
||||
uint8_t protocolType; /* 协议类型; 0x01表示:汇源协议(波特率9600) 0x02表示:南瑞协议(波特率115200)*/
|
||||
uint8_t startFlagHY; /* 起始码 */
|
||||
uint8_t endFlagHY; /* 结束码 */
|
||||
|
||||
uint8_t onlyPower; /* 是否只充当电源板:0x00:不是
|
||||
0x01:是*/
|
||||
|
||||
uint32_t gw485_Baud; /* 串口波特率 */
|
||||
uint32_t bat485_Baud; /* 串口波特率,为0代表bms不支持通信 */
|
||||
} config_parameter;
|
||||
extern config_parameter g_cfgParameter;
|
||||
typedef struct _otherParameter{
|
||||
|
@ -67,8 +66,11 @@ typedef struct _otherParameter{
|
|||
|
||||
int MPPT_Mode; /* 工作模式 */
|
||||
|
||||
uint8_t versionInformation[13]; /* 软件版本信息 */
|
||||
uint8_t versionInformation[13]; /* 软件版本信息 */
|
||||
|
||||
float loopImpedance; /* 回路阻抗大小 (Ω) */
|
||||
|
||||
uint16_t Registration_Status; /* 注册状态 */
|
||||
}otherParameter;
|
||||
|
||||
// #pragma pack(pop)
|
||||
|
@ -83,6 +85,8 @@ uint8_t getMosTemperState(void);
|
|||
void setMosTemperState(uint8_t state);
|
||||
BOOL getCheckImpedanceState(void);
|
||||
void setCheckImpedanceState(void);
|
||||
void setLastTime(timeInfo time);
|
||||
timeInfo getLastTime(void);
|
||||
|
||||
float getBatteryVoltage(void);
|
||||
void setBatteryVoltage(void);
|
||||
|
@ -114,8 +118,11 @@ float getChargBatteryCurrent(void);
|
|||
BOOL getChargMosState(void);
|
||||
void setChargMosState(BOOL state);
|
||||
BOOL getDischargMosState(void);
|
||||
uint8_t *getVersionInformation(void);
|
||||
|
||||
uint8_t *getVersionnInformation(void);
|
||||
float getLoopImpedance(void);
|
||||
BOOL setLoopImpedance(float loopImpedance);
|
||||
uint16_t getRegistrationStatus(void);
|
||||
void setRegistrationStatus(uint16_t status);
|
||||
|
||||
|
||||
#endif
|
|
@ -10,11 +10,15 @@ void task_Init(void);
|
|||
|
||||
void beginStartControlTask(void);
|
||||
void beginSoftStartTask(void);
|
||||
void beginHYconfigMode(void);
|
||||
void uartTaskInit(void);
|
||||
// void beginHYconfigMode(void);
|
||||
// void uartTaskInit(void);
|
||||
|
||||
void startShortCircuitProtection(void);
|
||||
void stopShortCircuitProtection(void);
|
||||
void startExcessiveLoadProtection(void);
|
||||
void startSoftShortCircuitProtection(void);
|
||||
|
||||
void chargRunLed(uint8_t mode);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -7,9 +7,10 @@
|
|||
#include "uart_dev.h"
|
||||
#include "parameter.h"
|
||||
#include "abnormalManage.h"
|
||||
|
||||
extern int getMPPT_Mode(void);
|
||||
//extern config_parameter g_cfgParameter;
|
||||
#include "pDebug.h"
|
||||
#include "interruptSend.h"
|
||||
#include "FM_RTC.h"
|
||||
#include "SOE.h"
|
||||
|
||||
/**
|
||||
* @brief 初始化外设,同时通过配置文件初始化系统参数
|
||||
|
@ -19,22 +20,38 @@ extern int getMPPT_Mode(void);
|
|||
*/
|
||||
void Init(void)
|
||||
{
|
||||
// HAL_Delay(10000);
|
||||
|
||||
config_info_start();
|
||||
ADC_Capture_Init();
|
||||
proportionalInt(getMPPT_Mode());
|
||||
proportionalInt(g_cfgParameter.powerBoxType);
|
||||
|
||||
g_cfgParameter.firstStageProtectionValue = setfirstStageProtectionValue(g_cfgParameter.firstStageProtectionCurr);
|
||||
|
||||
FM_GPIO_Init();
|
||||
tim_Init();
|
||||
FM_RTC_Init();
|
||||
|
||||
Init_debug_uart();
|
||||
// Init_BAT485_uart(g_cfgParameter.bat485_Baud);
|
||||
// Init_GW485_uart(g_cfgParameter.gw485_Baud);
|
||||
Init_BAT485_uart(115200);
|
||||
Init_GW485_uart(115200);
|
||||
Init_BAT485_uart(g_cfgParameter.bat485_Baud);
|
||||
Init_GW485_uart(g_cfgParameter.gw485_Baud);
|
||||
// Init_BAT485_uart(115200);
|
||||
// Init_GW485_uart(115200);
|
||||
start_gw485Rx_It();
|
||||
start_bat485Rx_It();
|
||||
|
||||
send_init();
|
||||
eventsOrderRecordStartInit();
|
||||
|
||||
// POW_FF_PCON_Open();
|
||||
// POW_OUT_PCON_Open();
|
||||
HAL_Delay(100);
|
||||
setPowerOutput(TRUE);
|
||||
|
||||
// EN_PWMOUT_Eable();
|
||||
// setDutyRatio(0.5);
|
||||
// while (1) {
|
||||
// log_info("Init_debug_uart \n");
|
||||
// HAL_Delay(1000);
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,207 @@
|
|||
|
||||
#include "SOE.h"
|
||||
#include "stdio.h"
|
||||
#include "parameter.h"
|
||||
#include "FM_RTC.h"
|
||||
#include "flash.h"
|
||||
|
||||
#define eventsOrderRecordStartAddr 4096
|
||||
|
||||
typedef struct _soeDataInfo {
|
||||
uint16_t mode; //故障类型 2byte
|
||||
timeInfo time; //时间 6byte
|
||||
float temp; //故障发生时刻的值 4byte
|
||||
} soeDataInfo;
|
||||
#define soeDataInfoSize sizeof(soeDataInfo)
|
||||
|
||||
typedef struct _soeSaveInfo {
|
||||
soeDataInfo data[5];
|
||||
|
||||
uint8_t insertPos; //记录插入数据的位置
|
||||
uint8_t outPos; //记录输出数据的位置
|
||||
uint8_t count; //记录可插入数据插入数据个数
|
||||
soeDataInfo *insertData; //指向能插入数据的位置
|
||||
soeDataInfo *outData; //指向能输出数据的位置
|
||||
} soeSaveInfo;
|
||||
|
||||
typedef struct _soeStorageParameters {
|
||||
uint16_t len; //soe下次记录距离0的偏移量
|
||||
uint16_t pos; //下次soe记录的位置
|
||||
} soeStorageParameters;
|
||||
|
||||
static soeSaveInfo soeInfo = {0};
|
||||
static soeStorageParameters soeParameters = {0};
|
||||
|
||||
/**
|
||||
* @brief 得到一次时间记录的长度
|
||||
* @param
|
||||
*/
|
||||
uint16_t getSoeDataInfoSize(void)
|
||||
{
|
||||
return soeDataInfoSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 初始化事件顺序记录
|
||||
* @param
|
||||
*/
|
||||
void eventsOrderRecordStartInit(void)
|
||||
{
|
||||
read_Flash((uint8_t *)(&soeParameters), eventsOrderRecordStartAddr, sizeof(soeParameters));
|
||||
|
||||
if (soeParameters.len == 0xFFFF && soeParameters.pos == 0xFFFF) {
|
||||
soeParameters.len = 0;
|
||||
soeParameters.pos = eventsOrderRecordStartAddr + sizeof(soeParameters);
|
||||
write_Flash((uint8_t *)(&soeParameters), eventsOrderRecordStartAddr, sizeof(soeParameters));
|
||||
}
|
||||
|
||||
else if (soeParameters.len > 100
|
||||
|| soeParameters.pos != eventsOrderRecordStartAddr + sizeof(soeParameters) + soeParameters.len * soeDataInfoSize) {
|
||||
soeParameters.len = 0;
|
||||
soeParameters.pos = eventsOrderRecordStartAddr + sizeof(soeParameters);
|
||||
write_Flash((uint8_t *)(&soeParameters), eventsOrderRecordStartAddr, sizeof(soeParameters));
|
||||
}
|
||||
|
||||
soeInfo.count = 5;
|
||||
soeInfo.insertPos = 0;
|
||||
soeInfo.outPos = 0;
|
||||
soeInfo.outData = NULL;
|
||||
soeInfo.insertData = &soeInfo.data[soeInfo.insertPos];
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 插入事件顺序记录
|
||||
* @param
|
||||
*/
|
||||
/*
|
||||
| 故障类型 | temp |
|
||||
| :-------------------: | :-------: |
|
||||
| firstStageProtection | 输出电流 |
|
||||
| secondStageProtection | 输出电流 |
|
||||
| thirdStageProtection | 输出电流 |
|
||||
| lowInputLoad | 输出电压 |
|
||||
| overTemperature | mos管温度 |
|
||||
| stopTemperature | mos管温度 |
|
||||
| overchargCurr | 充电电流 |
|
||||
*/
|
||||
void insertEventsOrderRecord(eventsOrderRecordMode mode)
|
||||
{
|
||||
/* 无位置插入时,退出 */
|
||||
if (soeInfo.count <= 0 || soeInfo.insertData == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
soeInfo.count--;
|
||||
soeInfo.insertData->mode = mode;
|
||||
getRTC_Time(&soeInfo.insertData->time);
|
||||
|
||||
if (mode == firstStageProtection) {
|
||||
soeInfo.insertData->temp = getDischargCurrent();
|
||||
}
|
||||
|
||||
else if (mode == secondStageProtection) {
|
||||
soeInfo.insertData->temp = getDischargCurrent();
|
||||
}
|
||||
|
||||
else if (mode == thirdStageProtection) {
|
||||
soeInfo.insertData->temp = getDischargCurrent();
|
||||
}
|
||||
|
||||
else if (mode == lowInputLoad) {
|
||||
soeInfo.insertData->temp = getOutputVoltage();
|
||||
}
|
||||
|
||||
else if (mode == overTemperature) {
|
||||
soeInfo.insertData->temp = getHighSideMosTemperature();
|
||||
}
|
||||
|
||||
else if (mode == stopTemperature) {
|
||||
soeInfo.insertData->temp = getHighSideMosTemperature();
|
||||
}
|
||||
|
||||
else if (mode == overchargCurr) {
|
||||
soeInfo.insertData->temp = getChargCurrent();
|
||||
}
|
||||
|
||||
else if (mode == overInputVolt) {
|
||||
soeInfo.insertData->temp = getSolarInCircuitVoltage();
|
||||
}
|
||||
|
||||
else {
|
||||
soeInfo.count++;
|
||||
return;
|
||||
}
|
||||
|
||||
soeInfo.insertPos++;
|
||||
if (soeInfo.insertPos >= 5) {
|
||||
soeInfo.insertPos = 0;
|
||||
}
|
||||
|
||||
if (soeInfo.count <= 0) {
|
||||
soeInfo.insertData = NULL;
|
||||
} else {
|
||||
soeInfo.insertData = &soeInfo.data[soeInfo.insertPos];
|
||||
}
|
||||
|
||||
soeInfo.outData = &soeInfo.data[soeInfo.outPos];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 将事件顺序记录在flash中
|
||||
* @param
|
||||
*/
|
||||
void setEventsOrderRecord(void)
|
||||
{
|
||||
if (soeInfo.outData == NULL || soeInfo.count >= 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
write_Flash((uint8_t *)(&soeInfo.outData), soeParameters.pos, soeDataInfoSize);
|
||||
|
||||
soeParameters.len++;
|
||||
if (soeParameters.len >= 100) {
|
||||
soeParameters.len = 0;
|
||||
}
|
||||
soeParameters.pos += soeDataInfoSize;
|
||||
write_Flash((uint8_t *)(&soeParameters), eventsOrderRecordStartAddr, sizeof(soeStorageParameters));
|
||||
|
||||
soeInfo.outPos++;
|
||||
if (soeInfo.outPos >= 5) {
|
||||
soeInfo.outPos = 0;
|
||||
}
|
||||
soeInfo.count++;
|
||||
|
||||
if (soeInfo.count >= 5) {
|
||||
soeInfo.outData = NULL;
|
||||
} else {
|
||||
soeInfo.outData = &soeInfo.data[soeInfo.outPos];
|
||||
}
|
||||
|
||||
if (soeInfo.insertData == NULL) {
|
||||
soeInfo.insertData = &soeInfo.data[soeInfo.insertPos];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 将事件从flash中依次读取出来
|
||||
* @param offset : 距离下次写入数据的偏移量
|
||||
* *data : 数据的储存位置
|
||||
*/
|
||||
|
||||
void readEventsOrderRecord(uint16_t offset, uint8_t *data)
|
||||
{
|
||||
uint16_t addr;
|
||||
|
||||
if (soeParameters.len + 1 - offset < 0) {
|
||||
addr = eventsOrderRecordStartAddr + sizeof(soeStorageParameters)
|
||||
+ (100 + soeParameters.len + 1 - offset) * soeDataInfoSize;
|
||||
} else {
|
||||
addr = eventsOrderRecordStartAddr + sizeof(soeStorageParameters)
|
||||
+ (soeParameters.len + 1 - offset) * soeDataInfoSize;
|
||||
}
|
||||
|
||||
read_Flash(data, addr, soeDataInfoSize);
|
||||
}
|
||||
|
||||
|
|
@ -5,8 +5,12 @@
|
|||
#include "checkTime.h"
|
||||
#include "FM_GPIO.h"
|
||||
#include "task.h"
|
||||
#include "configParameter.h"
|
||||
#include "capture.h"
|
||||
#include "bl_chargControl.h"
|
||||
#include "SOE.h"
|
||||
|
||||
|
||||
//static int checkMode = 0;
|
||||
|
||||
/* 软件输出过载标志位 */
|
||||
static BOOL disChargOverLoad = FALSE;
|
||||
|
@ -18,22 +22,110 @@ static BOOL shortCircuitFlag = FALSE;
|
|||
/* 硬件过载状态位 */
|
||||
static uint8_t excessiveLoad = 0;
|
||||
static BOOL excessiveLoadFlag = FALSE;
|
||||
|
||||
static BOOL excessiveLoadInterruptFlag = FALSE;
|
||||
|
||||
/**
|
||||
* @brief 设定放电过载状态
|
||||
* @param state TRUE 过载
|
||||
* FALSE 未过载
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void setDisChargOverLoad(void)
|
||||
{
|
||||
if (getDischargCurrent() > 30.0f) {
|
||||
disChargOverLoad = TRUE;
|
||||
/* 三段式保护中的第三段 */
|
||||
static int num1 = 0;
|
||||
if (getDischargCurrent() > g_cfgParameter.thirdStageProtectionCurr) {
|
||||
// disChargOverLoad = TRUE;
|
||||
num1++;
|
||||
} else {
|
||||
disChargOverLoad = FALSE;
|
||||
// disChargOverLoad = FALSE;
|
||||
num1 = 0;
|
||||
}
|
||||
|
||||
/* 过载时间过长关闭输出 */
|
||||
if (num1 >= g_cfgParameter.thirdStageProtectionDelay) {
|
||||
num1 = 0;
|
||||
setPowerOutput(FALSE);
|
||||
disChargOverLoad = TRUE;
|
||||
insertEventsOrderRecord(thirdStageProtection);
|
||||
}
|
||||
|
||||
|
||||
/* 三段式保护中的第二段 */
|
||||
static int num2 = 0;
|
||||
if (getDischargCurrent() > g_cfgParameter.secondStageProtectionCurr) {
|
||||
num2++;
|
||||
} else {
|
||||
num2 = 0;
|
||||
}
|
||||
|
||||
/* 过载时间过长关闭输出 */
|
||||
if (num2 >= g_cfgParameter.secondStageProtectionDelay) {
|
||||
num2 = 0;
|
||||
setPowerOutput(FALSE);
|
||||
disChargOverLoad = TRUE;
|
||||
insertEventsOrderRecord(secondStageProtection);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 软件短路保护
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void setSoftShortCircuit(uint16_t disChargCurrAdcNum)
|
||||
{
|
||||
// /* 三段式保护中的第一段 */
|
||||
// static int num = 0;
|
||||
// if (getDischargCurrent() > firstStageProtectionCurr) {
|
||||
// num++;
|
||||
// } else {
|
||||
// num = 0;
|
||||
// }
|
||||
|
||||
/* 三段式保护中的第一段 */
|
||||
static int num = 0;
|
||||
if (disChargCurrAdcNum > g_cfgParameter.firstStageProtectionValue) {
|
||||
num++;
|
||||
} else {
|
||||
num = 0;
|
||||
}
|
||||
|
||||
/* 20uS内都短路则关闭输出 */
|
||||
if (num >= g_cfgParameter.firstStageProtectionDelay) {
|
||||
setPowerOutput(FALSE);
|
||||
shortCircuitFlag = TRUE;
|
||||
shortCircuit++;
|
||||
insertEventsOrderRecord(firstStageProtection);
|
||||
startSoftShortCircuitProtection();
|
||||
}
|
||||
}
|
||||
void setSoftShortCircuit1(void)
|
||||
{
|
||||
// /* 三段式保护中的第一段 */
|
||||
// static int num = 0;
|
||||
// if (getDischargCurrent() > firstStageProtectionCurr) {
|
||||
// num++;
|
||||
// } else {
|
||||
// num = 0;
|
||||
// }
|
||||
|
||||
// /* 三段式保护中的第一段 */
|
||||
// static int num = 0;
|
||||
// if (getDischargCurrent() > firstStageProtectionCurr) {
|
||||
// num++;
|
||||
// } else {
|
||||
// num = 0;
|
||||
// }
|
||||
|
||||
// /* 200uS内都短路则关闭输出 */
|
||||
// if (num >= firstStageProtectionDelay) {
|
||||
// setPowerOutput(FALSE);
|
||||
// shortCircuitFlag = TRUE;
|
||||
// shortCircuit++;
|
||||
// startSoftShortCircuitProtection();
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -91,8 +183,7 @@ void setShortCircuitFlag(BOOL state)
|
|||
{
|
||||
if (state == TRUE || state == FALSE) {
|
||||
shortCircuitFlag = state;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -150,8 +241,7 @@ void setExcessiveLoadFlag(BOOL state)
|
|||
{
|
||||
if (state == TRUE || state == FALSE) {
|
||||
excessiveLoadFlag = state;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,9 +263,16 @@ BOOL getExcessiveLoadFlag(void)
|
|||
*/
|
||||
void setPowerOutput(BOOL state)
|
||||
{
|
||||
// static volatile float temp_OUT_VOLT_IN;
|
||||
// static volatile float temp_PV_VOLT_OUT;
|
||||
// temp_PV_VOLT_OUT = get_PV_VOLT_OUT();
|
||||
// temp_OUT_VOLT_IN = get_OUT_VOLT_IN();
|
||||
if (state == TRUE) {
|
||||
POW_FF_PCON_Open();
|
||||
POW_OUT_PCON_Open();
|
||||
// if (get_OUT_VOLT_IN() < (get_PV_VOLT_OUT() - 0.1f)) {
|
||||
// if (temp_OUT_VOLT_IN < (temp_PV_VOLT_OUT - 0.5f)) {
|
||||
POW_FF_PCON_Open();
|
||||
POW_OUT_PCON_Open();
|
||||
// }
|
||||
} else {
|
||||
POW_FF_PCON_Close();
|
||||
POW_OUT_PCON_Close();
|
||||
|
@ -191,16 +288,102 @@ BOOL getExcessiveLoadFlag(void)
|
|||
*/
|
||||
void checkFFMOS_CON(void)
|
||||
{
|
||||
if (get_CHG_CURR() > 2.0f) {
|
||||
// if (get_CHG_CURR() > 5.0f && FALSE == FFMOS_CON_read()) {
|
||||
// FFMOS_CON_Open();
|
||||
// }
|
||||
// else if (get_CHG_CURR() < 2.0f && TRUE == FFMOS_CON_read()) {
|
||||
// FFMOS_CON_Close();
|
||||
// }
|
||||
|
||||
if (getChargCurrent() > 5.0f && FALSE == FFMOS_CON_read()) {
|
||||
FFMOS_CON_Open();
|
||||
}
|
||||
else if (get_CHG_CURR() < 1.0f) {
|
||||
else if (getChargCurrent() < 2.0f && TRUE == FFMOS_CON_read()) {
|
||||
FFMOS_CON_Close();
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @brief 判断是否短路
|
||||
// * @param
|
||||
// * @retval
|
||||
// *
|
||||
// */
|
||||
// void checkShortCircuit(void)
|
||||
// {
|
||||
// static num = 0;
|
||||
// if (getChargCurrent() > 50.0f) {
|
||||
// num++;
|
||||
// } else {
|
||||
// num = 0;
|
||||
// }
|
||||
|
||||
// if (num == g_cfgParameter.softShortTime) {
|
||||
// setPowerOutput(FALSE);
|
||||
// }
|
||||
|
||||
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 输入功率过低保护
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void setOverLoad(void)
|
||||
{
|
||||
setPowerOutput(FALSE);
|
||||
setExcessiveLoad();
|
||||
/* 第一次进入输出过载,启动过载保护任务 */
|
||||
if (getExcessiveLoad() == 1) {
|
||||
setExcessiveLoadFlag(TRUE);
|
||||
startExcessiveLoadProtection();
|
||||
}
|
||||
|
||||
/* 多次进入输出过载,关闭输出 */
|
||||
if (getExcessiveLoad() > 2) {
|
||||
zeroExcessiveLoad();
|
||||
insertEventsOrderRecord(lowInputLoad);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 判断是否输入功率过低
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void lowInputLoadDetection(void)
|
||||
{
|
||||
static int num = 0;
|
||||
|
||||
if (excessiveLoadInterruptFlag == TRUE && getOutputVoltage() < g_cfgParameter.inputPowerLowDetectionVolt) {
|
||||
num++;
|
||||
} else {
|
||||
num = 0;
|
||||
excessiveLoadInterruptFlag = FALSE;
|
||||
}
|
||||
|
||||
if (excessiveLoadInterruptFlag == TRUE && num == g_cfgParameter.inputPowerLowDetectionDelay) {
|
||||
setOverLoad();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 判断充电电流是否过高,过高则关闭充电
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void judgeChargCurr(void)
|
||||
{
|
||||
if (getChargCurrent() > g_cfgParameter.maxChargCurr) {
|
||||
stopChargWork();
|
||||
insertEventsOrderRecord(overchargCurr);
|
||||
}
|
||||
}
|
||||
|
||||
void checkAbnormal(void)
|
||||
{
|
||||
|
@ -216,9 +399,12 @@ void checkAbnormal(void)
|
|||
|
||||
/* 判断 */
|
||||
checkFFMOS_CON();
|
||||
setDisChargOverLoad();
|
||||
|
||||
setDisChargOverLoad();
|
||||
setSoftShortCircuit1();
|
||||
lowInputLoadDetection();
|
||||
judgeChargCurr();
|
||||
|
||||
|
||||
|
||||
// checkAbnormalTime = getCheckTime();
|
||||
}
|
||||
|
@ -231,18 +417,19 @@ void checkAbnormal(void)
|
|||
*/
|
||||
void WORK_VOLT_Interrupt(void)
|
||||
{
|
||||
setExcessiveLoad();
|
||||
/* 第一次进入输出过载,启动过载保护任务 */
|
||||
if (getExcessiveLoad() == 1) {
|
||||
setExcessiveLoadFlag(TRUE);
|
||||
startExcessiveLoadProtection();
|
||||
}
|
||||
// setPowerOutput(FALSE);
|
||||
// setExcessiveLoad();
|
||||
// /* 第一次进入输出过载,启动过载保护任务 */
|
||||
// if (getExcessiveLoad() == 1) {
|
||||
// setExcessiveLoadFlag(TRUE);
|
||||
// startExcessiveLoadProtection();
|
||||
// }
|
||||
|
||||
/* 多次进入输出过载,关闭输出 */
|
||||
if (getExcessiveLoad() > 2) {
|
||||
zeroExcessiveLoad();
|
||||
setPowerOutput(FALSE);
|
||||
}
|
||||
// /* 多次进入输出过载,关闭输出 */
|
||||
// if (getExcessiveLoad() > 2) {
|
||||
// zeroExcessiveLoad();
|
||||
// }
|
||||
excessiveLoadInterruptFlag = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -258,7 +445,7 @@ void DSG_PROT_Interrupt(void)
|
|||
if (getShortCircuit() == 1) {
|
||||
setShortCircuitFlag(TRUE);
|
||||
startShortCircuitProtection();
|
||||
}
|
||||
}
|
||||
|
||||
/* 一定时间内第二次进入输出短路保护,关闭输出 */
|
||||
else if (getShortCircuit() >= 2) {
|
||||
|
|
|
@ -22,10 +22,24 @@ static void chargControlMode(void);
|
|||
static void BatteryChargControl(void);
|
||||
static void noBatteryChargControl(void);
|
||||
|
||||
static void setPIControlStep(float *PI_step);
|
||||
|
||||
|
||||
static BOOL chargControlFlag = FALSE;
|
||||
// static BOOL getChargControlFlag(void);
|
||||
void setChargControlFlag(BOOL state);
|
||||
|
||||
void setPIControlStep(float *PI_step)
|
||||
{
|
||||
if (*PI_step > PI_CONTROL_MAX) {
|
||||
*PI_step = PI_CONTROL_MAX;
|
||||
}
|
||||
|
||||
else if (*PI_step < PI_CONTROL_MIN) {
|
||||
*PI_step = PI_CONTROL_MIN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 恒定输入电压
|
||||
* @param InVoltage 需要控制到的输入电压
|
||||
|
@ -40,13 +54,19 @@ void mppt_constantVoltage(float InVoltage)
|
|||
static float error;
|
||||
static float stepPwm;
|
||||
|
||||
|
||||
// solarInCircuitVoltage = getSolarInCircuitVoltage();
|
||||
// error = InVoltage - getSolarInCircuitVoltage();
|
||||
error = getSolarInCircuitVoltage() - InVoltage;
|
||||
stepPwm = kp * error + ki * getSolarInCircuitVoltage();
|
||||
|
||||
setPIControlStep(&stepPwm);
|
||||
|
||||
setDutyRatio((getDutyRatio() + stepPwm));
|
||||
// if (getMosTemperState() == mosTemperEnd) {
|
||||
// setDutyRatio((getDutyRatio() + stepPwm - 0.1));
|
||||
// } else {
|
||||
// setDutyRatio((getDutyRatio() + stepPwm));
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -66,7 +86,8 @@ void mppt_constantVoltageNoBatteryO(float OutVoltage)
|
|||
outVolt = getOutputVoltage();
|
||||
error = OutVoltage - outVolt;
|
||||
stepPwm = kp * error + ki * outVolt;
|
||||
|
||||
setPIControlStep(&stepPwm);
|
||||
|
||||
setDutyRatio((getDutyRatio() + stepPwm));
|
||||
}
|
||||
|
||||
|
@ -90,11 +111,17 @@ void mppt_constantVoltageO(float OutVoltage)
|
|||
outVolt = getOutputVoltage();
|
||||
error = OutVoltage - outVolt;
|
||||
StepPwm = kp * error + ki * outVolt;
|
||||
setPIControlStep(&StepPwm);
|
||||
|
||||
/* 当有电池时,输出电压的曲线是先上升后下降 */
|
||||
if (lastDutyRatio >= getDutyRatio()) {
|
||||
// if (lastVolt >= outVolt) {
|
||||
setDutyRatio((getDutyRatio() + StepPwm));
|
||||
// if (getMosTemperState() == mosTemperEnd) {
|
||||
// setDutyRatio((getDutyRatio() + StepPwm - 0.1));
|
||||
// } else {
|
||||
// setDutyRatio((getDutyRatio() + StepPwm));
|
||||
// }
|
||||
// } else {
|
||||
// g_controlParameter.dutyRatio -= StepPwm;
|
||||
// }
|
||||
|
@ -104,7 +131,12 @@ void mppt_constantVoltageO(float OutVoltage)
|
|||
// } else {
|
||||
// g_controlParameter.dutyRatio += StepPwm;
|
||||
// }
|
||||
setDutyRatio((getDutyRatio() - StepPwm));
|
||||
setDutyRatio((getDutyRatio() - StepPwm));
|
||||
// if (getMosTemperState() == mosTemperEnd) {
|
||||
// setDutyRatio((getDutyRatio() + StepPwm - 0.1));
|
||||
// } else {
|
||||
// setDutyRatio((getDutyRatio() + StepPwm));
|
||||
// }
|
||||
}
|
||||
|
||||
// lastVolt = outVolt;
|
||||
|
@ -303,9 +335,21 @@ void mppt_readJust(void)
|
|||
|
||||
/* 调节电压,两个电压步调节 */
|
||||
static float Power = 0;
|
||||
Power = getOutputVoltage() * getChargCurrent();
|
||||
static float totalPower = 0;
|
||||
static float powerData[50] = {0};
|
||||
static uint8_t powerIndex = 0;
|
||||
|
||||
/* 获取50次的平均值 */
|
||||
totalPower -= powerData[powerIndex];
|
||||
powerData[powerIndex] = getOutputVoltage() * getChargCurrent();
|
||||
totalPower += powerData[powerIndex];
|
||||
powerIndex++;
|
||||
if (powerIndex >= 50) {
|
||||
powerIndex = 0;
|
||||
}
|
||||
|
||||
static float lPower = 0;
|
||||
// static float lLPower = 0;
|
||||
static float lLPower = 0;
|
||||
// static float lLLPower = 0;
|
||||
|
||||
static float SolarInCircuitV = 17; //控制太阳能板的输出电压稳定在该值,初始为17V
|
||||
|
@ -320,7 +364,7 @@ void mppt_readJust(void)
|
|||
/* 延时一段时间才判断 */
|
||||
static uint16_t flag = 0;
|
||||
flag++;
|
||||
if (flag < 50) {
|
||||
if (flag < 200) {
|
||||
// float pv1Volt = getSolarInCircuitVoltage();
|
||||
// float error = pv1Volt - SolarInCircuitV;
|
||||
// float stepPwm = kp * error + ki * pv1Volt;
|
||||
|
@ -332,7 +376,14 @@ void mppt_readJust(void)
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
if (getMosTemperState() == mosTemperReduce) {
|
||||
SolarInCircuitV = 16;
|
||||
}
|
||||
|
||||
|
||||
flag = 0;
|
||||
Power = totalPower / 50.0f;
|
||||
|
||||
static float powerT = 0;
|
||||
powerT = Power - lPower;
|
||||
|
@ -340,9 +391,9 @@ void mppt_readJust(void)
|
|||
powerT = -powerT;
|
||||
}
|
||||
|
||||
// if ((lPower + 0.7 < Power) && (lLPower + 0.7 < Power) && (lLLPower + 0.7 < Power)) {
|
||||
// if ((lPower + 0.7 < Power) && (lLPower + 0.7 < Power)) {
|
||||
if ((lPower + 1.0f < Power)) {
|
||||
// if ((lPower + 0.8f < Power) && (lLPower + 0.8f < Power) && (lLLPower + 0.8f < Power)) {
|
||||
if ((lPower + 0.1f < Power) && (lLPower + 0.1f < Power)) {
|
||||
// if ((lPower + 0.3f < Power)) {
|
||||
if (powerT > 5) {
|
||||
if (flag1) {
|
||||
SolarInCircuitV += stepV1;
|
||||
|
@ -360,9 +411,9 @@ void mppt_readJust(void)
|
|||
flag1 = 0;
|
||||
}
|
||||
}
|
||||
// } else if ((lPower - 0.7 > Power) && (lLPower - 0.7 > Power) && (lLLPower - 0.7 > Power)) {
|
||||
// } else if ((lPower - 0.7 > Power) && (lLPower - 0.7 > Power)) {
|
||||
} else if ((lPower - 1.0f > Power)) {
|
||||
// } else if ((lPower - 0.8f > Power) && (lLPower - 0.8f > Power) && (lLLPower - 0.8f > Power)) {
|
||||
} else if ((lPower - 0.1f > Power) && (lLPower - 0.1f > Power)) {
|
||||
// } else if ((lPower - 0.3f > Power)) {
|
||||
if (powerT > 5) {
|
||||
if (flag1) {
|
||||
SolarInCircuitV -= stepV1;
|
||||
|
@ -389,6 +440,8 @@ void mppt_readJust(void)
|
|||
SolarInCircuitV = 16.0f;
|
||||
}
|
||||
|
||||
// lLLPower = lLPower;
|
||||
lLPower = lPower;
|
||||
lPower = Power;
|
||||
}
|
||||
|
||||
|
@ -442,7 +495,6 @@ void startChargWork(void)
|
|||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 判断达到停止充电的条件
|
||||
* @param
|
||||
|
@ -450,12 +502,12 @@ void startChargWork(void)
|
|||
* FALSE 未达到
|
||||
*
|
||||
*/
|
||||
BOOL stopChargConditions(void)
|
||||
BOOL stopChargConditions(void)
|
||||
{
|
||||
if (getSolarInCircuitVoltage() < g_cfgParameter.stopSolarOpenCircuitV
|
||||
&& getChargCurrent() < 0.1f) {
|
||||
return TRUE;
|
||||
}
|
||||
if (getSolarInCircuitVoltage() < g_cfgParameter.stopSolarOutputCircuitV
|
||||
&& getChargCurrent() < 1) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -502,8 +554,8 @@ BOOL mpptChargConditions(void)
|
|||
*/
|
||||
BOOL constantVChargConditions(void)
|
||||
{
|
||||
if ((g_cfgParameter.constantVoltageChargeV < getBatteryVoltage())
|
||||
&& ((g_cfgParameter.floatI + 0.1f) <= getChargBatteryCurrent())) {
|
||||
if ((g_cfgParameter.constantVoltageV < getBatteryVoltage())
|
||||
&& ((g_cfgParameter.floatI + 0.1f) <= getChargBatteryCurrent())) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -522,23 +574,27 @@ void chargControlMode(void)
|
|||
endChargWork();
|
||||
}
|
||||
|
||||
if (floatChargConditions()) {
|
||||
else if (getBatteryState() == FALSE) {
|
||||
setMPPT_Mode(noBattery);
|
||||
}
|
||||
|
||||
else if (floatChargConditions()) {
|
||||
setMPPT_Mode(floatCharg);
|
||||
}
|
||||
|
||||
if (mpptChargConditions()) {
|
||||
setMPPT_Mode(MPPT);
|
||||
}
|
||||
|
||||
if (constantVChargConditions()) {
|
||||
else if (constantVChargConditions()) {
|
||||
setMPPT_Mode(constantVoltage);
|
||||
}
|
||||
|
||||
else if (mpptChargConditions()) {
|
||||
setMPPT_Mode(MPPT);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 判断有无电池
|
||||
* @param
|
||||
* @retval
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void judgeYNBattery(void)
|
||||
|
@ -561,7 +617,7 @@ void judgeYNBattery(void)
|
|||
*/
|
||||
void noBatteryChargControl(void)
|
||||
{
|
||||
mppt_constantVoltageNoBatteryO(g_cfgParameter.FloatV);
|
||||
mppt_constantVoltageNoBatteryO(g_cfgParameter.FloatChargeV);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -594,7 +650,7 @@ void constantVoltageCharge(void)
|
|||
*/
|
||||
void floatCharge(void)
|
||||
{
|
||||
mppt_constantVoltageO(g_cfgParameter.FloatV);
|
||||
mppt_constantVoltageO(g_cfgParameter.FloatChargeV);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -643,7 +699,13 @@ void setChargControlFlag(BOOL state)
|
|||
{
|
||||
if (state == TRUE || state == FALSE) {
|
||||
chargControlFlag = state;
|
||||
}
|
||||
}
|
||||
|
||||
if (state == TRUE) {
|
||||
chargRunLed(runLedChargMode);
|
||||
} else if (state == FALSE) {
|
||||
chargRunLed(runLedOtherMode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,25 +1,11 @@
|
|||
|
||||
#include "bl_comm.h"
|
||||
#include "uart_dev.h"
|
||||
|
||||
#include "interruptSend.h"
|
||||
|
||||
uint8_t rs485_buff[buffLen]={0x00};
|
||||
|
||||
|
||||
|
||||
void GW485_comm(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void BAT485_comm(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief gw485串口接收中断回调函数
|
||||
* @param
|
||||
|
@ -30,7 +16,8 @@ void gw485_RxIt(void)
|
|||
{
|
||||
// uart_device_info *dev = (uart_device_info *)g_gw485_uart2_handle;
|
||||
// if(!RingQueueFull(&dev->uart_ring_queue))
|
||||
// InRingQueue(&dev->uart_ring_queue, rx_gw485_buf[0]);
|
||||
// InRingQueue(&dev->uart_ring_queue, rx_gw485_buf[0]);
|
||||
setIdleStateGw();
|
||||
|
||||
uint8_t c = 0;
|
||||
c = rx_gw485_buf[0];
|
||||
|
@ -50,9 +37,39 @@ void gw485_RxIt(void)
|
|||
*/
|
||||
void bat485_RxIt(void)
|
||||
{
|
||||
setIdleStateBat();
|
||||
|
||||
uint8_t c = 0;
|
||||
c = rx_bat485_buf[0];
|
||||
|
||||
uart_device_info *dev = (uart_device_info *)g_bat485_uart3_handle;
|
||||
if(!RingQueueFull(&dev->uart_ring_queue))
|
||||
InRingQueue(&dev->uart_ring_queue, rx_bat485_buf[0]);
|
||||
InRingQueue(&dev->uart_ring_queue, c);
|
||||
|
||||
start_bat485Rx_It();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief gw485串口中断发送回调函数
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void gw485_TxIt(void)
|
||||
{
|
||||
setSendOverStateGw();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief bat485串口中断发送回调函数
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void bat485_TxIt(void)
|
||||
{
|
||||
setSendOverStateBat();
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,420 +0,0 @@
|
|||
|
||||
#include "cfg_protocol.h"
|
||||
#include "uart_dev.h"
|
||||
#include "inFlash.h"
|
||||
#include "parameter.h"
|
||||
#include "string.h"
|
||||
#include "chargControlEnum.h"
|
||||
#include "pDebug.h"
|
||||
|
||||
#define cfgBuffLen 200
|
||||
static uint8_t configBuff[cfgBuffLen];
|
||||
static uint8_t cfigLen = 0;
|
||||
|
||||
/* 配置文件中的部分数据放大倍数 */
|
||||
#define enlargeScale 100
|
||||
|
||||
/**
|
||||
* @brief 向配置文件buff中存入一个数据
|
||||
* @param c 数据
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void inConfigBuff(uint8_t c)
|
||||
{
|
||||
if (cfigLen < cfgBuffLen) {
|
||||
configBuff[cfigLen] = c;
|
||||
cfigLen++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 向配置文件buff中丢掉一个数据
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void outConfigBuff(void)
|
||||
{
|
||||
if (cfigLen > 0) {
|
||||
cfigLen--;
|
||||
memcpy(configBuff, configBuff + 1, cfigLen);
|
||||
// memcpy(configBuff, configBuff + 1, sizeof(configBuff) - 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief modbus的crc校验
|
||||
* @param *arr_buff 需要校验的数据
|
||||
* len 数据长度
|
||||
* @retval crc 校验的结果
|
||||
*/
|
||||
uint16_t checkModebusCrc(uint8_t *arr_buff, uint8_t len)
|
||||
{
|
||||
uint16_t crc = 0xFFFF;
|
||||
uint16_t i, j;
|
||||
for (j = 0; j < len; ++j) {
|
||||
crc = crc ^ (*arr_buff++);
|
||||
for (i = 0; i < 8; ++i) {
|
||||
if ((crc&0x0001) > 0) {
|
||||
crc = crc >> 1;
|
||||
crc = crc ^ 0xa001;
|
||||
}
|
||||
else {
|
||||
crc = crc >> 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return crc;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 清空配置文件buff
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void zeroConfigBuff(void)
|
||||
{
|
||||
cfigLen = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 判断接收到的配置文件数据是否正确,正确的话存入flash中
|
||||
* @param None
|
||||
* @retval None
|
||||
*
|
||||
*/
|
||||
void read_and_process_config_data(void)
|
||||
{
|
||||
recv_config_info *pack = (recv_config_info *)configBuff;
|
||||
static config_info save_configInfo;
|
||||
while (cfigLen >= RECV_CONFIG_INFO) {
|
||||
/* 判断起始标志是否正确 */
|
||||
debug_printf(" start_Flag : 0x%x, 0x%x \n", pack->start_Flag[0], pack->start_Flag[1]);
|
||||
if (pack->start_Flag[0] != g_cfgParameter.startFlagSL[0]
|
||||
|| pack->start_Flag[1] != g_cfgParameter.startFlagSL[1]) {
|
||||
// debug(" start_Flag : 0x%x, 0x%x \n", pack->start_Flag[0], pack->start_Flag[1]);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// /* 判断接入节点类型是否正确 */
|
||||
// save_configInfo.Access_Node_Type = (uint16_t)pack->Access_Node_Type[0] << 8
|
||||
// | (uint16_t)pack->Access_Node_Type[1];
|
||||
// if (save_configInfo.Access_Node_Type != POWERBOX) {
|
||||
// // debug(" Access_Node_Type : 0x%x \n", save_configInfo.Access_Node_Type);
|
||||
// goto err;
|
||||
// }
|
||||
|
||||
// /* 判断通信方式是否正确 */
|
||||
// save_configInfo.Communication_Methods = (uint16_t)pack->Communication_Methods[0] << 8
|
||||
// | (uint16_t)pack->Communication_Methods[1];
|
||||
// // if (temp_u16 != RS485 || temp_u16 != RJ45) {
|
||||
// if (save_configInfo.Communication_Methods != RS485) {
|
||||
// debug(" Communication_Methods : 0x%x \n", save_configInfo.Communication_Methods);
|
||||
// goto err;
|
||||
// }
|
||||
|
||||
/* 判断波特率是否正确 */
|
||||
save_configInfo.gw485_Baud = (uint32_t)pack->gw485_Baud[0] << 24
|
||||
| (uint32_t)pack->gw485_Baud[1] << 16
|
||||
| (uint32_t)pack->gw485_Baud[2] << 8
|
||||
| (uint32_t)pack->gw485_Baud[3];
|
||||
// debug(" gw485_Baud : 0x%x, %d \n", save_configInfo.gw485_Baud, save_configInfo.gw485_Baud);
|
||||
if (save_configInfo.gw485_Baud != 9600
|
||||
&& save_configInfo.gw485_Baud != 115200) {
|
||||
// debug(" gw485_Baud : %d\n", save_configInfo.gw485_Baud);
|
||||
goto err;
|
||||
}
|
||||
|
||||
save_configInfo.bat485_Baud = (uint32_t)pack->bat485_Baud[0] << 24
|
||||
| (uint32_t)pack->bat485_Baud[1] << 16
|
||||
| (uint32_t)pack->bat485_Baud[2] << 8
|
||||
| (uint32_t)pack->bat485_Baud[3];
|
||||
if (save_configInfo.bat485_Baud != 9600
|
||||
&& save_configInfo.bat485_Baud!= 115200
|
||||
&& save_configInfo.bat485_Baud!= 0) {
|
||||
// debug(" bat485_Baud : 0x%x, %d \n", save_configInfo.bat485_Baud, save_configInfo.bat485_Baud);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断汇源协议类型是否正确 */
|
||||
if (pack->protocolType != 0x01 && pack->protocolType != 0x02) {
|
||||
// debug(" protocolType : 0x%x \n", pack->protocolType);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断通信协议类型是否正确 */
|
||||
if (pack->CommunicationProtocolType != 0x00
|
||||
&& pack->CommunicationProtocolType != 0x01) {
|
||||
// debug(" CommunicationProtocolType : 0x%x \n", pack->CommunicationProtocolType);
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
/* 判断电源盒类型是否正确 */
|
||||
if (pack->onlyPower != 0x00 && pack->onlyPower != 0x01) {
|
||||
// debug(" onlyPower : 0x%x \n", pack->onlyPower);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断恒压充电阈值是否正确 */
|
||||
save_configInfo.constantVoltageV =
|
||||
(float)(pack->ConstantVoltageV[0] << 8 | pack->ConstantVoltageV[1]) / enlargeScale;
|
||||
if (!((save_configInfo.constantVoltageV < 14.4f && save_configInfo.constantVoltageV > 13.5f)
|
||||
|| save_configInfo.constantVoltageV == 0)) {
|
||||
// debug(" constantVoltageV : %f \n", save_configInfo.constantVoltageV);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断浮充充电阈值是否正确 */
|
||||
save_configInfo.floatI = (float)(pack->FloatI[0] << 8 | pack->FloatI[1]) / enlargeScale;
|
||||
if (save_configInfo.floatI > 0.2f || save_configInfo.floatI < 0) {
|
||||
// debug(" floatI : %f \n", save_configInfo.floatI);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断太阳能板开路启动电压是否正确 */
|
||||
save_configInfo.startSolarOpenCircuitV =
|
||||
(float)(pack->startSolarOpenCircuitV[0] << 8 | pack->startSolarOpenCircuitV[1]) / enlargeScale;
|
||||
if (!((save_configInfo.startSolarOpenCircuitV < 24 && save_configInfo.startSolarOpenCircuitV > 14)
|
||||
|| save_configInfo.startSolarOpenCircuitV == 0)) {
|
||||
// debug(" startSolarOpenCircuitV : %f \n", save_configInfo.startSolarOpenCircuitV);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断太阳能板关闭电压是否正确 */
|
||||
save_configInfo.stopSolarOpenCircuitV =
|
||||
(float)(pack->stopSolarOpenCircuitV[0] << 8 | pack->stopSolarOpenCircuitV[1]) / enlargeScale;
|
||||
if (!((save_configInfo.stopSolarOpenCircuitV > 17 && save_configInfo.stopSolarOpenCircuitV < 13)
|
||||
|| save_configInfo.stopSolarOpenCircuitV == 0)) {
|
||||
// debug(" stopSolarOpenCircuitV : %f \n", save_configInfo.stopSolarOpenCircuitV);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断恒压充电时的输出电压是否正确 */
|
||||
save_configInfo.constantVoltageChargeV =
|
||||
(float)(pack->constantVoltageChargeV[0] << 8 | pack->constantVoltageChargeV[1]) / enlargeScale;
|
||||
if (!((save_configInfo.constantVoltageChargeV < 14.6f && save_configInfo.constantVoltageChargeV > 14)
|
||||
|| save_configInfo.constantVoltageChargeV == 0)) {
|
||||
// debug(" constantVoltageChargeV : %f \n", save_configInfo.constantVoltageChargeV);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断浮充充电时的输出电压是否正确 */
|
||||
save_configInfo.FloatChargeV =
|
||||
(float)(pack->FloatChargeV[0] << 8 | pack->FloatChargeV[1]) / enlargeScale;
|
||||
if (!((save_configInfo.FloatChargeV < 14.4f && save_configInfo.FloatChargeV > 13.8f)
|
||||
|| save_configInfo.FloatChargeV == 0)) {
|
||||
// debug(" FloatChargeV : %f \n", save_configInfo.FloatChargeV);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断mos管停止工作温度是否正确 */
|
||||
save_configInfo.HighSideMosTemperature_stop =
|
||||
(float)(pack->HighSideMosTemperature_stop[0] << 8 | pack->HighSideMosTemperature_stop[1]) / enlargeScale;
|
||||
if (save_configInfo.HighSideMosTemperature_stop < 50 && save_configInfo.HighSideMosTemperature_stop != 0) {
|
||||
// debug(" HighSideMosTemperature_stop : %f \n", save_configInfo.HighSideMosTemperature_stop);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断mos管降低工作功率工作温度是否正确 */
|
||||
save_configInfo.HighSideMosTemperature_end =
|
||||
(float)(pack->HighSideMosTemperature_end[0] << 8 | pack->HighSideMosTemperature_end[1]) / enlargeScale;
|
||||
if (save_configInfo.HighSideMosTemperature_end < 40 && save_configInfo.HighSideMosTemperature_end != 0) {
|
||||
// debug(" HighSideMosTemperature_end : %f \n", save_configInfo.HighSideMosTemperature_end);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断mos管完全恢复工作温度是否正确 */
|
||||
save_configInfo.HighSideMosTemperature_start =
|
||||
(float)(pack->HighSideMosTemperature_start[0] << 8 | pack->HighSideMosTemperature_start[1]) / enlargeScale;
|
||||
if (save_configInfo.HighSideMosTemperature_start > 70 && save_configInfo.HighSideMosTemperature_start != 0) {
|
||||
debug(" HighSideMosTemperature_start : %d \n", save_configInfo.HighSideMosTemperature_start);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// /* 判断启动任务中太阳能板开路电压检测间隔时间是否正确 */
|
||||
// save_configInfo.checkSolarOpenCircuitVTime =
|
||||
// pack->checkSolarOpenCircuitVTime[0] << 8 | pack->checkSolarOpenCircuitVTime[1];
|
||||
// if (save_configInfo.checkSolarOpenCircuitVTime > 1800 || save_configInfo.checkSolarOpenCircuitVTime < 5) {
|
||||
// debug(" checkSolarOpenCircuitVTime : %d \n", save_configInfo.checkSolarOpenCircuitVTime);
|
||||
// goto err;
|
||||
// }
|
||||
|
||||
// /* 判断传感器运行再次注册的间隔是否正确 */
|
||||
// save_configInfo.sensorEnableBroadcastTime =
|
||||
// pack->sensorEnableBroadcastTime[0] << 8 | pack->sensorEnableBroadcastTime[1];
|
||||
// if (save_configInfo.sensorEnableBroadcastTime > 60 || save_configInfo.sensorEnableBroadcastTime < 10) {
|
||||
// debug(" sensorEnableBroadcastTime : %d \n", save_configInfo.sensorEnableBroadcastTime);
|
||||
// goto err;
|
||||
// }
|
||||
|
||||
/* 判断出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出的间隔是否正确 */
|
||||
save_configInfo.outputAgainFlagTime =
|
||||
pack->outputAgainFlagTime[0] << 8 | pack->outputAgainFlagTime[1];
|
||||
if (!((save_configInfo.outputAgainFlagTime < 30 && save_configInfo.outputAgainFlagTime > 5)
|
||||
|| save_configInfo.outputAgainFlagTime == 0)) {
|
||||
// debug(" outputAgainFlagTime : %d \n", save_configInfo.outputAgainFlagTime);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断出现过载后,在该间隔时间中多次(2次)出现过载,则关闭输出的间隔是否正确 */
|
||||
save_configInfo.excessiveLoadFlagTime =
|
||||
pack->excessiveLoadFlagTime[0] << 8 | pack->excessiveLoadFlagTime[1];
|
||||
if (!((save_configInfo.excessiveLoadFlagTime < 90 && save_configInfo.excessiveLoadFlagTime > 20)
|
||||
|| save_configInfo.excessiveLoadFlagTime == 0)) {
|
||||
// debug(" excessiveLoadFlagTime : %d \n", save_configInfo.excessiveLoadFlagTime);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 判断出现过载过载保护后,在该间隔段时间后,再次尝试输出的间隔是否正确 */
|
||||
save_configInfo.eLAgainTime = pack->eLAgainTime[0] << 8 | pack->eLAgainTime[1];
|
||||
if (save_configInfo.eLAgainTime > 3000 || save_configInfo.eLAgainTime < 1000) {
|
||||
debug(" eLAgainTime : %d \n", save_configInfo.eLAgainTime);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* crc校验 */
|
||||
save_configInfo.crc = pack->crc[0] << 8 | pack->crc[1];
|
||||
if (save_configInfo.crc != checkModebusCrc(configBuff, RECV_CONFIG_INFO - 3)) {
|
||||
debug(" crc : %x%x \n", pack->crc[0], pack->crc[1]);
|
||||
debug(" checkModebusCrc : %x \n", checkModebusCrc(configBuff, RECV_CONFIG_INFO));
|
||||
goto err;
|
||||
}
|
||||
|
||||
|
||||
/* 结束标志 */
|
||||
if (pack->end_Flag != 0x16) {
|
||||
debug(" end_Flag : %x \n", pack->end_Flag);
|
||||
goto err;
|
||||
}
|
||||
|
||||
// debug("address : 0x %x %x %x %x %x %x %x\n", pack->address[0]
|
||||
// , pack->address[1], pack->address[2], pack->address[3]
|
||||
// , pack->address[4], pack->address[5], pack->address[6]);
|
||||
config_info temp_configInfo;
|
||||
read_config_info(&temp_configInfo);
|
||||
|
||||
if (pack->address[0] != 0xFF
|
||||
|| pack->address[1] != 0xFF
|
||||
|| pack->address[2] != 0xFF
|
||||
|| pack->address[3] != 0xFF
|
||||
|| pack->address[4] != 0xFF
|
||||
|| pack->address[5] != 0xFF
|
||||
|| pack->address[6] != 0xFF) {
|
||||
save_configInfo.address[0] = pack->address[0];
|
||||
save_configInfo.address[1] = pack->address[1];
|
||||
save_configInfo.address[2] = pack->address[2];
|
||||
save_configInfo.address[3] = pack->address[3];
|
||||
save_configInfo.address[4] = pack->address[4];
|
||||
save_configInfo.address[5] = pack->address[5];
|
||||
save_configInfo.address[6] = pack->address[6];
|
||||
// debug("address : 0x %x %x %x %x %x %x %x\n", save_configInfo.address[0]
|
||||
// , save_configInfo.address[1], save_configInfo.address[2], save_configInfo.address[3]
|
||||
// , save_configInfo.address[4], save_configInfo.address[5], save_configInfo.address[6]);
|
||||
} else {
|
||||
save_configInfo.address[0] = temp_configInfo.address[0];
|
||||
save_configInfo.address[1] = temp_configInfo.address[1];
|
||||
save_configInfo.address[2] = temp_configInfo.address[2];
|
||||
save_configInfo.address[3] = temp_configInfo.address[3];
|
||||
save_configInfo.address[4] = temp_configInfo.address[4];
|
||||
save_configInfo.address[5] = temp_configInfo.address[5];
|
||||
save_configInfo.address[6] = temp_configInfo.address[6];
|
||||
}
|
||||
|
||||
if (pack->hardwareID[0] != 0xFF
|
||||
|| pack->hardwareID[1] != 0xFF
|
||||
|| pack->hardwareID[2] != 0xFF
|
||||
|| pack->hardwareID[3] != 0xFF
|
||||
|| pack->hardwareID[4] != 0xFF
|
||||
|| pack->hardwareID[5] != 0xFF) {
|
||||
save_configInfo.hardwareID[0] = pack->hardwareID[0];
|
||||
save_configInfo.hardwareID[1] = pack->hardwareID[1];
|
||||
save_configInfo.hardwareID[2] = pack->hardwareID[2];
|
||||
save_configInfo.hardwareID[3] = pack->hardwareID[3];
|
||||
save_configInfo.hardwareID[4] = pack->hardwareID[4];
|
||||
save_configInfo.hardwareID[5] = pack->hardwareID[5];
|
||||
} else {
|
||||
save_configInfo.hardwareID[0] = temp_configInfo.hardwareID[0];
|
||||
save_configInfo.hardwareID[1] = temp_configInfo.hardwareID[1];
|
||||
save_configInfo.hardwareID[2] = temp_configInfo.hardwareID[2];
|
||||
save_configInfo.hardwareID[3] = temp_configInfo.hardwareID[3];
|
||||
save_configInfo.hardwareID[4] = temp_configInfo.hardwareID[4];
|
||||
save_configInfo.hardwareID[5] = temp_configInfo.hardwareID[5];
|
||||
}
|
||||
|
||||
if (pack->communicationID[0] != 0xFF
|
||||
|| pack->communicationID[1] != 0xFF
|
||||
|| pack->communicationID[2] != 0xFF
|
||||
|| pack->communicationID[3] != 0xFF) {
|
||||
save_configInfo.communicationID[0] = pack->communicationID[0];
|
||||
save_configInfo.communicationID[1] = pack->communicationID[1];
|
||||
save_configInfo.communicationID[2] = pack->communicationID[2];
|
||||
save_configInfo.communicationID[3] = pack->communicationID[3];
|
||||
} else {
|
||||
save_configInfo.communicationID[0] = temp_configInfo.communicationID[0];
|
||||
save_configInfo.communicationID[1] = temp_configInfo.communicationID[1];
|
||||
save_configInfo.communicationID[2] = temp_configInfo.communicationID[2];
|
||||
save_configInfo.communicationID[3] = temp_configInfo.communicationID[3];
|
||||
}
|
||||
|
||||
save_configInfo.protocolType = pack->protocolType;
|
||||
|
||||
save_configInfo.CommunicationProtocolType = pack->CommunicationProtocolType;
|
||||
|
||||
save_configInfo.onlyPower = pack->onlyPower;
|
||||
|
||||
|
||||
save_configInfo.crc = checkModebusCrc((uint8_t *)&save_configInfo, CONFIG_INFO_SIZE - 2);
|
||||
// save_backups_config_info(&save_configInfo);
|
||||
// save_config_info(&save_configInfo);
|
||||
saveConfigInfo(&save_configInfo);
|
||||
|
||||
// memset(config_buff, 0, sizeof(config_buff));
|
||||
zeroConfigBuff();
|
||||
|
||||
// /* 返回更改配置文件成功 */
|
||||
// SL_Mppt_SOther_pack SUpdateProfile_pack = {0};
|
||||
|
||||
// SUpdateProfile_pack.start_Flag[0] = g_otherParameter.startFlagSL[0];
|
||||
// SUpdateProfile_pack.start_Flag[1] = g_otherParameter.startFlagSL[1];
|
||||
|
||||
// SUpdateProfile_pack.address[0] = save_configInfo.address[0];
|
||||
// SUpdateProfile_pack.address[1] = save_configInfo.address[1];
|
||||
// SUpdateProfile_pack.address[2] = save_configInfo.address[2];
|
||||
// SUpdateProfile_pack.address[3] = save_configInfo.address[3];
|
||||
// SUpdateProfile_pack.address[4] = save_configInfo.address[4];
|
||||
// SUpdateProfile_pack.address[5] = save_configInfo.address[5];
|
||||
// SUpdateProfile_pack.address[6] = save_configInfo.address[6];
|
||||
|
||||
// SUpdateProfile_pack.function_Code = SL_Function_Code_Update_Profile;
|
||||
|
||||
// SUpdateProfile_pack.state = 0x01;
|
||||
|
||||
// uint16_t crc = CheckFuncSL((uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE - 3);
|
||||
// SUpdateProfile_pack.check_Bit_H = crc >> 8;
|
||||
// SUpdateProfile_pack.check_Bit_L = crc;
|
||||
|
||||
// SUpdateProfile_pack.end_Flag = g_otherParameter.endFlagSL;
|
||||
|
||||
// while (1) {
|
||||
// if (!Check_485_bus_busy(g_gw485_uart4_handle)) {
|
||||
// uart_dev_write(g_gw485_uart4_handle, (uint8_t *)&SUpdateProfile_pack, SL_MPPT_SOTHER_PACK_SIZE);
|
||||
// USART_ITConfig(USART3, USART_IT_RXNE, ENABLE);
|
||||
// break;
|
||||
// }
|
||||
// Delay_Ms(randomDelay());
|
||||
// }
|
||||
uart_dev_write(g_gw485_uart2_handle, "hello world\n", sizeof("hello world\n"));
|
||||
|
||||
/* 复位 */
|
||||
NVIC_SystemReset();
|
||||
|
||||
err:
|
||||
// config_buff_pos--;
|
||||
// memcpy(config_buff, config_buff + 1, sizeof(config_buff) - 1);
|
||||
outConfigBuff();
|
||||
}
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -2,7 +2,8 @@
|
|||
#include "inFlash.h"
|
||||
#include "parameter.h"
|
||||
#include "pDebug.h"
|
||||
#include "cfg_protocol.h"
|
||||
//#include "cfg_protocol.h"
|
||||
#include "configParameter.h"
|
||||
|
||||
static void save_config_info(config_info *save_config_info);
|
||||
|
||||
|
@ -46,26 +47,95 @@ void read_config_info(config_info *output_config_info)
|
|||
// read_Flash((uint8_t *)output_config_info, CONFIG_SAVE_addr, CONFIG_INFO_SIZE);
|
||||
// }
|
||||
|
||||
void saveConfigInfo(config_info *config_info)
|
||||
void saveConfigInfo(config_info *configInfo)
|
||||
{
|
||||
save_config_info(config_info);
|
||||
save_config_info(configInfo);
|
||||
// save_backups_config_info(config_info);
|
||||
}
|
||||
|
||||
void cfgTest(void)
|
||||
{
|
||||
// uint32_t tempTime = HAL_GetTick();
|
||||
// config_info temp_configInfo;
|
||||
// read_config_info(&temp_configInfo);
|
||||
// log_info("1 read time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// saveConfigInfo(&temp_configInfo);
|
||||
// log_info("1 write time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// read_config_info(&temp_configInfo);
|
||||
// saveConfigInfo(&temp_configInfo);
|
||||
// }
|
||||
// log_info("10 time : %d \n", HAL_GetTick() - tempTime);
|
||||
|
||||
// uint32_t tempTime = HAL_GetTick();
|
||||
// float tempF;
|
||||
// readtotalElectricityConsumption(&tempF);
|
||||
// log_info("1 read time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// savetotalElectricityConsumption(&tempF);
|
||||
// log_info("1 write time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// readtotalElectricityConsumption(&tempF);
|
||||
// savetotalElectricityConsumption(&tempF);
|
||||
// }
|
||||
// log_info("10 time : %d \n", HAL_GetTick() - tempTime);
|
||||
|
||||
// uint32_t tempTime = HAL_GetTick();
|
||||
// timeInfo tempT;
|
||||
// readTime(&tempT);
|
||||
// log_info("1 read time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// saveTime(&tempT);
|
||||
// log_info("1 write time : %d \n", HAL_GetTick() - tempTime);
|
||||
// tempTime = HAL_GetTick();
|
||||
// for (int i = 0; i < 10; i++) {
|
||||
// readTime(&tempT);
|
||||
// saveTime(&tempT);
|
||||
// }
|
||||
// log_info("10 time : %d \n", HAL_GetTick() - tempTime);
|
||||
|
||||
uint32_t tempTime = HAL_GetTick();
|
||||
uint8_t tempBuf[30];
|
||||
write_Flash((uint8_t *)"hello 12345\n", 2048, sizeof("hello 12345\n"));
|
||||
log_info("1 write time : %d \n", HAL_GetTick() - tempTime);
|
||||
tempTime = HAL_GetTick();
|
||||
read_Flash(tempBuf, 2048, sizeof("hello 12345\n"));
|
||||
log_info("1 read time : %d \n", HAL_GetTick() - tempTime);
|
||||
log_info("%s\n", tempBuf);
|
||||
tempTime = HAL_GetTick();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
read_Flash(tempBuf, 2048, sizeof("hello world\n"));
|
||||
write_Flash((uint8_t *)"hello world\n", 2048, sizeof("hello world\n"));
|
||||
}
|
||||
log_info("10 time : %d \n", HAL_GetTick() - tempTime);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 检测flash中是否有配置文件或者文件是否有损坏,若两处flash中都损坏则使用默认文件
|
||||
* @param config_info 读取的配置信息
|
||||
* @retval None
|
||||
*
|
||||
*/
|
||||
static void readFlashContent(config_info *config_info)
|
||||
void readFlashContent(config_info *configInfo)
|
||||
{
|
||||
read_config_info(config_info);
|
||||
read_config_info(configInfo);
|
||||
/* 配置文件正确就返回 */
|
||||
if (config_info->crc == checkModebusCrc((uint8_t *)config_info, CONFIG_INFO_SIZE - 2)) {
|
||||
// static volatile uint16_t tempCrc1, tempCrc2;
|
||||
// tempCrc1 = configInfo->crc;
|
||||
// tempCrc2 = checkModebusCrc((uint8_t *)configInfo, CONFIG_INFO_SIZE - 2);
|
||||
// if (tempCrc1 == tempCrc2) {
|
||||
// return;
|
||||
// }
|
||||
if (configInfo->crc == checkModebusCrc((uint8_t *)configInfo, CONFIG_INFO_SIZE - 2)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// /* 更深处的配置文件正确就返回 */
|
||||
// read_backups_config_info(config_info);
|
||||
// if (config_info->crc == configCheckFunc((uint8_t *)config_info, CONFIG_INFO_SIZE - 2)) {
|
||||
|
@ -74,48 +144,65 @@ static void readFlashContent(config_info *config_info)
|
|||
// }
|
||||
|
||||
/* 配置文件错误使用默认配置 */
|
||||
config_info->address[0] = 0x11;
|
||||
config_info->address[1] = 0x11;
|
||||
config_info->address[2] = 0x11;
|
||||
config_info->address[3] = 0x11;
|
||||
config_info->address[4] = 0x11;
|
||||
config_info->address[5] = 0x11;
|
||||
config_info->address[6] = 0x11;
|
||||
// config_info->Access_Node_Type = 0x01;
|
||||
// config_info->Communication_Methods = 0x02;
|
||||
config_info->gw485_Baud = 9600;
|
||||
config_info->bat485_Baud = 115200;
|
||||
|
||||
config_info->hardwareID[0] = 0x48;
|
||||
config_info->hardwareID[1] = 0x59;
|
||||
config_info->hardwareID[2] = 0x30;
|
||||
config_info->hardwareID[3] = 0x30;
|
||||
config_info->hardwareID[4] = 0x30;
|
||||
config_info->hardwareID[5] = 0x31;
|
||||
config_info->communicationID[0] = 0x00;
|
||||
config_info->communicationID[1] = 0x00;
|
||||
config_info->communicationID[2] = 0x00;
|
||||
config_info->communicationID[3] = 0x01;
|
||||
config_info->protocolType = 0x01;
|
||||
configInfo->uniqueDeviceID[0] = 0x11;
|
||||
configInfo->uniqueDeviceID[1] = 0x11;
|
||||
configInfo->uniqueDeviceID[2] = 0x11;
|
||||
configInfo->uniqueDeviceID[3] = 0x11;
|
||||
configInfo->uniqueDeviceID[4] = 0x11;
|
||||
configInfo->uniqueDeviceID[5] = 0x11;
|
||||
configInfo->uniqueDeviceID[6] = 0x11;
|
||||
|
||||
config_info->CommunicationProtocolType = 0x01;
|
||||
config_info->onlyPower = 0x01;
|
||||
configInfo->gw485_Baud = 115200;
|
||||
configInfo->bat485_Baud = 115200;
|
||||
|
||||
config_info->constantVoltageV = 14;
|
||||
config_info->floatI = 0.02;
|
||||
config_info->startSolarOpenCircuitV = 17;
|
||||
config_info->stopSolarOpenCircuitV = 15;
|
||||
config_info->constantVoltageChargeV = 14.4;
|
||||
config_info->FloatChargeV = 14;
|
||||
config_info->HighSideMosTemperature_stop = 100;
|
||||
config_info->HighSideMosTemperature_end = 90;
|
||||
config_info->HighSideMosTemperature_start = 50;
|
||||
configInfo->powerBoxType = 0x01;
|
||||
|
||||
configInfo->constantVoltageV = 14;
|
||||
configInfo->floatI = 0.1f;
|
||||
configInfo->startSolarOpenCircuitV = 17;
|
||||
configInfo->stopSolarOutputCircuitV = 15;
|
||||
|
||||
configInfo->checkCanStartTime = 5;
|
||||
configInfo->shortCircuitJudgmentDelay = 10;
|
||||
configInfo->inputPowerLowJudgmentDelay = 30;
|
||||
configInfo->inputPowerLowAgainOutputDelay = 1800;
|
||||
|
||||
configInfo->firstStageProtectionDelay = 2;
|
||||
configInfo->firstStageProtectionCurr = 50;
|
||||
configInfo->secondStageProtectionDelay = 50000;
|
||||
configInfo->secondStageProtectionCurr = 35;
|
||||
configInfo->thirdStageProtectionDelay = 600000;
|
||||
configInfo->thirdStageProtectionCurr = 30;
|
||||
|
||||
configInfo->inputPowerLowDetectionDelay = 10;
|
||||
configInfo->inputPowerLowDetectionVolt = 10.0f;
|
||||
|
||||
configInfo->maxOpenSolarOutputCircuitV = 25;
|
||||
configInfo->maxChargCurr = 35;
|
||||
|
||||
configInfo->minCheckLoopImpedanceChargCurr = 5;
|
||||
|
||||
configInfo->stopPowerOutputTemperature = 100;
|
||||
configInfo->reducePowerOutputTemperature = 90;
|
||||
configInfo->fullPowerOutputTemperature = 50;
|
||||
|
||||
configInfo->constantVoltageChargeV = 14.4f;
|
||||
configInfo->FloatChargeV = 14.2f;
|
||||
configInfo->collectOpenCircuitVoltageTime = 1800;
|
||||
|
||||
// configInfo->firstStageProtectionCurr = firstStageProtectionCurrMacro;
|
||||
// configInfo->firstStageProtectionDelay = firstStageProtectionDelayMacro;
|
||||
// configInfo->firstStageProtectionValue = firstStageProtectionValueMacro;
|
||||
// configInfo->secondStageProtectionCurr = secondStageProtectionCurrMacro;
|
||||
// configInfo->secondStageProtectionDelay = secondStageProtectionDelayMacro;
|
||||
// configInfo->thirdStageProtectionCurr = thirdStageProtectionCurrMacro;
|
||||
// configInfo->thirdStageProtectionDelay = thirdStageProtectionDelayMacro;
|
||||
// configInfo->checkLoopImpedanceChargCurr = checkLoopImpedanceChargCurrMacro;
|
||||
// configInfo->lowInputLoadDetectionVolt = lowInputLoadDetectionVoltMacro;
|
||||
// configInfo->lowInputLoadDetectionDelay = lowInputLoadDetectionDelayMacro;
|
||||
// configInfo->maxChargCurr = maxChargCurrMacro;
|
||||
// configInfo->maxOpenSolarOpenCircuitV = maxOpenSolarOpenCircuitVMacro;
|
||||
|
||||
// config_info->checkSolarOpenCircuitVTime = 10;
|
||||
// config_info->sensorEnableBroadcastTime = 20;
|
||||
config_info->outputAgainFlagTime = 10;
|
||||
config_info->excessiveLoadFlagTime = 60;
|
||||
config_info->eLAgainTime = 1800;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -131,97 +218,97 @@ void config_info_start(void)
|
|||
config_info temp_configInfo;
|
||||
readFlashContent(&temp_configInfo);
|
||||
|
||||
g_cfgParameter.constantVoltageV = temp_configInfo.constantVoltageV;
|
||||
g_cfgParameter.floatI = temp_configInfo.floatI;
|
||||
g_cfgParameter.startSolarOpenCircuitV = temp_configInfo.startSolarOpenCircuitV;
|
||||
g_cfgParameter.stopSolarOpenCircuitV = temp_configInfo.stopSolarOpenCircuitV;
|
||||
g_cfgParameter.constantVoltageChargeV = temp_configInfo.constantVoltageChargeV;
|
||||
g_cfgParameter.FloatV = temp_configInfo.FloatChargeV;
|
||||
g_cfgParameter.HighSideMosTemperature_stop = temp_configInfo.HighSideMosTemperature_stop;
|
||||
g_cfgParameter.HighSideMosTemperature_end = temp_configInfo.HighSideMosTemperature_end;
|
||||
g_cfgParameter.HighSideMosTemperature_start = temp_configInfo.HighSideMosTemperature_start;
|
||||
// g_cfgParameter.sensorEnableBroadcastTime = temp_configInfo.sensorEnableBroadcastTime;
|
||||
// g_cfgParameter.checkSolarOpenCircuitVTime = temp_configInfo.checkSolarOpenCircuitVTime;
|
||||
g_cfgParameter.outputAgainFlagTime = temp_configInfo.outputAgainFlagTime;
|
||||
g_cfgParameter.excessiveLoadFlagTime = temp_configInfo.excessiveLoadFlagTime;
|
||||
g_cfgParameter.eLAgainTime = temp_configInfo.eLAgainTime;
|
||||
g_cfgParameter.collectOpenCircuitVoltageTime= 3600;
|
||||
g_cfgParameter.address[0] = temp_configInfo.address[0];
|
||||
g_cfgParameter.address[1] = temp_configInfo.address[1];
|
||||
g_cfgParameter.address[2] = temp_configInfo.address[2];
|
||||
g_cfgParameter.address[3] = temp_configInfo.address[3];
|
||||
g_cfgParameter.address[4] = temp_configInfo.address[4];
|
||||
g_cfgParameter.address[5] = temp_configInfo.address[5];
|
||||
g_cfgParameter.address[6] = temp_configInfo.address[6];
|
||||
// g_cfgParameter.Access_Node_Type = temp_configInfo.Access_Node_Type;
|
||||
// g_cfgParameter.Communication_Methods = temp_configInfo.Communication_Methods;
|
||||
g_cfgParameter.hardwareID[0] = temp_configInfo.hardwareID[0];
|
||||
g_cfgParameter.hardwareID[1] = temp_configInfo.hardwareID[1];
|
||||
g_cfgParameter.hardwareID[2] = temp_configInfo.hardwareID[2];
|
||||
g_cfgParameter.hardwareID[3] = temp_configInfo.hardwareID[3];
|
||||
g_cfgParameter.hardwareID[4] = temp_configInfo.hardwareID[4];
|
||||
g_cfgParameter.hardwareID[5] = temp_configInfo.hardwareID[5];
|
||||
g_cfgParameter.communicationID[0] = temp_configInfo.communicationID[0];
|
||||
g_cfgParameter.communicationID[1] = temp_configInfo.communicationID[1];
|
||||
g_cfgParameter.communicationID[2] = temp_configInfo.communicationID[2];
|
||||
g_cfgParameter.communicationID[3] = temp_configInfo.communicationID[3];
|
||||
g_cfgParameter.protocolType = temp_configInfo.protocolType;
|
||||
// g_cfgParameter.CommunicationProtocolType = temp_configInfo.CommunicationProtocolType;
|
||||
g_cfgParameter.onlyPower = temp_configInfo.onlyPower;
|
||||
|
||||
g_cfgParameter.startFlagSL[0] = 'S';
|
||||
g_cfgParameter.startFlagSL[1] = 'L';
|
||||
g_cfgParameter.endFlagSL = 0x16;
|
||||
g_cfgParameter.startFlagHY = 0x68;
|
||||
g_cfgParameter.endFlagHY = 0x16;
|
||||
|
||||
// if (g_cfgParameter.CommunicationProtocolType == 0x00) {
|
||||
// g_cfgParameter.gw485_Baud = temp_configInfo.gw485_Baud;
|
||||
// g_cfgParameter.bat485_Baud = temp_configInfo.bat485_Baud;
|
||||
// } else if (g_cfgParameter.CommunicationProtocolType == 0x01) {
|
||||
// g_cfgParameter.bat485_Baud = temp_configInfo.bat485_Baud;
|
||||
// if (g_cfgParameter.protocolType == 0x01) {
|
||||
// g_cfgParameter.gw485_Baud = 9600;
|
||||
// } else if (g_cfgParameter.protocolType == 0x02) {
|
||||
// g_cfgParameter.gw485_Baud = 115200;
|
||||
// }
|
||||
// }
|
||||
g_cfgParameter.gw485_Baud = 115200;
|
||||
g_cfgParameter.bat485_Baud = 115200;
|
||||
g_cfgParameter.Access_Node_Type = POWERBOX;
|
||||
g_cfgParameter.Communication_Methods = RS485;
|
||||
|
||||
g_cfgParameter.gw485_Baud = temp_configInfo.gw485_Baud;
|
||||
g_cfgParameter.bat485_Baud = temp_configInfo.bat485_Baud;
|
||||
|
||||
g_cfgParameter.uniqueDeviceID[0] = temp_configInfo.uniqueDeviceID[0];
|
||||
g_cfgParameter.uniqueDeviceID[1] = temp_configInfo.uniqueDeviceID[1];
|
||||
g_cfgParameter.uniqueDeviceID[2] = temp_configInfo.uniqueDeviceID[2];
|
||||
g_cfgParameter.uniqueDeviceID[3] = temp_configInfo.uniqueDeviceID[3];
|
||||
g_cfgParameter.uniqueDeviceID[4] = temp_configInfo.uniqueDeviceID[4];
|
||||
g_cfgParameter.uniqueDeviceID[5] = temp_configInfo.uniqueDeviceID[5];
|
||||
g_cfgParameter.uniqueDeviceID[6] = temp_configInfo.uniqueDeviceID[6];
|
||||
|
||||
g_cfgParameter.powerBoxType = temp_configInfo.powerBoxType;
|
||||
|
||||
g_cfgParameter.constantVoltageV = temp_configInfo.constantVoltageV;
|
||||
g_cfgParameter.floatI = temp_configInfo.floatI;
|
||||
|
||||
g_cfgParameter.startSolarOpenCircuitV = temp_configInfo.startSolarOpenCircuitV;
|
||||
g_cfgParameter.stopSolarOutputCircuitV = temp_configInfo.stopSolarOutputCircuitV;
|
||||
|
||||
g_cfgParameter.checkCanStartTime = temp_configInfo.checkCanStartTime;
|
||||
g_cfgParameter.shortCircuitJudgmentDelay = temp_configInfo.shortCircuitJudgmentDelay;
|
||||
g_cfgParameter.inputPowerLowJudgmentDelay = temp_configInfo.inputPowerLowJudgmentDelay;
|
||||
g_cfgParameter.inputPowerLowAgainOutputDelay= temp_configInfo.inputPowerLowAgainOutputDelay;
|
||||
|
||||
g_cfgParameter.firstStageProtectionCurr = temp_configInfo.firstStageProtectionCurr;
|
||||
g_cfgParameter.firstStageProtectionDelay = temp_configInfo.firstStageProtectionDelay;
|
||||
g_cfgParameter.secondStageProtectionCurr = temp_configInfo.secondStageProtectionCurr;
|
||||
g_cfgParameter.secondStageProtectionDelay = temp_configInfo.secondStageProtectionDelay;
|
||||
g_cfgParameter.thirdStageProtectionCurr = temp_configInfo.thirdStageProtectionCurr;
|
||||
g_cfgParameter.thirdStageProtectionDelay = temp_configInfo.thirdStageProtectionDelay;
|
||||
|
||||
g_cfgParameter.inputPowerLowDetectionDelay = temp_configInfo.inputPowerLowDetectionDelay;
|
||||
g_cfgParameter.inputPowerLowDetectionVolt = temp_configInfo.inputPowerLowDetectionVolt;
|
||||
|
||||
g_cfgParameter.maxOpenSolarOutputCircuitV = temp_configInfo.maxOpenSolarOutputCircuitV;
|
||||
g_cfgParameter.maxChargCurr = temp_configInfo.maxChargCurr;
|
||||
g_cfgParameter.minCheckLoopImpedanceChargCurr = temp_configInfo.minCheckLoopImpedanceChargCurr;
|
||||
g_cfgParameter.stopPowerOutputTemperature = temp_configInfo.stopPowerOutputTemperature;
|
||||
g_cfgParameter.reducePowerOutputTemperature = temp_configInfo.reducePowerOutputTemperature;
|
||||
g_cfgParameter.fullPowerOutputTemperature = temp_configInfo.fullPowerOutputTemperature;
|
||||
|
||||
g_cfgParameter.constantVoltageChargeV = temp_configInfo.constantVoltageChargeV;
|
||||
g_cfgParameter.FloatChargeV = temp_configInfo.FloatChargeV;
|
||||
g_cfgParameter.collectOpenCircuitVoltageTime= temp_configInfo.collectOpenCircuitVoltageTime;
|
||||
|
||||
/* 读取的回路阻抗无效则回路阻抗设置为0 */
|
||||
if (readLoopImpedance() == FALSE) {
|
||||
setLoopImpedance(0);
|
||||
saveLoopImpedance();
|
||||
}
|
||||
|
||||
float fTemp;
|
||||
readLoopImpedance(&fTemp);
|
||||
/* 读取的回路阻抗偏差过大则不使用 */
|
||||
if (fTemp > (float)0.005 && fTemp < (float)1) {
|
||||
g_cfgParameter.loopImpedance = fTemp;
|
||||
}
|
||||
else {
|
||||
g_cfgParameter.loopImpedance = 0;
|
||||
saveLoopImpedance(&g_cfgParameter.loopImpedance);
|
||||
}
|
||||
readtotalElectricityConsumption(&fTemp);
|
||||
totalElectricityConsumptionInt(fTemp);
|
||||
readtotalChargCapacity(&fTemp);
|
||||
totalChargCapacityInt(fTemp);
|
||||
|
||||
timeInfo time;
|
||||
readTime(&time);
|
||||
setLastTime(time);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 保存回路阻抗在flash中
|
||||
* @param
|
||||
*/
|
||||
void saveLoopImpedance(float *loopImpedance)
|
||||
void saveLoopImpedance(void)
|
||||
{
|
||||
write_Flash((uint8_t *)loopImpedance, LoopImpedance_SAVE_addr, sizeof(float));
|
||||
float loopImpedance;
|
||||
loopImpedance = getLoopImpedance();
|
||||
write_Flash((uint8_t *)&loopImpedance, LoopImpedance_SAVE_addr, sizeof(float));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取flash中的回路阻抗
|
||||
* @param
|
||||
*/
|
||||
void readLoopImpedance(float *loopImpedance)
|
||||
BOOL readLoopImpedance(void)
|
||||
{
|
||||
read_Flash((uint8_t *)loopImpedance, LoopImpedance_SAVE_addr, sizeof(float));
|
||||
float loopImpedance;
|
||||
read_Flash((uint8_t *)&loopImpedance, LoopImpedance_SAVE_addr, sizeof(float));
|
||||
return setLoopImpedance(loopImpedance);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -260,3 +347,31 @@ void readtotalChargCapacity(float *totalChargCapacity)
|
|||
read_Flash((uint8_t *)totalChargCapacity, totalChargCapacity_SAVE_addr, sizeof(float));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取flash中的时间,这个时间是上次读取充放电量的时间
|
||||
* @param
|
||||
*/
|
||||
void saveTime(timeInfo *time)
|
||||
{
|
||||
write_Flash((uint8_t *)time, time_SAVE_addr, sizeof(timeInfo));
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 读取flash中的时间
|
||||
* @param
|
||||
*/
|
||||
void readTime(timeInfo *time)
|
||||
{
|
||||
read_Flash((uint8_t *)time, time_SAVE_addr, sizeof(timeInfo));
|
||||
}
|
||||
|
||||
// void saveOtherInfo(other_info *otherInfo)
|
||||
// {
|
||||
// write_Flash((uint8_t *)otherInfo, LoopImpedance_SAVE_addr, sizeof(OTHER_INFO_SIZE));
|
||||
// }
|
||||
|
||||
// void readOtherInfo(other_info *otherInfo)
|
||||
// {
|
||||
// read_Flash((uint8_t *)otherInfo, LoopImpedance_SAVE_addr, sizeof(OTHER_INFO_SIZE));
|
||||
// }
|
||||
|
||||
|
|
|
@ -0,0 +1,366 @@
|
|||
|
||||
#include "interruptSend.h"
|
||||
|
||||
|
||||
#define RS485_MAX_PACK_DATA_LEN 256
|
||||
|
||||
static uint8_t dataLocation1[RS485_MAX_PACK_DATA_LEN];
|
||||
static uint8_t dataLocation2[RS485_MAX_PACK_DATA_LEN];
|
||||
static uint8_t dataLocation3[RS485_MAX_PACK_DATA_LEN];
|
||||
|
||||
extern UART_HandleTypeDef huart2;
|
||||
extern UART_HandleTypeDef huart3;
|
||||
|
||||
#define GW485_huart huart2
|
||||
#define BAT485_huart huart3
|
||||
|
||||
/* 指定对齐方式为1字节 */
|
||||
#pragma pack(push,1)
|
||||
|
||||
typedef struct _send_data_info{
|
||||
device_handle device;
|
||||
BOOL dataState; //储存数据的状态,TRUE:有数据,FALSE:无数据
|
||||
uint8_t dataLen; //数据长度
|
||||
uint8_t Counter; //已经发送的长度
|
||||
uint8_t *data; //储存数据的内容
|
||||
}send_data_info;
|
||||
|
||||
typedef struct _uart_send_info {
|
||||
uint8_t insertState; //能否插入指示,大于0代表能插入
|
||||
// uint8_t sendStateGw:1; //能否发送指示,1:需要发送,0:不需要发送
|
||||
// uint8_t sendStateBat:1; //能否发送指示
|
||||
// uint8_t sendOverStateGw:1; //发送完成指示,1:发送完成,0:发送中
|
||||
// uint8_t sendOverStateBat:1; //发送完成指示
|
||||
// uint8_t GwState:1; //向上通信485总线空闲状态,1:空闲,0:繁忙
|
||||
// uint8_t idleStateGw:1; //向上通信空闲状态,1:没数据到来,0:有数据到来
|
||||
// uint8_t BatState:1; //向下通信485总线空闲状态
|
||||
// uint8_t idleStateBat:1; //向下通信空闲状态
|
||||
|
||||
BOOL sendStateGw; //能否发送指示,TRUE:需要发送,FALSE:不需要发送
|
||||
BOOL sendStateBat; //能否发送指示
|
||||
BOOL sendOverStateGw; //发送完成指示,TRUE:发送完成,FALSE:发送中
|
||||
BOOL sendOverStateBat; //发送完成指示
|
||||
BOOL GwState; //向上通信485总线空闲状态,TRUE:空闲,FALSE:繁忙
|
||||
BOOL idleStateGw; //向上通信空闲状态,TRUE:没数据到来,FALSE:有数据到来
|
||||
BOOL BatState; //向下通信485总线空闲状态
|
||||
BOOL idleStateBat; //向下通信空闲状态
|
||||
|
||||
send_data_info *insertData; //通过该指针写入数据
|
||||
send_data_info *sendDataGw; //通过该指针发送数据
|
||||
send_data_info *sendDataBat; //通过该指针发送数据
|
||||
send_data_info data1; //储存数据的第1个位置
|
||||
send_data_info data2; //储存数据的第2个位置
|
||||
send_data_info data3; //储存数据的第3个位置
|
||||
}uart_send_info;
|
||||
/* 恢复默认的对齐设置 */
|
||||
#pragma pack(pop)
|
||||
|
||||
uart_send_info uart_send = {0};
|
||||
|
||||
/**
|
||||
* @brief 串口中断发送的初始化,通过空闲中断来判断总线空闲状态
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void send_init(void)
|
||||
{
|
||||
/* 指定数据储存位置 */
|
||||
uart_send.data1.data = dataLocation1;
|
||||
uart_send.data2.data = dataLocation2;
|
||||
uart_send.data3.data = dataLocation3;
|
||||
|
||||
/* 初始化插入位置为data1 */
|
||||
uart_send.insertData = &uart_send.data1;
|
||||
uart_send.sendDataGw = NULL;
|
||||
uart_send.sendDataBat = NULL;
|
||||
|
||||
//有3个位置可以写入数据
|
||||
uart_send.insertState = 3;
|
||||
|
||||
//没有数据能够发送
|
||||
uart_send.sendStateGw = FALSE;
|
||||
uart_send.sendStateBat = FALSE;
|
||||
|
||||
//发送完成
|
||||
uart_send.sendOverStateBat = TRUE;
|
||||
uart_send.sendOverStateGw = TRUE;
|
||||
|
||||
//485总线空闲
|
||||
uart_send.GwState = TRUE;
|
||||
uart_send.idleStateGw = TRUE;
|
||||
uart_send.BatState = TRUE;
|
||||
uart_send.idleStateBat = TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GW485串口接收到数据后调用该函数,设置485总线空闲状态
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void setIdleStateGw(void)
|
||||
{
|
||||
if (uart_send.idleStateGw == FALSE) {
|
||||
uart_send.idleStateGw = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BAT485串口接收到数据后调用该函数,设置485总线空闲状态
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void setIdleStateBat(void)
|
||||
{
|
||||
if (uart_send.idleStateBat == FALSE) {
|
||||
uart_send.idleStateBat = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GW485串口设置485总线空闲状态,间隔10ms使用
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void setGwState(void)
|
||||
{
|
||||
if (uart_send.idleStateGw == FALSE) {
|
||||
uart_send.GwState = TRUE;
|
||||
} else {
|
||||
uart_send.GwState = FALSE;
|
||||
}
|
||||
|
||||
uart_send.idleStateGw = FALSE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief BAT485串口设置485总线空闲状态,间隔10ms使用
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void setBatState(void)
|
||||
{
|
||||
if (uart_send.idleStateBat == FALSE) {
|
||||
uart_send.BatState = TRUE;
|
||||
} else {
|
||||
uart_send.BatState = FALSE;
|
||||
}
|
||||
|
||||
uart_send.idleStateBat = FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief GW485串口发送完成后,调用该函数
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void setSendOverStateGw(void)
|
||||
{
|
||||
/* 配置文件传输完成,复位 */
|
||||
if (uart_send.sendDataGw->data[9] = 0xD0
|
||||
&& uart_send.sendDataGw->data[12] == 0xAA) {
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
uart_send.sendOverStateGw = TRUE;
|
||||
uart_send.sendStateGw = FALSE;
|
||||
uart_send.sendDataGw->dataState = FALSE;
|
||||
uart_send.sendDataGw = NULL;
|
||||
uart_send.insertState++;
|
||||
|
||||
/* 插入指针指向为空时 */
|
||||
if (uart_send.data1.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data1;
|
||||
}
|
||||
else if (uart_send.data2.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data2;
|
||||
}
|
||||
else if (uart_send.data3.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data3;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief BAT485串口发送完成后,调用该函数
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void setSendOverStateBat(void)
|
||||
{
|
||||
uart_send.sendOverStateBat = TRUE;
|
||||
uart_send.sendStateBat = FALSE;
|
||||
uart_send.sendDataBat->dataState = FALSE;
|
||||
uart_send.sendDataBat = NULL;
|
||||
uart_send.insertState++;
|
||||
|
||||
/* 插入指针指向为空时 */
|
||||
if (uart_send.data1.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data1;
|
||||
}
|
||||
else if (uart_send.data2.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data2;
|
||||
}
|
||||
else if (uart_send.data3.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data3;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 检测是否有数据需要发送
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void check_sendState(void)
|
||||
{
|
||||
/* 向上通信总线空闲时,检测到有数据需要发送,同时上一次数据发送完成 */
|
||||
if (uart_send.GwState && uart_send.sendStateGw && uart_send.sendOverStateGw) {
|
||||
/* 将数据塞入中断发送 */
|
||||
HAL_UART_Transmit_IT(&GW485_huart, uart_send.sendDataGw->data, uart_send.sendDataGw->dataLen);
|
||||
uart_send.sendOverStateGw = FALSE;
|
||||
}
|
||||
|
||||
/* 向下通信总线空闲时,检测到有数据需要发送,同时上一次数据发送完成 */
|
||||
if (uart_send.BatState && uart_send.sendStateBat && uart_send.sendOverStateBat) {
|
||||
HAL_UART_Transmit_IT(&BAT485_huart, uart_send.sendDataBat->data, uart_send.sendDataBat->dataLen);
|
||||
uart_send.sendOverStateBat = FALSE;
|
||||
}
|
||||
|
||||
if (uart_send.sendDataGw == NULL) {
|
||||
if (uart_send.data1.dataState) {
|
||||
if (uart_send.data1.device == g_gw485_uart2_handle) {
|
||||
uart_send.sendStateGw = TRUE;
|
||||
uart_send.sendDataGw = &uart_send.data1;
|
||||
}
|
||||
}
|
||||
if (uart_send.data2.dataState) {
|
||||
if (uart_send.data2.device == g_gw485_uart2_handle) {
|
||||
uart_send.sendStateGw= TRUE;
|
||||
uart_send.sendDataGw = &uart_send.data2;
|
||||
}
|
||||
}
|
||||
if (uart_send.data3.dataState) {
|
||||
if (uart_send.data3.device == g_gw485_uart2_handle) {
|
||||
uart_send.sendStateGw = TRUE;
|
||||
uart_send.sendDataGw = &uart_send.data3;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (uart_send.sendDataBat == NULL) {
|
||||
if (uart_send.data1.dataState) {
|
||||
if (uart_send.data1.device == g_bat485_uart3_handle) {
|
||||
uart_send.sendStateBat = TRUE;
|
||||
uart_send.sendDataBat = &uart_send.data1;
|
||||
}
|
||||
}
|
||||
if (uart_send.data2.dataState) {
|
||||
if (uart_send.data2.device == g_bat485_uart3_handle) {
|
||||
uart_send.sendStateBat= TRUE;
|
||||
uart_send.sendDataBat = &uart_send.data2;
|
||||
}
|
||||
}
|
||||
if (uart_send.data3.dataState) {
|
||||
if (uart_send.data3.device == g_bat485_uart3_handle) {
|
||||
uart_send.sendStateBat = TRUE;
|
||||
uart_send.sendDataBat = &uart_send.data3;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 串口中断发送函数
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void uart_interruptSend(device_handle device, uint8_t buff[], uint8_t len)
|
||||
{
|
||||
/* 拷贝数据到发送 */
|
||||
do {
|
||||
if (uart_send.insertState > 0 && uart_send.insertData != NULL) {
|
||||
// memcpy(uart_send.insertData->data, buff, len);
|
||||
for (int var = 0; var < len; ++var) {
|
||||
uart_send.insertData->data[var] = buff[var];
|
||||
// printf(" %x ", uart_send.insertData->data[var]);
|
||||
}
|
||||
uart_send.insertData->Counter = 0;
|
||||
uart_send.insertData->dataLen = len;
|
||||
uart_send.insertData->device = device;
|
||||
// uart_send.insertData->dataState = 1;
|
||||
// uart_send.insertState--;
|
||||
|
||||
uart_send.insertData->dataState = TRUE;
|
||||
uart_send.insertState--;
|
||||
break;
|
||||
}
|
||||
/* 0执行一次, 1一直循环直到能插入 */
|
||||
} while (0);
|
||||
|
||||
/* 可插入数据大于0时,将插入指针指向空的储存位置,否则指向NULL */
|
||||
if (uart_send.insertState > 0) {
|
||||
if (uart_send.data1.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data1;
|
||||
}
|
||||
else if (uart_send.data2.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data2;
|
||||
}
|
||||
else if (uart_send.data3.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data3;
|
||||
}
|
||||
} else {
|
||||
uart_send.insertData = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 得到中断发送插入数据指针
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
uint8_t *getInsertData(void)
|
||||
{
|
||||
return uart_send.insertData->data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 将数据发送指针的内容发送
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void uart_insertDataSend(device_handle device, uint8_t len)
|
||||
{
|
||||
uart_send.insertData->Counter = 0;
|
||||
uart_send.insertData->dataLen = len;
|
||||
uart_send.insertData->device = device;
|
||||
|
||||
uart_send.insertData->dataState = TRUE;
|
||||
uart_send.insertState--;
|
||||
|
||||
/* 可插入数据大于0时,将插入指针指向空的储存位置,否则指向NULL */
|
||||
if (uart_send.insertState > 0) {
|
||||
if (uart_send.data1.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data1;
|
||||
}
|
||||
else if (uart_send.data2.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data2;
|
||||
}
|
||||
else if (uart_send.data3.dataState == FALSE) {
|
||||
uart_send.insertData = &uart_send.data3;
|
||||
}
|
||||
} else {
|
||||
uart_send.insertData = NULL;
|
||||
}
|
||||
}
|
|
@ -3,15 +3,16 @@
|
|||
#include "FM_TIM.h"
|
||||
#include "FM_GPIO.h"
|
||||
#include "capture.h"
|
||||
#include "chargControlEnum.h"
|
||||
#include "bl_chargControl.h"
|
||||
|
||||
config_parameter g_cfgParameter = {0};
|
||||
static otherParameter g_otherParameter = {0};
|
||||
|
||||
static BOOL batteryState = FALSE; /* 有无电池(估计) */
|
||||
static float dutyRatio; /* 占空比 */
|
||||
static uint8_t mosTemperState = mosTemperStop; /* mos管温度状态 */
|
||||
static BOOL checkImpedanceState = FALSE; /* 启动后是否进行了回路阻抗检测 */
|
||||
static BOOL batteryState = FALSE; /* 有无电池(估计) */
|
||||
static float dutyRatio = 0; /* 占空比 */
|
||||
static uint8_t mosTemperState = mosTemperFull; /* mos管温度状态 */
|
||||
static BOOL checkImpedanceState = FALSE; /* 启动后是否进行了回路阻抗检测 */
|
||||
static timeInfo lastTime = {0}; /* 上次读取充放电量参数的时间 */
|
||||
|
||||
/**
|
||||
* @brief 获取电池状态
|
||||
|
@ -55,15 +56,16 @@ float getDutyRatio(void)
|
|||
*/
|
||||
void setDutyRatio(float DutyRatio)
|
||||
{
|
||||
if (DutyRatio > 0.9f) {
|
||||
dutyRatio = 0.9f;
|
||||
if (DutyRatio > 0.95f) {
|
||||
dutyRatio = 0.95f;
|
||||
}
|
||||
else if (DutyRatio < 0.05f) {
|
||||
dutyRatio = 0.05f;
|
||||
}
|
||||
else {
|
||||
dutyRatio = DutyRatio;
|
||||
}
|
||||
}
|
||||
|
||||
set_pwmDutyRatio(dutyRatio);
|
||||
}
|
||||
|
||||
|
@ -96,7 +98,7 @@ uint8_t getMosTemperState(void)
|
|||
*/
|
||||
void setMosTemperState(uint8_t state)
|
||||
{
|
||||
if (state == mosTemperStart || state == mosTemperEnd || state == mosTemperStop) {
|
||||
if (state == mosTemperFull || state == mosTemperReduce || state == mosTemperStop) {
|
||||
mosTemperState = state;
|
||||
}
|
||||
}
|
||||
|
@ -123,6 +125,29 @@ void setCheckImpedanceState(void)
|
|||
checkImpedanceState = TRUE;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 设置上次读取充放电量参数的时间
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
void setLastTime(timeInfo time)
|
||||
{
|
||||
lastTime = time;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置上次读取充放电量参数的时间
|
||||
* @param
|
||||
* @retval
|
||||
*
|
||||
*/
|
||||
timeInfo getLastTime(void)
|
||||
{
|
||||
return lastTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到电池电压
|
||||
* @param
|
||||
|
@ -141,7 +166,7 @@ float getBatteryVoltage(void)
|
|||
void setBatteryVoltage(void)
|
||||
{
|
||||
g_otherParameter.Battery_Voltage = g_otherParameter.Output_Voltage
|
||||
- getChargBatteryCurrent() * g_cfgParameter.loopImpedance;
|
||||
- getChargBatteryCurrent() * getLoopImpedance();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -417,10 +442,10 @@ void setChargMosState(BOOL state)
|
|||
{
|
||||
if (state == FALSE) {
|
||||
/* 关闭充电 */
|
||||
|
||||
stopChargWork();
|
||||
} else if (state == TRUE) {
|
||||
/* 打开充电 */
|
||||
|
||||
beginChargWork();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -431,7 +456,7 @@ void setChargMosState(BOOL state)
|
|||
*/
|
||||
BOOL getDischargMosState(void)
|
||||
{
|
||||
if (g_cfgParameter.onlyPower) {
|
||||
if (g_cfgParameter.powerBoxType) {
|
||||
return readOnlyPowerOutputState();
|
||||
} else {
|
||||
return readOutputState();
|
||||
|
@ -443,8 +468,55 @@ BOOL getDischargMosState(void)
|
|||
* @param
|
||||
* @retval softVer 软件版本号
|
||||
*/
|
||||
uint8_t *getVersionInformation(void)
|
||||
uint8_t *getVersionnInformation(void)
|
||||
{
|
||||
return softVer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到回路阻抗大小
|
||||
* @param
|
||||
* @retval 回路阻抗大小
|
||||
*/
|
||||
float getLoopImpedance(void)
|
||||
{
|
||||
return g_otherParameter.loopImpedance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置回路阻抗大小
|
||||
* @param loopImpedance 回路阻抗大小
|
||||
* @retval
|
||||
*/
|
||||
BOOL setLoopImpedance(float loopImpedance)
|
||||
{
|
||||
/* 读取的回路阻抗偏差过大则不使用 */
|
||||
if (loopImpedance < 0 || loopImpedance > 0.3f) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
g_otherParameter.loopImpedance = loopImpedance;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到注册状态
|
||||
* @param
|
||||
* @retval 注册状态
|
||||
*/
|
||||
uint16_t getRegistrationStatus(void)
|
||||
{
|
||||
return g_otherParameter.Registration_Status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置注册状态
|
||||
* @param 注册状态
|
||||
* @retval
|
||||
*/
|
||||
void setRegistrationStatus(uint16_t status)
|
||||
{
|
||||
if (status == UNREGISTER || status == REGISTER_FAIL || status == REGISTER_SUCCESS) {
|
||||
g_otherParameter.Registration_Status = status;
|
||||
}
|
||||
}
|
|
@ -3,17 +3,27 @@
|
|||
#include "inFlash.h"
|
||||
#include "parameter.h"
|
||||
#include "FM_GPIO.h"
|
||||
#include "chargControlEnum.h"
|
||||
#include "chargControlTypes.h"
|
||||
#include "bl_chargControl.h"
|
||||
#include "hy_protocol.h"
|
||||
#include "cfg_protocol.h"
|
||||
//#include "hy_protocol.h"
|
||||
//#include "cfg_protocol.h"
|
||||
#include "uart_dev.h"
|
||||
#include "abnormalManage.h"
|
||||
#include "interruptSend.h"
|
||||
#include "configParameter.h"
|
||||
#include "capture.h"
|
||||
#include "bl_usart.h"
|
||||
#include "SOE.h"
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
|
||||
|
||||
/* 控制运行指示灯和喂狗 */
|
||||
// #define runled_reloadVal 1000 /* 任务执行间隔 */
|
||||
static uint16_t runled_reloadVal = 1000; /* 任务执行间隔 */
|
||||
#define runled_reloadVal 2000 /* 任务执行间隔 */
|
||||
// static uint16_t runled_reloadVal = 1000; /* 任务执行间隔 */
|
||||
#define runled_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_runled;
|
||||
static void Task_Runled(void);
|
||||
|
@ -44,7 +54,7 @@ static void Task_softStart(void);
|
|||
|
||||
/* 回路阻抗检测 */
|
||||
#define impedanceCalculation_reloadVal 20 /* 任务执行间隔 */
|
||||
#define impedanceCalculation_offset 0 /* 任务执行偏移量 */
|
||||
#define impedanceCalculation_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_impedanceCalculation;
|
||||
static void Task_impedanceCalculation(void);
|
||||
|
||||
|
@ -54,31 +64,31 @@ static void Task_impedanceCalculation(void);
|
|||
STR_TimeSliceOffset m_collectOpenCircuitVoltage;
|
||||
void Task_collectOpenCircuitVoltage(void);
|
||||
|
||||
/* 限时开启HY协议配置模式 */
|
||||
#define beginHYconfigMode_reloadVal 1000 /* 任务执行间隔 */
|
||||
#define beginHYconfigMode_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_beginHYconfigMode;
|
||||
static void Task_beginHYconfigMode(void);
|
||||
// /* 限时开启HY协议配置模式 */
|
||||
// #define beginHYconfigMode_reloadVal 1000 /* 任务执行间隔 */
|
||||
// #define beginHYconfigMode_offset 0 /* 任务执行偏移量 */
|
||||
// static STR_TimeSliceOffset m_beginHYconfigMode;
|
||||
// static void Task_beginHYconfigMode(void);
|
||||
|
||||
/* 串口数据接收判断 */
|
||||
#define usartJudge_reloadVal 100 /* 任务执行间隔 */
|
||||
#define usartJudge_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_usartJudge;
|
||||
static void Task_usartJudge(void);
|
||||
// /* 串口数据接收判断 */
|
||||
// #define usartJudge_reloadVal 100 /* 任务执行间隔 */
|
||||
// #define usartJudge_offset 0 /* 任务执行偏移量 */
|
||||
// static STR_TimeSliceOffset m_usartJudge;
|
||||
// static void Task_usartJudge(void);
|
||||
|
||||
/* 串口数据解析和处理 */
|
||||
#define usartHandle_reloadVal 20 /* 任务执行间隔 */
|
||||
#define usartHandle_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_usartHandle;
|
||||
static void Task_usartHandle(void);
|
||||
typedef void (*uartJudgeHandle)(device_handle device);
|
||||
static uartJudgeHandle uart_judge_handle;
|
||||
// /* 串口数据解析和处理 */
|
||||
// #define usartHandle_reloadVal 20 /* 任务执行间隔 */
|
||||
// #define usartHandle_offset 0 /* 任务执行偏移量 */
|
||||
// static STR_TimeSliceOffset m_usartHandle;
|
||||
// static void Task_usartHandle(void);
|
||||
// typedef void (*uartJudgeHandle)(device_handle device);
|
||||
// static uartJudgeHandle uart_judge_handle;
|
||||
|
||||
/* 配置文件数据解析和处理 */
|
||||
#define usartCfg_reloadVal 200 /* 任务执行间隔 */
|
||||
#define usartCfg_offset 0 /* 任务执行偏移量 */
|
||||
static STR_TimeSliceOffset m_usartCfg;
|
||||
static void Task_usartCfg(void);
|
||||
// /* 配置文件数据解析和处理 */
|
||||
// #define usartCfg_reloadVal 200 /* 任务执行间隔 */
|
||||
// #define usartCfg_offset 0 /* 任务执行偏移量 */
|
||||
// static STR_TimeSliceOffset m_usartCfg;
|
||||
// static void Task_usartCfg(void);
|
||||
|
||||
/* 短路保护 */
|
||||
#define shortCircuitProtection_reloadVal 1000 /* 任务执行间隔 */
|
||||
|
@ -92,6 +102,45 @@ static void Task_shortCircuitProtection(void);
|
|||
STR_TimeSliceOffset m_excessiveLoad;
|
||||
void Task_excessiveLoad(void);
|
||||
|
||||
/* 总线状态检测 */
|
||||
#define busFree_reloadVal 5 /* 任务执行间隔 */
|
||||
#define busFree_offset 0 /* 任务执行偏移量 */
|
||||
STR_TimeSliceOffset m_busFree;
|
||||
void Task_busFree(void);
|
||||
|
||||
// /* 中断发送 */
|
||||
// #define interruptSend_reloadVal 1 /* 任务执行间隔 */
|
||||
// #define interruptSend_offset 0 /* 任务执行偏移量 */
|
||||
// STR_TimeSliceOffset m_interruptSend;
|
||||
// void Task_interruptSend(void);
|
||||
|
||||
// /* 软件过载保护 */
|
||||
// #define softExcessiveLoad_reloadVal 1000 /* 任务执行间隔 */
|
||||
// #define softExcessiveLoad_offset 0 /* 任务执行偏移量 */
|
||||
// STR_TimeSliceOffset m_softExcessiveLoad;
|
||||
// void Task_softExcessiveLoad(void);
|
||||
|
||||
/* 软件短路保护 */
|
||||
#define softShortCircuit_reloadVal 1000 /* 任务执行间隔 */
|
||||
#define softShortCircuit_offset 0 /* 任务执行偏移量 */
|
||||
STR_TimeSliceOffset m_softShortCircuit;
|
||||
void Task_softShortCircuit(void);
|
||||
|
||||
|
||||
/* 串口任务 */
|
||||
#define uart_reloadVal 10 /* 任务执行间隔 */
|
||||
#define uart_offset 0 /* 任务执行偏移量 */
|
||||
STR_TimeSliceOffset m_uart;
|
||||
void Task_uart(void);
|
||||
|
||||
/* 将记录下来的时间存入flash中 */
|
||||
#define SOE_reloadVal 3000 /* 任务执行间隔 */
|
||||
#define SOE_offset 100 /* 任务执行偏移量 */
|
||||
STR_TimeSliceOffset m_SOE;
|
||||
void Task_SOE(void);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 启动时初始化各任务
|
||||
* @param None
|
||||
|
@ -108,9 +157,10 @@ void task_Init(void)
|
|||
TimeSliceOffset_Register(&m_collectOpenCircuitVoltage, Task_collectOpenCircuitVoltage
|
||||
, collectOpenCircuitVoltage_reloadVal, collectOpenCircuitVoltage_offset);
|
||||
|
||||
uartTaskInit();
|
||||
TimeSliceOffset_Register(&m_usartJudge, Task_usartJudge, usartJudge_reloadVal, usartJudge_offset);
|
||||
TimeSliceOffset_Register(&m_usartCfg, Task_usartCfg, usartCfg_reloadVal, usartCfg_offset);
|
||||
TimeSliceOffset_Register(&m_uart, Task_uart, uart_reloadVal, uart_offset);
|
||||
TimeSliceOffset_Register(&m_busFree, Task_busFree, busFree_reloadVal, busFree_offset);
|
||||
|
||||
TimeSliceOffset_Register(&m_SOE, Task_SOE, SOE_reloadVal, SOE_offset);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -124,6 +174,23 @@ void Task_Runled(void)
|
|||
RUN_LED();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 修改运行指示灯状态
|
||||
* @param mode 充电时1Hz的频率闪烁
|
||||
* 其余时间2Hz的频率闪烁
|
||||
* @retval None
|
||||
*
|
||||
*/
|
||||
void chargRunLed(uint8_t mode)
|
||||
{
|
||||
if (mode == runLedChargMode) {
|
||||
m_runled.reloadVal = 500;
|
||||
}
|
||||
else if (mode == runLedOtherMode) {
|
||||
m_runled.reloadVal = 2000;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 喂狗任务
|
||||
* @param None
|
||||
|
@ -133,17 +200,67 @@ void Task_wdi(void)
|
|||
{
|
||||
feedDog();
|
||||
|
||||
// debug_printf("chargCurrent:%f \n", getChargCurrent());
|
||||
// debug_printf("outputVoltage:%f \n", getOutputVoltage());
|
||||
// debug_printf("BatteryVoltage:%f \n", getBatteryVoltage());
|
||||
// debug_printf("dischargCurrent:%f \n", getDischargCurrent());
|
||||
// debug_printf("solarInCircuitVoltage:%f \n", getSolarInCircuitVoltage());
|
||||
// debug_printf("HighSideMosTemperature:%f \n", getHighSideMosTemperature());
|
||||
// debug_printf("InputVoltage:%f \n", getInputVoltage());
|
||||
// debug_printf("DischargMosState:%d \n", getDischargMosState());
|
||||
// debug_printf("MPPT_Mode:%d \n", getMPPT_Mode());
|
||||
// debug_printf("loopImpedance:%f \n", g_cfgParameter.loopImpedance);
|
||||
// debug_printf("DutyRatio:%f \n", getDutyRatio());
|
||||
debug_printf("chargCurrent:%f \n", getChargCurrent());
|
||||
debug_printf("outputVoltage:%f \n", getOutputVoltage());
|
||||
debug_printf("BatteryVoltage:%f \n", getBatteryVoltage());
|
||||
debug_printf("dischargCurrent:%f \n", getDischargCurrent());
|
||||
debug_printf("solarInCircuitVoltage:%f \n", getSolarInCircuitVoltage());
|
||||
debug_printf("HighSideMosTemperature:%f \n", getHighSideMosTemperature());
|
||||
debug_printf("InputVoltage:%f \n", getInputVoltage());
|
||||
debug_printf("DischargMosState:%d \n", getDischargMosState());
|
||||
debug_printf("MPPT_Mode:%d \n", getMPPT_Mode());
|
||||
debug_printf("loopImpedance:%f \n", getLoopImpedance());
|
||||
debug_printf("DutyRatio:%f \n", getDutyRatio());
|
||||
debug_printf("OUT_VOLT_IN:%f \n", get_OUT_VOLT_IN());
|
||||
debug_printf("HAL_GetTick:%d \n", HAL_GetTick());
|
||||
|
||||
|
||||
// char buf[100];
|
||||
// sprintf(buf, "chargCurrent:%f \n", getChargCurrent());
|
||||
// uart_dev_write(g_gw485_uart2_handle, buf, strlen(buf));
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "outputVoltage:%f \n", getOutputVoltage());
|
||||
// uart_dev_write(g_gw485_uart2_handle, buf, strlen(buf));
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "BatteryVoltage:%f \n", getBatteryVoltage());
|
||||
// uart_dev_write(g_gw485_uart2_handle, buf, strlen(buf));
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "dischargCurrent:%f \n", getDischargCurrent());
|
||||
// uart_dev_write(g_gw485_uart2_handle, buf, strlen(buf));
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "solarInCircuitVoltage:%f \n", getSolarInCircuitVoltage());
|
||||
// uart_dev_write(g_gw485_uart2_handle, buf, strlen(buf));
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "HighSideMosTemperature:%f \n", getHighSideMosTemperature());
|
||||
// uart_dev_write(g_gw485_uart2_handle, buf, strlen(buf));
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "InputVoltage:%f \n", getInputVoltage());
|
||||
// uart_dev_write(g_gw485_uart2_handle, buf, strlen(buf));
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "DischargMosState:%d \n", getDischargMosState());
|
||||
// uart_dev_write(g_gw485_uart2_handle, buf, strlen(buf));
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "MPPT_Mode:%d \n", getMPPT_Mode());
|
||||
// uart_dev_write(g_gw485_uart2_handle, buf, strlen(buf));
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "loopImpedance:%f \n", g_cfgParameter.loopImpedance);
|
||||
// uart_dev_write(g_gw485_uart2_handle, buf, strlen(buf));
|
||||
|
||||
// memset(buf, 0, sizeof(buf));
|
||||
// sprintf(buf, "DutyRatio:%f \n", getDutyRatio());
|
||||
// uart_dev_write(g_gw485_uart2_handle, buf, strlen(buf));
|
||||
|
||||
|
||||
// uart_interruptSend(g_gw485_uart2_handle, "hello world\n", sizeof("hello world\n"));
|
||||
|
||||
/* 每天复位一次,复位前将电量信息写入flash中 */
|
||||
static uint32_t temp = 60 * 60 * 24;
|
||||
|
@ -154,9 +271,11 @@ void Task_wdi(void)
|
|||
savetotalElectricityConsumption(&tempF);
|
||||
tempF = getTotalChargCapacity();
|
||||
savetotalChargCapacity(&tempF);
|
||||
timeInfo time;
|
||||
time = getLastTime();
|
||||
saveTime(&time);
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -171,38 +290,45 @@ void Task_refreshJudgeData(void)
|
|||
setInputVoltage();
|
||||
setHighSideMosTemperature();
|
||||
|
||||
// static float tempOutV;
|
||||
// tempOutV = get_OUT_VOLT_IN();
|
||||
// debug_printf("get_OUT_VOLT_IN:%f \n", tempOutV);
|
||||
|
||||
/* 判断有无电池 */
|
||||
if (getBatteryState() == FALSE && (getChargBatteryCurrent() > 1 || getChargBatteryCurrent() < -1)
|
||||
&& getOutputVoltage() < 14.2f) {
|
||||
setBatteryState(TRUE);
|
||||
}
|
||||
|
||||
/* 有电池,太阳能输出功率大,同时回路阻抗未测试或需要重新测试 */
|
||||
if ((getCheckImpedanceState() == FALSE || g_cfgParameter.loopImpedance == 0.0f)
|
||||
&& (getBatteryState() == TRUE) && (getChargCurrent() > 3.0f)
|
||||
&& (getOutputVoltage() > 9) && (getSolarInCircuitVoltage() > 14)) {
|
||||
/* 有电池,太阳能输出功率大,电池电压低于14V,同时回路阻抗未测试或需要重新测试 */
|
||||
if ((getCheckImpedanceState() == FALSE || getLoopImpedance() == 0.0f)
|
||||
&& (getBatteryState() == TRUE) && (getChargCurrent() > g_cfgParameter.maxChargCurr)
|
||||
&& (getOutputVoltage() > 9) && (getSolarInCircuitVoltage() > 14)
|
||||
&& (getBatteryVoltage() < 14)) {
|
||||
TimeSliceOffset_Register(&m_impedanceCalculation, Task_impedanceCalculation
|
||||
, impedanceCalculation_reloadVal, impedanceCalculation_reloadVal);
|
||||
}
|
||||
|
||||
/* 温度检测 */
|
||||
if ((getMosTemperState() != mosTemperStart)
|
||||
&& (getHighSideMosTemperature() < g_cfgParameter.HighSideMosTemperature_start)) {
|
||||
if ((getMosTemperState() != mosTemperFull)
|
||||
&& (getHighSideMosTemperature() < g_cfgParameter.fullPowerOutputTemperature)) {
|
||||
/* 状态处于停止运行则打开充电开关 */
|
||||
if (getMosTemperState() == mosTemperStop) {
|
||||
beginChargWork();
|
||||
}
|
||||
setMosTemperState(mosTemperStart);
|
||||
setMosTemperState(mosTemperFull);
|
||||
}
|
||||
else if ((getMosTemperState() == mosTemperStart)
|
||||
&& getHighSideMosTemperature() > g_cfgParameter.HighSideMosTemperature_end) {
|
||||
setMosTemperState(mosTemperEnd);
|
||||
else if ((getMosTemperState() == mosTemperFull)
|
||||
&& getHighSideMosTemperature() > g_cfgParameter.reducePowerOutputTemperature) {
|
||||
setMosTemperState(mosTemperReduce);
|
||||
insertEventsOrderRecord(overTemperature);
|
||||
}
|
||||
else if ((getMosTemperState() == mosTemperEnd)
|
||||
&& getHighSideMosTemperature() > g_cfgParameter.HighSideMosTemperature_stop) {
|
||||
else if ((getMosTemperState() == mosTemperReduce)
|
||||
&& getHighSideMosTemperature() > g_cfgParameter.stopPowerOutputTemperature) {
|
||||
setMosTemperState(mosTemperStop);
|
||||
/* 停止充电 */
|
||||
stopChargWork();
|
||||
insertEventsOrderRecord(stopTemperature);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -218,7 +344,8 @@ void Task_refreshJudgeData(void)
|
|||
void Task_startControl(void)
|
||||
{
|
||||
/* 是否达到启动条件 */
|
||||
if (getSolarInCircuitVoltage() > g_cfgParameter.startSolarOpenCircuitV) {
|
||||
if (getSolarInCircuitVoltage() > g_cfgParameter.startSolarOpenCircuitV
|
||||
&& getSolarInCircuitVoltage() < g_cfgParameter.maxOpenSolarOutputCircuitV) {
|
||||
TimeSliceOffset_Unregister(&m_startControl);
|
||||
m_startControl.runFlag = 0;
|
||||
|
||||
|
@ -233,6 +360,11 @@ void Task_startControl(void)
|
|||
/* 启动软起动任务 */
|
||||
TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
|
||||
}
|
||||
|
||||
if (getSolarInCircuitVoltage() >= g_cfgParameter.maxOpenSolarOutputCircuitV) {
|
||||
insertEventsOrderRecord(overInputVolt);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* @brief 打开启动任务
|
||||
|
@ -309,8 +441,8 @@ void Task_impedanceCalculation(void)
|
|||
|
||||
if (num == 1) {
|
||||
setChargControlFlag(FALSE);
|
||||
setDutyRatio(0.7);
|
||||
set_pwmDutyRatio(getDutyRatio());
|
||||
setDutyRatio(0.5);
|
||||
// set_pwmDutyRatio(getDutyRatio());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -318,11 +450,13 @@ void Task_impedanceCalculation(void)
|
|||
currOne = getChargCurrent() - getDischargCurrent();
|
||||
voltOne = getOutputVoltage();
|
||||
setDutyRatio(0.85);
|
||||
set_pwmDutyRatio(getDutyRatio());
|
||||
// set_pwmDutyRatio(getDutyRatio());
|
||||
return;
|
||||
}
|
||||
|
||||
if (num == 21) {
|
||||
num = 0;
|
||||
|
||||
TimeSliceOffset_Unregister(&m_impedanceCalculation);
|
||||
m_impedanceCalculation.runFlag = 0;
|
||||
|
||||
|
@ -331,15 +465,18 @@ void Task_impedanceCalculation(void)
|
|||
float tempLoopImpedance = 0;
|
||||
tempLoopImpedance = (voltOne - voltTwo) / (currOne - currTwo);
|
||||
|
||||
// if (tempLoopImpedance < 1.0f && tempLoopImpedance > 0.05f) {
|
||||
// g_cfgParameter.loopImpedance = tempLoopImpedance;
|
||||
// saveLoopImpedance(&g_cfgParameter.loopImpedance);
|
||||
// setCheckImpedanceState();
|
||||
// }
|
||||
/* 判断回路阻抗是否合理 */
|
||||
if (tempLoopImpedance < 1.0f && tempLoopImpedance > 0.05f) {
|
||||
g_cfgParameter.loopImpedance = tempLoopImpedance;
|
||||
saveLoopImpedance(&g_cfgParameter.loopImpedance);
|
||||
if (setLoopImpedance(tempLoopImpedance) == TRUE) {
|
||||
saveLoopImpedance();
|
||||
setCheckImpedanceState();
|
||||
}
|
||||
num = 0;
|
||||
}
|
||||
|
||||
setMPPT_Mode(MPPT);
|
||||
setMPPT_Mode(MPPT);
|
||||
setChargControlFlag(TRUE);
|
||||
return;
|
||||
}
|
||||
|
@ -382,7 +519,7 @@ void Task_collectOpenCircuitVoltage(void)
|
|||
if (getBatteryState()) {
|
||||
collectOpenCircuitVoltageYesFlag = TRUE;
|
||||
stopChargWork();
|
||||
/* 设置延时为1000-500ms */
|
||||
/* 设置延时为(1000-500)ms */
|
||||
m_collectOpenCircuitVoltage.count = 500;
|
||||
}
|
||||
collectOpenCircuitVoltageYesNUM = 0;
|
||||
|
@ -390,92 +527,95 @@ void Task_collectOpenCircuitVoltage(void)
|
|||
|
||||
/* 检测开路电压 */
|
||||
if (collectOpenCircuitVoltageYesNUM == g_cfgParameter.collectOpenCircuitVoltageTime + 1) {
|
||||
setSolarOpenCircuitVoltage();
|
||||
beginChargWork();
|
||||
collectOpenCircuitVoltageYesFlag = FALSE;
|
||||
/* 有电池才进行开路电压检测 */
|
||||
if (getBatteryState()) {
|
||||
setSolarOpenCircuitVoltage();
|
||||
beginChargWork();
|
||||
collectOpenCircuitVoltageYesFlag = FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 开启HY配置模式后,配置完成后120S后自动退出
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_beginHYconfigMode(void)
|
||||
{
|
||||
static uint8_t num = 0;
|
||||
num++;
|
||||
if (num >= 120) {
|
||||
TimeSliceOffset_Unregister(&m_beginHYconfigMode);
|
||||
m_beginHYconfigMode.runFlag = 0;
|
||||
num = 0;
|
||||
setHYconfigModeState(FALSE);
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * @brief 开启HY配置模式后,配置完成后120S后自动退出
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void Task_beginHYconfigMode(void)
|
||||
// {
|
||||
// static uint8_t num = 0;
|
||||
// num++;
|
||||
// if (num >= 120) {
|
||||
// TimeSliceOffset_Unregister(&m_beginHYconfigMode);
|
||||
// m_beginHYconfigMode.runFlag = 0;
|
||||
// num = 0;
|
||||
// setHYconfigModeState(FALSE);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 开启HY配置模式后启动退出任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void beginHYconfigMode(void)
|
||||
{
|
||||
setHYconfigModeState(TRUE);
|
||||
TimeSliceOffset_Register(&m_beginHYconfigMode, Task_beginHYconfigMode
|
||||
, beginHYconfigMode_reloadVal, beginHYconfigMode_offset);
|
||||
}
|
||||
// /**
|
||||
// * @brief 开启HY配置模式后启动退出任务
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void beginHYconfigMode(void)
|
||||
// {
|
||||
// setHYconfigModeState(TRUE);
|
||||
// TimeSliceOffset_Register(&m_beginHYconfigMode, Task_beginHYconfigMode
|
||||
// , beginHYconfigMode_reloadVal, beginHYconfigMode_offset);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 初始化串口任务,确定使用的协议
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void uartTaskInit(void)
|
||||
{
|
||||
// if (g_cfgParameter.CommunicationProtocolType == 0x00) {
|
||||
// uart_judge_handle = read_and_process_uart_data;
|
||||
// } else if (g_cfgParameter.CommunicationProtocolType == 0x01) {
|
||||
// uart_judge_handle = HY_read_and_process_uart_data;
|
||||
// }
|
||||
// /**
|
||||
// * @brief 初始化串口任务,确定使用的协议
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void uartTaskInit(void)
|
||||
// {
|
||||
// // if (g_cfgParameter.CommunicationProtocolType == 0x00) {
|
||||
// // uart_judge_handle = read_and_process_uart_data;
|
||||
// // } else if (g_cfgParameter.CommunicationProtocolType == 0x01) {
|
||||
// // uart_judge_handle = HY_read_and_process_uart_data;
|
||||
// // }
|
||||
|
||||
uart_judge_handle = HY_read_and_process_uart_data;
|
||||
}
|
||||
// uart_judge_handle = HY_read_and_process_uart_data;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 检测有无通信数据传来
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_usartJudge(void)
|
||||
{
|
||||
/* 检测到对上通信串口有数据启动读取并解析任务 */
|
||||
if (uart_dev_char_present(g_gw485_uart2_handle)) {
|
||||
TimeSliceOffset_Register(&m_usartHandle, Task_usartHandle
|
||||
, usartHandle_reloadVal, usartHandle_offset);
|
||||
}
|
||||
}
|
||||
// /**
|
||||
// * @brief 检测有无通信数据传来
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void Task_usartJudge(void)
|
||||
// {
|
||||
// /* 检测到对上通信串口有数据启动读取并解析任务 */
|
||||
// if (uart_dev_char_present(g_gw485_uart2_handle)) {
|
||||
// TimeSliceOffset_Register(&m_usartHandle, Task_usartHandle
|
||||
// , usartHandle_reloadVal, usartHandle_offset);
|
||||
// }
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 读取并解析对上通讯的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_usartHandle(void)
|
||||
{
|
||||
TimeSliceOffset_Unregister(&m_usartHandle);
|
||||
m_usartHandle.runFlag = 0;
|
||||
uart_judge_handle(g_gw485_uart2_handle);
|
||||
}
|
||||
// /**
|
||||
// * @brief 读取并解析对上通讯的数据
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void Task_usartHandle(void)
|
||||
// {
|
||||
// TimeSliceOffset_Unregister(&m_usartHandle);
|
||||
// m_usartHandle.runFlag = 0;
|
||||
// uart_judge_handle(g_gw485_uart2_handle);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 读取并解析配置文件的数据
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_usartCfg(void)
|
||||
{
|
||||
read_and_process_config_data();
|
||||
}
|
||||
// /**
|
||||
// * @brief 读取并解析配置文件的数据
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void Task_usartCfg(void)
|
||||
// {
|
||||
// read_and_process_config_data();
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 短路保护任务,短路后启动该任务
|
||||
|
@ -488,7 +628,7 @@ void Task_shortCircuitProtection(void)
|
|||
num++;
|
||||
|
||||
/* 设定输出短路保护时间 */
|
||||
if (num == g_cfgParameter.outputAgainFlagTime) {
|
||||
if (num == g_cfgParameter.shortCircuitJudgmentDelay) {
|
||||
num = 0;
|
||||
zeroShortCircuit();
|
||||
TimeSliceOffset_Unregister(&m_shortCircuitProtection);
|
||||
|
@ -497,7 +637,7 @@ void Task_shortCircuitProtection(void)
|
|||
/* 仍然过流,彻底关闭输出 */
|
||||
if (readOverCurrState() == FALSE) {
|
||||
setPowerOutput(FALSE);
|
||||
}
|
||||
}
|
||||
/* 不过流,则状态位复位 */
|
||||
else {
|
||||
setShortCircuitFlag(FALSE);
|
||||
|
@ -564,7 +704,7 @@ void Task_excessiveLoad(void)
|
|||
}
|
||||
|
||||
/* 仅过载一次,达到时间后关闭该任务 */
|
||||
if (num == g_cfgParameter.excessiveLoadFlagTime) {
|
||||
if (num == g_cfgParameter.inputPowerLowJudgmentDelay) {
|
||||
num = 0;
|
||||
setExcessiveLoadFlag(FALSE);
|
||||
TimeSliceOffset_Unregister(&m_excessiveLoad);
|
||||
|
@ -578,7 +718,7 @@ void Task_excessiveLoad(void)
|
|||
}
|
||||
|
||||
/* 达到时间就重新尝试输出 */
|
||||
if (numLong == g_cfgParameter.eLAgainTime) {
|
||||
if (numLong == g_cfgParameter.inputPowerLowAgainOutputDelay) {
|
||||
numLong = 0;
|
||||
TimeSliceOffset_Unregister(&m_excessiveLoad);
|
||||
m_excessiveLoad.runFlag = 0;
|
||||
|
@ -596,4 +736,99 @@ void startExcessiveLoadProtection(void)
|
|||
{
|
||||
TimeSliceOffset_Register(&m_excessiveLoad, Task_excessiveLoad
|
||||
, excessiveLoad_reloadVal, excessiveLoad_offset);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 检测总线是否空闲,并且判断有无数据需要发送
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_busFree(void)
|
||||
{
|
||||
setGwState();
|
||||
setBatState();
|
||||
check_sendState();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @brief 中断发送任务
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void Task_interruptSend(void)
|
||||
// {
|
||||
// // if(check_sendState() == TRUE) {
|
||||
// // TimeSliceOffset_Unregister(&m_interruptSend);
|
||||
// // m_interruptSend.runFlag = 0;
|
||||
// // }
|
||||
// }
|
||||
|
||||
// /**
|
||||
// * @brief 启动中断发送任务
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void startInterruptSendTask(void)
|
||||
// {
|
||||
// TimeSliceOffset_Register(&m_interruptSend, Task_interruptSend
|
||||
// , interruptSend_reloadVal, interruptSend_offset);
|
||||
// }
|
||||
|
||||
/**
|
||||
* @brief 软件短路保护任务,一段时间中连续出现短路,则关闭输出
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_softShortCircuit(void)
|
||||
{
|
||||
static uint8_t num = 0;
|
||||
|
||||
if (2 == num++) {
|
||||
setPowerOutput(TRUE);
|
||||
}
|
||||
|
||||
if (num >= g_cfgParameter.shortCircuitJudgmentDelay) {
|
||||
num = 0;
|
||||
if (getShortCircuit() == 1) {
|
||||
setShortCircuitFlag(FALSE);
|
||||
}
|
||||
zeroShortCircuit();
|
||||
TimeSliceOffset_Unregister(&m_softShortCircuit);
|
||||
m_softShortCircuit.runFlag = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 启动软件短路保护任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void startSoftShortCircuitProtection(void)
|
||||
{
|
||||
TimeSliceOffset_Register(&m_softShortCircuit, Task_softShortCircuit
|
||||
, softShortCircuit_reloadVal, softShortCircuit_offset);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 启动软件解析任务
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_uart(void)
|
||||
{
|
||||
gw485DataAnalysis(g_gw485_uart2_handle);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief 将记录下来的事件存入flash中
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void Task_SOE(void)
|
||||
{
|
||||
setEventsOrderRecord();
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ void RUN_LEN_Open(void);
|
|||
void RUN_LEN_Close(void);
|
||||
void RUN_LED(void);
|
||||
|
||||
BOOL FFMOS_CON_read(void);
|
||||
void FFMOS_CON_Open(void);
|
||||
void FFMOS_CON_Close(void);
|
||||
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#ifndef FM_RTC_H_
|
||||
#define FM_RTC_H_
|
||||
|
||||
#include "HD_RTC.h"
|
||||
#include "chargControlTypes.h"
|
||||
|
||||
void FM_RTC_Init(void);
|
||||
void setRTC_Time(timeInfo *time);
|
||||
void getRTC_Time(timeInfo *time);
|
||||
uint32_t differTime(timeInfo *time1, timeInfo *time2);
|
||||
|
||||
#endif
|
|
@ -23,6 +23,7 @@ typedef struct _adcCapture
|
|||
|
||||
void ADC_Capture_Init(void);
|
||||
void proportionalInt(int mode);
|
||||
uint16_t setfirstStageProtectionValue(float curr);
|
||||
|
||||
float get_CHG_CURR(void);
|
||||
float get_PV_VOLT_OUT(void);
|
||||
|
@ -30,7 +31,12 @@ float get_DSG_CURR(void);
|
|||
float get_PV1_VOLT_IN(void);
|
||||
float get_PV_VOLT_IN1(void);
|
||||
float get_MOSFET_Temper(void);
|
||||
float get_OUT_VOLT_IN(void);
|
||||
|
||||
void adcCaptureFir();
|
||||
|
||||
extern void setSoftShortCircuit(uint16_t disChargCurrAdcNum);
|
||||
|
||||
extern void chargControl(void);
|
||||
|
||||
#endif
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
#include "main.h"
|
||||
#include "w25qxx.h"
|
||||
// #include "w25q256.h"
|
||||
|
||||
void Flash_Init(void);
|
||||
void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead);
|
||||
|
|
|
@ -52,4 +52,8 @@ void start_bat485Rx_It(void);
|
|||
extern void gw485_RxIt(void);
|
||||
extern void bat485_RxIt(void);
|
||||
|
||||
extern void gw485_TxIt(void);
|
||||
extern void bat485_TxIt(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -93,6 +93,19 @@ void RUN_LED(void)
|
|||
HAL_GPIO_TogglePin(RUN_LED_GPIO_Port, RUN_LED_Pin);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 打开mppt电感后的输出mos管
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
BOOL FFMOS_CON_read(void)
|
||||
{
|
||||
if (HAL_GPIO_ReadPin(FFMOS_CON_GPIO_Port, FFMOS_CON_Pin)) {
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 打开mppt电感后的输出mos管
|
||||
* @param None
|
||||
|
@ -165,11 +178,24 @@ BOOL readOverCurrState(void)
|
|||
*/
|
||||
BOOL readOnlyPowerOutputState(void)
|
||||
{
|
||||
if (HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin)
|
||||
&& HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin)
|
||||
&& HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin)) {
|
||||
return TRUE;
|
||||
}
|
||||
// static volatile GPIO_PinState gpioTemp1, gpioTemp2, gpioTemp3;
|
||||
GPIO_PinState gpioTemp1, gpioTemp2, gpioTemp3;
|
||||
|
||||
gpioTemp1 = HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin);
|
||||
gpioTemp2 = HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin);
|
||||
gpioTemp3 = HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin);
|
||||
|
||||
if (gpioTemp1 == GPIO_PIN_SET
|
||||
&& gpioTemp2 == GPIO_PIN_SET
|
||||
&& gpioTemp3 == GPIO_PIN_SET) {
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
// if (HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin)
|
||||
// && HAL_GPIO_ReadPin(POW_OUT_CON_GPIO_Port, POW_OUT_CON_Pin)
|
||||
// && HAL_GPIO_ReadPin(DSG_PROT_GPIO_Port, DSG_PROT_Pin)) {
|
||||
// return TRUE;
|
||||
// }
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
@ -200,9 +226,9 @@ void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
|
|||
WORK_VOLT_Interrupt();
|
||||
}
|
||||
|
||||
else if (GPIO_Pin == DSG_PROT_Pin) {
|
||||
DSG_PROT_Interrupt();
|
||||
}
|
||||
// else if (GPIO_Pin == DSG_PROT_Pin) {
|
||||
// DSG_PROT_Interrupt();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,91 @@
|
|||
|
||||
#include "FM_RTC.h"
|
||||
|
||||
|
||||
extern RTC_HandleTypeDef hrtc;
|
||||
|
||||
/**
|
||||
* @brief 初始化rtc
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void FM_RTC_Init(void)
|
||||
{
|
||||
HD_RTC_Init();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置rtc时间
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void setRTC_Time(timeInfo *time)
|
||||
{
|
||||
/* 日期结构体 */
|
||||
static RTC_DateTypeDef setData;
|
||||
/* 时间结构体 */
|
||||
static RTC_TimeTypeDef setTime;
|
||||
|
||||
setData.Year = time->year;
|
||||
setData.Month = time->month;
|
||||
setData.Date = time->day;
|
||||
|
||||
setTime.Hours = time->hour;
|
||||
setTime.Minutes = time->minute;
|
||||
setTime.Seconds = time->second;
|
||||
|
||||
HAL_RTC_SetDate(&hrtc, &setData, RTC_FORMAT_BIN);
|
||||
HAL_RTC_SetTime(&hrtc, &setTime, RTC_FORMAT_BIN);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 得到rtc时间
|
||||
* @param
|
||||
* @retval
|
||||
*/
|
||||
void getRTC_Time(timeInfo *time)
|
||||
{
|
||||
/* 日期结构体 */
|
||||
static RTC_DateTypeDef getData;
|
||||
/* 时间结构体 */
|
||||
static RTC_TimeTypeDef getTime;
|
||||
|
||||
HAL_RTC_GetDate(&hrtc, &getData, RTC_FORMAT_BIN);
|
||||
HAL_RTC_GetTime(&hrtc, &getTime, RTC_FORMAT_BIN);
|
||||
|
||||
time->year = getData.Year;
|
||||
time->month = getData.Month;
|
||||
time->day = getData.Date;
|
||||
time->hour = getTime.Hours;
|
||||
time->minute = getTime.Minutes;
|
||||
time->second = getTime.Seconds;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief time1 - time2的差值
|
||||
* @param
|
||||
* @retval 返回的时间单位为秒
|
||||
*/
|
||||
uint32_t differTime(timeInfo *time1, timeInfo *time2)
|
||||
{
|
||||
uint32_t differ_s;
|
||||
|
||||
differ_s = time1->second - time2->second
|
||||
+ time1->minute * 60 - time2->minute * 60
|
||||
+ time1->hour * 3600 - time2->hour * 3600
|
||||
+ time1->day * 86400 - time2->day * 86400
|
||||
+ (time1->month - time2->month) * 2592000
|
||||
+ (time1->year - time2->year) * 31536000;
|
||||
|
||||
return differ_s;
|
||||
}
|
||||
|
||||
// /**
|
||||
// * @brief time3根据time1和time2差值得到time3,time3 += time1 - time2
|
||||
// * @param
|
||||
// * @retval
|
||||
// */
|
||||
// void chargeTime(timeInfo *time1, timeInfo *time2, timeInfo *time3)
|
||||
// {
|
||||
|
||||
// }
|
|
@ -19,7 +19,7 @@ void tim_Init(void)
|
|||
// HAL_TIM_Base_Start(&htim3);
|
||||
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_4);
|
||||
|
||||
HD_controlTim_Init();
|
||||
// HD_controlTim_Init();
|
||||
HAL_TIM_Base_Start_IT(&htim7);
|
||||
|
||||
HD_taskBaseTim_Init();
|
||||
|
@ -62,7 +62,7 @@ void set_pwmDutyRatio(float DutyRatio)
|
|||
{
|
||||
uint32_t Pulse = (int)(DutyRatio * PWM_RESOLUTION);
|
||||
|
||||
set_pwmPulse(Pulse);
|
||||
set_pwmPulse(Pulse);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -98,7 +98,9 @@ enum {
|
|||
CHG_CURR_NUM = 2,
|
||||
PV_VOLT_IN_NUM = 3,
|
||||
};
|
||||
int16_t adcBuff[4];
|
||||
// int16_t adcBuff[4];
|
||||
|
||||
int16_t adcBuff[40];
|
||||
/* 指向adcCapture中的inData16数组中的第一位也是最后一位 */
|
||||
uint8_t pointer;
|
||||
|
||||
|
@ -113,6 +115,7 @@ static float P_PV_VOLT_OUT = 0;
|
|||
static float P_DSG_CURR = 0;
|
||||
static float P_PV1_VOLT_IN = 0;
|
||||
static float P_PV_VOLT_IN1 = 0;
|
||||
static float P_OUT_VOLT_IN = 0;
|
||||
|
||||
/* 2.5为adc的电压,4095是2^adc的位数 - 1 */
|
||||
// const float32_t Proportion = 2.5 / 4095;
|
||||
|
@ -160,7 +163,7 @@ void ADC_Capture_Init(void)
|
|||
// captureFirInit();
|
||||
|
||||
HAL_TIM_Base_Start(&htim6);
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adcBuff, 4);
|
||||
HAL_ADC_Start_DMA(&hadc1, (uint32_t *)adcBuff, 40);
|
||||
|
||||
// /* 光伏充电输出电流比例,放大倍数*电阻 */
|
||||
// P_CHG_CURR = (1.0 / (50 * (1 / (1 / 0.01 + 1 / 0.002)))) * Proportion;
|
||||
|
@ -186,13 +189,15 @@ void proportionalInt(int mode)
|
|||
/* 光伏充电输出电流比例,放大倍数*电阻 */
|
||||
P_CHG_CURR = (1.0 / (50 * (1 / (1 / 0.01 + 1 / 0.002)))) * Proportion;
|
||||
/* 充电控制盒输出电压比例,分压系数 */
|
||||
P_PV_VOLT_OUT = ((47.0 + 10.0) / 10.0) * Proportion;
|
||||
P_PV_VOLT_OUT = ((56.0 + 10.0) / 10.0) * Proportion;
|
||||
/* 放电电流采集电流倍数 */
|
||||
P_DSG_CURR = (1.0 / (50 * (1 / (1 / 0.002 * 2)))) * Proportion;
|
||||
P_DSG_CURR = (1.0 / (50 * (1 / (1 / 0.002 + 1 / 0.001)))) * Proportion;
|
||||
/* 光伏板输出电压比例 */
|
||||
P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
/* 系统电源电压比例 */
|
||||
P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion;
|
||||
P_PV_VOLT_IN1 = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
/* 输出外部电压比例 */
|
||||
P_OUT_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
}
|
||||
|
||||
/* 电源盒外还有网关功能 */
|
||||
|
@ -200,27 +205,42 @@ void proportionalInt(int mode)
|
|||
/* 光伏充电输出电流比例,放大倍数*电阻 */
|
||||
P_CHG_CURR = (1.0 / (50 * 0.005)) * Proportion;
|
||||
/* 光伏充电输出电压比例,分压系数 */
|
||||
P_PV_VOLT_OUT = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
P_PV_VOLT_OUT = ((56.0 + 10.0) / 10.0) * Proportion;
|
||||
/* 放电电流采集电流倍数 */
|
||||
P_DSG_CURR = (1.0 / (50 * 0.005)) * Proportion;
|
||||
/* 光伏1开路输出电压比例 */
|
||||
P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
/* 系统电源电压比例 */
|
||||
P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion;
|
||||
/* 输出外部电压比例 */
|
||||
P_OUT_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
}
|
||||
|
||||
/* 光伏充电输出电流比例,放大倍数*电阻 */
|
||||
P_CHG_CURR = (1.0 / (50 * (1 / (1 / 0.01 + 1 / 0.002)))) * Proportion;
|
||||
/* 充电控制盒输出电压比例,分压系数 */
|
||||
P_PV_VOLT_OUT = ((47.0 + 10.0) / 10.0) * Proportion;
|
||||
/* 放电电流采集电流倍数 */
|
||||
P_DSG_CURR = (1.0 / (50 * (1 / (1 / 0.002 * 2)))) * Proportion;
|
||||
/* 光伏板输出电压比例 */
|
||||
P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
/* 系统电源电压比例 */
|
||||
P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion;
|
||||
|
||||
|
||||
// /* 光伏充电输出电流比例,放大倍数*电阻 */
|
||||
// P_CHG_CURR = (1.0 / (50 * (1 / (1 / 0.01 + 1 / 0.002)))) * Proportion;
|
||||
// /* 充电控制盒输出电压比例,分压系数 */
|
||||
// P_PV_VOLT_OUT = ((47.0 + 10.0) / 10.0) * Proportion;
|
||||
// /* 放电电流采集电流倍数 */
|
||||
// P_DSG_CURR = (1.0 / (50 * (1 / (1 / 0.002 * 2)))) * Proportion;
|
||||
// /* 光伏板输出电压比例 */
|
||||
// P_PV1_VOLT_IN = ((47.0 + 4.7) / 4.7) * Proportion;
|
||||
// /* 系统电源电压比例 */
|
||||
// P_PV_VOLT_IN1 = ((47 + 4.7) / 4.7) * Proportion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 设置第一段保护ADC采样的值
|
||||
* @param
|
||||
* @retval None
|
||||
*/
|
||||
uint16_t setfirstStageProtectionValue(float curr)
|
||||
{
|
||||
return (uint16_t)(curr / P_DSG_CURR);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define N 4
|
||||
/**
|
||||
* @brief 中位值平均滤波
|
||||
|
@ -356,7 +376,7 @@ float get_PV1_VOLT_IN(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief 得到系统电压电压
|
||||
* @brief 得到系统电压
|
||||
* @param
|
||||
* @retval V 电压值
|
||||
*/
|
||||
|
@ -410,6 +430,39 @@ float get_MOSFET_Temper(void)
|
|||
return T;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief 输出外部电压
|
||||
* @param
|
||||
* @retval V 电压值
|
||||
*/
|
||||
float get_OUT_VOLT_IN(void)
|
||||
{
|
||||
float V;
|
||||
uint16_t V_ADC;
|
||||
static uint16_t V_ADCTemp = (uint16_t)(0.52f / 3.0f * 4095);
|
||||
// static uint16_t V_ADCTemp = (uint16_t)(0.17f / 3.0f * 4095);
|
||||
|
||||
V_ADC = ADC2_Capture(OUT_VOLT_IN_CHANNEL);
|
||||
|
||||
|
||||
if (HAL_GPIO_ReadPin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin)) {
|
||||
V = (float)(V_ADC) * P_OUT_VOLT_IN;
|
||||
} else {
|
||||
if (V_ADC > V_ADCTemp) {
|
||||
V = (float)(V_ADC - V_ADCTemp) * P_OUT_VOLT_IN;
|
||||
}
|
||||
V = (float)(V_ADC) * P_OUT_VOLT_IN;
|
||||
}
|
||||
|
||||
#ifdef enable_Printf_VI
|
||||
debug("\n OUT_VOLT_IN ADC : %d \n", V_ADC);
|
||||
debug(" OUT_VOLT_IN V : %f \n", V);
|
||||
#endif
|
||||
|
||||
return V;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief adc转换并传输完成后进入该回调函数
|
||||
* @param hdma dma
|
||||
|
@ -418,35 +471,59 @@ float get_MOSFET_Temper(void)
|
|||
void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef *hdma)
|
||||
{
|
||||
if (hdma->Instance == ADC1) {
|
||||
WORK_VOLT_capture.totalInData -= WORK_VOLT_capture.inData16[pointer];
|
||||
DSG_CURR_capture.totalInData -= DSG_CURR_capture.inData16[pointer];
|
||||
PV_VOLT_IN_capture.totalInData -= PV_VOLT_IN_capture.inData16[pointer];
|
||||
CHG_CURR_capture.totalInData -= CHG_CURR_capture.inData16[pointer];
|
||||
// HAL_GPIO_TogglePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin);
|
||||
// HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin,GPIO_PIN_SET);
|
||||
|
||||
WORK_VOLT_capture.inData16[pointer] = adcBuff[WORK_VOLT_NUM];
|
||||
DSG_CURR_capture.inData16[pointer] = adcBuff[DSG_CURR_NUM];
|
||||
PV_VOLT_IN_capture.inData16[pointer] = adcBuff[PV_VOLT_IN_NUM];
|
||||
CHG_CURR_capture.inData16[pointer] = adcBuff[CHG_CURR_NUM];
|
||||
// setSoftShortCircuit(adcBuff[DSG_CURR_NUM]);
|
||||
|
||||
WORK_VOLT_capture.totalInData += WORK_VOLT_capture.inData16[pointer];
|
||||
DSG_CURR_capture.totalInData += DSG_CURR_capture.inData16[pointer];
|
||||
PV_VOLT_IN_capture.totalInData += PV_VOLT_IN_capture.inData16[pointer];
|
||||
CHG_CURR_capture.totalInData += CHG_CURR_capture.inData16[pointer];
|
||||
// WORK_VOLT_capture.totalInData -= WORK_VOLT_capture.inData16[pointer];
|
||||
// DSG_CURR_capture.totalInData -= DSG_CURR_capture.inData16[pointer];
|
||||
// PV_VOLT_IN_capture.totalInData -= PV_VOLT_IN_capture.inData16[pointer];
|
||||
// CHG_CURR_capture.totalInData -= CHG_CURR_capture.inData16[pointer];
|
||||
|
||||
pointer++;
|
||||
if (pointer >= 10) {
|
||||
pointer = 0;
|
||||
}
|
||||
// WORK_VOLT_capture.inData16[pointer] = adcBuff[WORK_VOLT_NUM];
|
||||
// DSG_CURR_capture.inData16[pointer] = adcBuff[DSG_CURR_NUM];
|
||||
// PV_VOLT_IN_capture.inData16[pointer] = adcBuff[PV_VOLT_IN_NUM];
|
||||
// CHG_CURR_capture.inData16[pointer] = adcBuff[CHG_CURR_NUM];
|
||||
|
||||
arm_copy_f32(WORK_VOLT_capture.IODataF + 1, WORK_VOLT_capture.IODataF, 3);
|
||||
arm_copy_f32(DSG_CURR_capture.IODataF + 1, DSG_CURR_capture.IODataF, 3);
|
||||
arm_copy_f32(PV_VOLT_IN_capture.IODataF + 1, PV_VOLT_IN_capture.IODataF, 3);
|
||||
arm_copy_f32(CHG_CURR_capture.IODataF + 1, CHG_CURR_capture.IODataF, 3);
|
||||
// WORK_VOLT_capture.totalInData += WORK_VOLT_capture.inData16[pointer];
|
||||
// DSG_CURR_capture.totalInData += DSG_CURR_capture.inData16[pointer];
|
||||
// PV_VOLT_IN_capture.totalInData += PV_VOLT_IN_capture.inData16[pointer];
|
||||
// CHG_CURR_capture.totalInData += CHG_CURR_capture.inData16[pointer];
|
||||
|
||||
// pointer++;
|
||||
// if (pointer >= 10) {
|
||||
// pointer = 0;
|
||||
// }
|
||||
|
||||
// arm_copy_f32(WORK_VOLT_capture.IODataF + 1, WORK_VOLT_capture.IODataF, 3);
|
||||
// arm_copy_f32(DSG_CURR_capture.IODataF + 1, DSG_CURR_capture.IODataF, 3);
|
||||
// arm_copy_f32(PV_VOLT_IN_capture.IODataF + 1, PV_VOLT_IN_capture.IODataF, 3);
|
||||
// arm_copy_f32(CHG_CURR_capture.IODataF + 1, CHG_CURR_capture.IODataF, 3);
|
||||
|
||||
// WORK_VOLT_capture.IODataF[3] = (float32_t)WORK_VOLT_capture.totalInData / indata16_size;
|
||||
// DSG_CURR_capture.IODataF[3] = (float32_t)DSG_CURR_capture.totalInData / indata16_size;
|
||||
// PV_VOLT_IN_capture.IODataF[3] = (float32_t)PV_VOLT_IN_capture.totalInData / indata16_size;
|
||||
// CHG_CURR_capture.IODataF[3] = (float32_t)CHG_CURR_capture.totalInData / indata16_size;
|
||||
|
||||
// HAL_GPIO_TogglePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin);
|
||||
// HAL_GPIO_WritePin(POW_FF_CON_GPIO_Port, POW_FF_CON_Pin,GPIO_PIN_RESET);
|
||||
|
||||
|
||||
|
||||
WORK_VOLT_capture.outData = (float32_t)(adcBuff[0] + adcBuff[4] + adcBuff[8] + adcBuff[12] + adcBuff[16]
|
||||
+ adcBuff[20] + adcBuff[24] + adcBuff[28] + adcBuff[32] + adcBuff[36]) / indata16_size;
|
||||
DSG_CURR_capture.outData = (float32_t)(adcBuff[1] + adcBuff[5] + adcBuff[9] + adcBuff[13] + adcBuff[17]
|
||||
+ adcBuff[21] + adcBuff[25] + adcBuff[29] + adcBuff[33] + adcBuff[37]) / indata16_size;
|
||||
CHG_CURR_capture.outData = (float32_t)(adcBuff[2] + adcBuff[6] + adcBuff[10] + adcBuff[14] + adcBuff[18]
|
||||
+ adcBuff[22] + adcBuff[26] + adcBuff[30] + adcBuff[34] + adcBuff[38]) / indata16_size;
|
||||
PV_VOLT_IN_capture.outData = (float32_t)(adcBuff[3] + adcBuff[7] + adcBuff[11] + adcBuff[15] + adcBuff[19]
|
||||
+ adcBuff[23] + adcBuff[27] + adcBuff[31] + adcBuff[35] + adcBuff[39]) / indata16_size;
|
||||
|
||||
setSoftShortCircuit(DSG_CURR_capture.outData);
|
||||
|
||||
chargControl();
|
||||
|
||||
WORK_VOLT_capture.IODataF[3] = (float32_t)WORK_VOLT_capture.totalInData / indata16_size;
|
||||
DSG_CURR_capture.IODataF[3] = (float32_t)DSG_CURR_capture.totalInData / indata16_size;
|
||||
PV_VOLT_IN_capture.IODataF[3] = (float32_t)PV_VOLT_IN_capture.totalInData / indata16_size;
|
||||
CHG_CURR_capture.IODataF[3] = (float32_t)CHG_CURR_capture.totalInData / indata16_size;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,15 +597,15 @@ void adcCaptureFir(void)
|
|||
// PV_VOLT_IN_capture.outData = 1;
|
||||
// CHG_CURR_capture.outData = 1;
|
||||
|
||||
static float32_t outputf;
|
||||
arm_dot_prod_f32(WORK_VOLT_capture.IODataF, firLP, firLen, &outputf);
|
||||
WORK_VOLT_capture.outData = (int16_t)outputf;
|
||||
arm_dot_prod_f32(DSG_CURR_capture.IODataF, firLP, firLen, &outputf);
|
||||
DSG_CURR_capture.outData = (int16_t)outputf;
|
||||
arm_dot_prod_f32(PV_VOLT_IN_capture.IODataF, firLP, firLen, &outputf);
|
||||
PV_VOLT_IN_capture.outData = (int16_t)outputf;
|
||||
arm_dot_prod_f32(CHG_CURR_capture.IODataF, firLP, firLen, &outputf);
|
||||
CHG_CURR_capture.outData = (int16_t)outputf;
|
||||
// static float32_t outputf;
|
||||
// arm_dot_prod_f32(WORK_VOLT_capture.IODataF, firLP, firLen, &outputf);
|
||||
// WORK_VOLT_capture.outData = (int16_t)outputf;
|
||||
// arm_dot_prod_f32(DSG_CURR_capture.IODataF, firLP, firLen, &outputf);
|
||||
// DSG_CURR_capture.outData = (int16_t)outputf;
|
||||
// arm_dot_prod_f32(PV_VOLT_IN_capture.IODataF, firLP, firLen, &outputf);
|
||||
// PV_VOLT_IN_capture.outData = (int16_t)outputf;
|
||||
// arm_dot_prod_f32(CHG_CURR_capture.IODataF, firLP, firLen, &outputf);
|
||||
// CHG_CURR_capture.outData = (int16_t)outputf;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
#include "flash.h"
|
||||
// #include "gpio.h"
|
||||
#include "main.h"
|
||||
|
||||
/**
|
||||
* @brief flash初始化
|
||||
|
@ -11,12 +13,60 @@ void Flash_Init(void)
|
|||
HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET);
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
/*Configure GPIO pin : FLASH_CS_Pin */
|
||||
GPIO_InitStruct.Pin = FLASH_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
HAL_GPIO_Init(FLASH_CS_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
// GPIO_InitStruct.Pin = FLASH_CS_Pin | FLASH_CLK_Pin | FLASH_MISO_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
// GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// // GPIO_InitStruct.Pin = FLASH_MOSI_Pin;
|
||||
// // GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
// // GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
// // GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
// // HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// GPIO_InitStruct.Pin = FLASH_CS_Pin | FLASH_CLK_Pin | FLASH_MISO_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
// GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// GPIO_InitStruct.Pin = FLASH_MOSI_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
// GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
// __HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
|
||||
// /*Configure GPIO pin Output Level */
|
||||
// // HAL_GPIO_WritePin(GPIOA, FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin, GPIO_PIN_RESET);
|
||||
// HAL_GPIO_WritePin(GPIOA, FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MOSI_Pin, GPIO_PIN_RESET);
|
||||
|
||||
// /*Configure GPIO pins : FLASH_CS_Pin FLASH_CLK_Pin FLASH_MISO_Pin */
|
||||
// // GPIO_InitStruct.Pin = FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MISO_Pin;
|
||||
// GPIO_InitStruct.Pin = FLASH_CS_Pin|FLASH_CLK_Pin|FLASH_MOSI_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
// GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
// HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
// /*Configure GPIO pin : FLASH_MOSI_Pin */
|
||||
// GPIO_InitStruct.Pin = FLASH_MISO_Pin;
|
||||
// GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
||||
// GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
// HAL_GPIO_Init(FLASH_MOSI_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
// Flash_GPIO_Init();
|
||||
W25QXX_Init();
|
||||
}
|
||||
|
||||
|
@ -29,6 +79,8 @@ void Flash_Init(void)
|
|||
void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead)
|
||||
{
|
||||
W25QXX_Read(pBuffer, ReadAddr, NumByteToRead);
|
||||
// Flash_Read(pBuffer, ReadAddr, NumByteToRead);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,4 +92,6 @@ void read_Flash(uint8_t* pBuffer,uint32_t ReadAddr,uint16_t NumByteToRead)
|
|||
void write_Flash(uint8_t* pBuffer,uint32_t WriteAddr,uint16_t NumByteToWrite)
|
||||
{
|
||||
W25QXX_Write(pBuffer, WriteAddr, NumByteToWrite);
|
||||
// Flash_Write_MorePage(pBuffer, WriteAddr, NumByteToWrite);
|
||||
// W25Q128_Write(pBuffer, WriteAddr, NumByteToWrite);
|
||||
}
|
|
@ -248,6 +248,20 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart)
|
||||
{
|
||||
if (huart->Instance == USART2) {
|
||||
gw485_TxIt();
|
||||
}
|
||||
else if (huart->Instance == USART3) {
|
||||
bat485_TxIt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief 开启向上对网关通信485串口的中断接收.
|
||||
* @retval None
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "stm32g431xx.h"
|
||||
|
||||
#define SYS_VOLT_IN_CHANNEL ADC_CHANNEL_1
|
||||
#define OUT_VOLT_IN_CHANNEL ADC_CHANNEL_9
|
||||
#define MOSFET_Temper_CHANNEL ADC_CHANNEL_15
|
||||
|
||||
void HD_adc_Init(void);
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
|
||||
#ifndef HD_RTC_H_
|
||||
#define HD_RTC_H_
|
||||
|
||||
#include "rtc.h"
|
||||
#include "comm_types.h"
|
||||
#include "stm32g431xx.h"
|
||||
|
||||
void HD_RTC_Init(void);
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,72 @@
|
|||
#ifndef _W25Q256_H
|
||||
#define _W25Q256_H
|
||||
|
||||
#include "gpio.h"
|
||||
#include "main.h"
|
||||
|
||||
/*******************************************************************************
|
||||
* 常量&宏定义 *
|
||||
*******************************************************************************/
|
||||
#define FLASH_CS_GPIO_Port GPIOA
|
||||
#define FLASH_CS_Pin FLASH_CS_Pin
|
||||
#define FLASH_CLK_GPIO_Port GPIOA
|
||||
#define FLASH_CLK_Pin FLASH_CLK_Pin
|
||||
#define FLASH_MISO_GPIO_Port GPIOA
|
||||
#define FLASH_MISO_Pin FLASH_MISO_Pin
|
||||
#define FLASH_MOSI_GPIO_Port GPIOA
|
||||
#define FLASH_MOSI_Pin FLASH_MOSI_Pin
|
||||
|
||||
#define FLASH_CS_ENABLE HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_RESET) /*片选使能*/
|
||||
#define FLASH_CS_DISABLE HAL_GPIO_WritePin(FLASH_CS_GPIO_Port, FLASH_CS_Pin, GPIO_PIN_SET) /*片选失能*/
|
||||
|
||||
#define FLASH_CLK_HIGH HAL_GPIO_WritePin(FLASH_CLK_GPIO_Port, FLASH_CLK_Pin, GPIO_PIN_SET) /*时钟信号高*/
|
||||
#define FLASH_CLK_LOW HAL_GPIO_WritePin(FLASH_CLK_GPIO_Port, FLASH_CLK_Pin, GPIO_PIN_RESET) /*时钟信号低*/
|
||||
|
||||
#define FLASH_MISO_READ HAL_GPIO_ReadPin(FLASH_MISO_GPIO_Port, FLASH_MISO_Pin) /*MISO数据输入*/
|
||||
|
||||
#define FLASH_MOSI_HIGH HAL_GPIO_WritePin(FLASH_MOSI_GPIO_Port, FLASH_MOSI_Pin, GPIO_PIN_SET) /*MOSI数据引脚高电平*/
|
||||
#define FLASH_MOSI_LOW HAL_GPIO_WritePin(FLASH_MOSI_GPIO_Port, FLASH_MOSI_Pin, GPIO_PIN_RESET) /*MOSI数据引脚低电平*/
|
||||
|
||||
#define FLASH_W25Q128
|
||||
#ifdef FLASH_W25Q128
|
||||
#define Flash_ReadData_CMD 0x03
|
||||
#endif
|
||||
#ifdef FLASH_W25Q256
|
||||
#define Flash_ReadData_CMD 0x13
|
||||
#endif
|
||||
|
||||
#define FLASH_WRITE_BUSYBIT 0X01
|
||||
#define Flash_ReadID 0x90 /*读ID***16位*/
|
||||
#define Flash_ReadID_only 0x4b /*读唯一ID***64位*/
|
||||
#define Flash_Chip_Erase_CMD 0xC7 /*片擦除*/
|
||||
#define Flash_WriteEnable_CMD 0x06
|
||||
#define Flash_WriteDisable_CMD 0x04
|
||||
#define Flash_PageProgram_CMD 0x02
|
||||
#define Flash_WriteSR_CMD 0x01
|
||||
#define Flash_ReadSR_CMD 0x05
|
||||
#define Flash_SecErase_CMD 0x20
|
||||
#define Flash_BlockErase_CMD 0xD8
|
||||
#define W25Q_4ByteAddrModeEnable 0xB7
|
||||
#define W25Q_Exit4ByteAddrModeEnable 0xE9
|
||||
#define Flash_PAGEBYTE_LENGTH 256
|
||||
#define EXT_FLASH_SECTOR_SIZE (1024*4)
|
||||
#define EXT_FLASH_BLOCK_SIZE (1024*64)
|
||||
|
||||
/*******************************************************************************
|
||||
* 函数声明 *
|
||||
*******************************************************************************/
|
||||
/* w25q256相关引脚初始化 */
|
||||
void Flash_GPIO_Init(void);
|
||||
/* 扇区擦除 */
|
||||
void Flash_Erase_Block(uint8_t BlockNum);
|
||||
/* 块擦除 */
|
||||
void Flash_Erase_Sector(uint8_t Block_Num,uint8_t Sector_Number);
|
||||
/* 写数据 */
|
||||
void Flash_Write_Page(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum);
|
||||
void Flash_Write_MorePage(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum);
|
||||
/* 读数据 */
|
||||
void Flash_Read(uint8_t *pBuffer,uint32_t ReadAddr,uint32_t ReadBytesNum);
|
||||
|
||||
void W25Q128_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum);
|
||||
|
||||
#endif
|
|
@ -48,8 +48,8 @@ void HD_GPIO_Init(void)
|
|||
|
||||
/*Configure GPIO pin : WORK_VOLT_INT_Pin */
|
||||
GPIO_InitStruct.Pin = WORK_VOLT_INT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
|
||||
HAL_GPIO_Init(WORK_VOLT_INT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/* EXTI interrupt init*/
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
|
||||
#include "HD_RTC.h"
|
||||
#include "stm32g431xx.h"
|
||||
|
||||
|
||||
void HD_RTC_Init(void)
|
||||
{
|
||||
hrtc.Instance = RTC;
|
||||
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
|
||||
hrtc.Init.AsynchPrediv = 127;
|
||||
hrtc.Init.SynchPrediv = 255;
|
||||
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
|
||||
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
|
||||
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
|
||||
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
|
||||
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
|
||||
if (HAL_RTC_Init(&hrtc) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,318 @@
|
|||
#include <string.h>
|
||||
#include "w25q256.h"
|
||||
|
||||
///@brief Flash相关引脚初始化
|
||||
void Flash_GPIO_Init(void)
|
||||
{
|
||||
FLASH_CS_DISABLE;
|
||||
FLASH_CLK_HIGH;
|
||||
FLASH_MOSI_LOW;
|
||||
}
|
||||
|
||||
///@brief 读取一个字节数据
|
||||
static uint8_t Flash_ReadOneByte(void)
|
||||
{
|
||||
uint8_t retValue = 0;
|
||||
|
||||
FLASH_CLK_HIGH; //时钟线拉高,恢复时钟线为高电平
|
||||
for(uint8_t i= 0; i < 8; i++)
|
||||
{
|
||||
retValue <<= 1;
|
||||
FLASH_CLK_HIGH; //时钟线拉高,恢复时钟线为高电平
|
||||
if(FLASH_MISO_READ)
|
||||
{
|
||||
retValue |= 0x01;
|
||||
}
|
||||
else
|
||||
{
|
||||
retValue &= 0xFE;
|
||||
}
|
||||
FLASH_CLK_LOW; //时钟线拉低,产生下降沿读出数据
|
||||
}
|
||||
FLASH_CLK_HIGH;
|
||||
|
||||
return (retValue);
|
||||
}
|
||||
|
||||
///@brief 写入一个字节
|
||||
static void Flash_WriteOneByte(uint8_t DataBuffer)
|
||||
{
|
||||
FLASH_CLK_LOW; //时钟线拉低,恢复时钟线为低电平
|
||||
for(uint8_t i = 0; i < 8; i++)
|
||||
{
|
||||
FLASH_CLK_LOW; //时钟线拉低,恢复时钟线为低电平
|
||||
if(DataBuffer & 0x80)
|
||||
{
|
||||
FLASH_MOSI_HIGH;
|
||||
}
|
||||
else
|
||||
{
|
||||
FLASH_MOSI_LOW;
|
||||
}
|
||||
DataBuffer <<= 1;
|
||||
FLASH_CLK_HIGH; //时钟线拉高,产生上升沿写入数据
|
||||
}
|
||||
FLASH_CLK_LOW;
|
||||
FLASH_MOSI_HIGH; //一字节数据传送完毕,MOSI数据线置高表示空闲状态
|
||||
}
|
||||
|
||||
///@brief 写指令
|
||||
static void Flash_Write_CMD(uint8_t *pCMD)
|
||||
{
|
||||
#ifdef FLASH_W25Q256
|
||||
for(uint8_t i = 0; i < 4; i++) //new add
|
||||
{
|
||||
Flash_WriteOneByte(pCMD[i]);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FLASH_W25Q128
|
||||
for(uint8_t i = 0; i < 3; i++) //new add
|
||||
{
|
||||
Flash_WriteOneByte(pCMD[i]);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
///@brief 读取SR
|
||||
static uint8_t Flash_ReadSR(void)
|
||||
{
|
||||
uint8_t retValue = 0;
|
||||
|
||||
FLASH_CS_ENABLE;
|
||||
Flash_WriteOneByte(Flash_ReadSR_CMD);
|
||||
retValue = Flash_ReadOneByte();
|
||||
FLASH_CS_DISABLE;
|
||||
|
||||
return retValue;
|
||||
}
|
||||
|
||||
///@brief 等待标志位
|
||||
static void Flash_Wait_Busy(void)
|
||||
{
|
||||
uint32_t i =0;
|
||||
|
||||
while(((Flash_ReadSR() & FLASH_WRITE_BUSYBIT) == 0x01) && (i<0x1ffff))
|
||||
{
|
||||
i ++;
|
||||
}
|
||||
}
|
||||
|
||||
///@brief 写使能
|
||||
static void Flash_Write_Enable(void)
|
||||
{
|
||||
FLASH_CS_ENABLE;
|
||||
Flash_WriteOneByte(Flash_WriteEnable_CMD);
|
||||
FLASH_CS_DISABLE;
|
||||
}
|
||||
|
||||
#if 0
|
||||
///@brief 进入4字节模式
|
||||
void Enter4ByteAddrMode(void)
|
||||
{
|
||||
FLASH_CS_ENABLE; //使能器件
|
||||
Flash_WriteOneByte(W25Q_4ByteAddrModeEnable); //进入4Byte地址模式W25Q128以上使用
|
||||
FLASH_CS_DISABLE;
|
||||
}
|
||||
|
||||
///@brief 退出4字节模式
|
||||
void Exit4ByteAddrMode(void)
|
||||
{
|
||||
FLASH_CS_ENABLE; //使能器件
|
||||
Flash_WriteOneByte(W25Q_Exit4ByteAddrModeEnable); //进入4Byte地址模式W25Q128以上使用
|
||||
FLASH_CS_DISABLE;
|
||||
}
|
||||
#endif
|
||||
|
||||
///@brief 擦除区域
|
||||
void Flash_Erase_Sector(uint8_t Block_Num,uint8_t Sector_Number)
|
||||
{
|
||||
uint8_t pcmd[3] = {0};
|
||||
Flash_Write_Enable();
|
||||
FLASH_CS_ENABLE;
|
||||
Flash_WriteOneByte(Flash_SecErase_CMD);
|
||||
|
||||
pcmd[0] = Block_Num;
|
||||
pcmd[1] = Sector_Number<<4;
|
||||
pcmd[2] = 0;
|
||||
Flash_Write_CMD(pcmd);
|
||||
FLASH_CS_DISABLE;
|
||||
Flash_Wait_Busy();//每次擦除数据都要延时等待写入结束
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
///@brief 擦除块
|
||||
void Flash_Erase_Block(uint8_t BlockNum)
|
||||
{
|
||||
|
||||
uint8_t pcmd[3] = {0};
|
||||
Flash_Write_Enable(); //写使能
|
||||
FLASH_CS_ENABLE; //片选拉低
|
||||
Flash_WriteOneByte(Flash_BlockErase_CMD); //传输Block擦除指令
|
||||
pcmd[0] = BlockNum ; //传24位地址
|
||||
Flash_Write_CMD(pcmd);
|
||||
FLASH_CS_DISABLE;
|
||||
Flash_Wait_Busy(); //每次擦除数据都要延时等待写入结束
|
||||
|
||||
return ;
|
||||
}
|
||||
|
||||
///@brief 页写
|
||||
void Flash_Write_Page(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum)
|
||||
{
|
||||
uint8_t pcmd[4] = {0};
|
||||
|
||||
Flash_Write_Enable();
|
||||
FLASH_CS_ENABLE;
|
||||
Flash_WriteOneByte(Flash_PageProgram_CMD);
|
||||
#ifdef FLASH_W25Q256
|
||||
pcmd[0] = (uint8_t)((WriteAddr&0xff000000)>>24); //new add
|
||||
pcmd[1] = (uint8_t)((WriteAddr&0x00ff0000)>>16);
|
||||
pcmd[2] = (uint8_t)((WriteAddr&0x0000ff00)>>8);
|
||||
pcmd[3] = (uint8_t)WriteAddr;
|
||||
#endif
|
||||
|
||||
#ifdef FLASH_W25Q128
|
||||
pcmd[0] = (uint8_t)((WriteAddr&0x00ff0000)>>16);
|
||||
pcmd[1] = (uint8_t)((WriteAddr&0x0000ff00)>>8);
|
||||
pcmd[2] = (uint8_t)WriteAddr;
|
||||
#endif
|
||||
|
||||
Flash_Write_CMD(pcmd);
|
||||
|
||||
for(uint32_t i = 0;i < WriteBytesNum; i++)
|
||||
{
|
||||
|
||||
Flash_WriteOneByte(pBuffer[i]); //向Flash中写入最大一页256bytes字节数据
|
||||
}
|
||||
FLASH_CS_DISABLE;
|
||||
Flash_Wait_Busy(); //每次写入一定数量的数据都要延时等待写入结束
|
||||
return;
|
||||
}
|
||||
|
||||
///@brief 连续写入多页
|
||||
void Flash_Write_MorePage(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum)
|
||||
{
|
||||
uint16_t PageByteRemain = 0;
|
||||
PageByteRemain = Flash_PAGEBYTE_LENGTH - WriteAddr%Flash_PAGEBYTE_LENGTH;
|
||||
if(WriteBytesNum <= PageByteRemain)
|
||||
{
|
||||
PageByteRemain = WriteBytesNum;
|
||||
}
|
||||
while(1)
|
||||
{
|
||||
Flash_Write_Page(pBuffer,WriteAddr,PageByteRemain);
|
||||
if(WriteBytesNum == PageByteRemain)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
pBuffer += PageByteRemain;
|
||||
WriteAddr += PageByteRemain;
|
||||
WriteBytesNum -= PageByteRemain;
|
||||
if(WriteBytesNum > Flash_PAGEBYTE_LENGTH)
|
||||
{
|
||||
PageByteRemain = Flash_PAGEBYTE_LENGTH;
|
||||
}
|
||||
else
|
||||
{
|
||||
PageByteRemain = WriteBytesNum;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
///@brief 连续写入多页
|
||||
uint8_t W25QXX_BUFFER[4096];
|
||||
void W25Q128_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint32_t WriteBytesNum)
|
||||
{
|
||||
// volatile static int timeReadTemp1, timeReadTemp2, timeReadTemp3, timeReadTemp4, timeReadTemp5, timeReadTemp6;
|
||||
|
||||
uint32_t secpos;
|
||||
uint16_t secoff;
|
||||
uint16_t secremain;
|
||||
uint16_t i;
|
||||
uint8_t *W25QXX_BUF;
|
||||
W25QXX_BUF = W25QXX_BUFFER;
|
||||
secpos = WriteAddr / 4096; //扇区地址
|
||||
secoff = WriteAddr % 4096; //在扇区内的偏移
|
||||
secremain = 4096 - secoff; //扇区剩余空间大小
|
||||
if (WriteBytesNum <= secremain)
|
||||
secremain = WriteBytesNum; //不大于4096个字节
|
||||
while (1)
|
||||
{
|
||||
// timeReadTemp1 = HAL_GetTick();
|
||||
Flash_Read(W25QXX_BUF, secpos * 4096, 4096); //读出整个扇区的内容
|
||||
// timeReadTemp2 = HAL_GetTick();
|
||||
for (i = 0; i < secremain; i++) //校验数据
|
||||
{
|
||||
if (W25QXX_BUF[secoff + i] != 0XFF)
|
||||
break; //需要擦除
|
||||
}
|
||||
if (i < secremain) //需要擦除
|
||||
{
|
||||
Flash_Erase_Block(secpos); //擦除这个扇区
|
||||
// timeReadTemp3 = HAL_GetTick();
|
||||
for (i = 0; i < secremain; i++) //复制
|
||||
{
|
||||
W25QXX_BUF[i + secoff] = pBuffer[i];
|
||||
}
|
||||
Flash_Write_Page(W25QXX_BUF, secpos * 4096, 4096); //写入整个扇区
|
||||
// timeReadTemp4 = HAL_GetTick();
|
||||
// timeReadTemp5 = NumByteToWrite;
|
||||
// timeReadTemp6 = WriteAddr;
|
||||
}
|
||||
else
|
||||
Flash_Write_Page(pBuffer, WriteAddr, secremain); //写已经擦除了的,直接写入扇区剩余区间.
|
||||
if (WriteBytesNum == secremain)
|
||||
break; //写入结束了
|
||||
else //写入未结束
|
||||
{
|
||||
secpos++; //扇区地址增1
|
||||
secoff = 0; //偏移位置为0
|
||||
|
||||
pBuffer += secremain; //指针偏移
|
||||
WriteAddr += secremain; //写地址偏移
|
||||
WriteBytesNum -= secremain; //字节数递减
|
||||
if (WriteBytesNum > 4096)
|
||||
secremain = 4096; //下一个扇区还是写不完
|
||||
else
|
||||
secremain = WriteBytesNum; //下一个扇区可以写完了
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
///@brief 读取数据
|
||||
void Flash_Read(uint8_t *pBuffer,uint32_t ReadAddr,uint32_t ReadBytesNum)
|
||||
{
|
||||
uint8_t pcmd[4] = {0};
|
||||
FLASH_CS_ENABLE; //打开spiflash片选
|
||||
Flash_WriteOneByte(Flash_ReadData_CMD);
|
||||
#ifdef FLASH_W25Q256
|
||||
pcmd[0] = (uint8_t)((ReadAddr&0xff000000)>>24); //new add
|
||||
pcmd[1] = (uint8_t)((ReadAddr&0x00ff0000)>>16);
|
||||
pcmd[2] = (uint8_t)((ReadAddr&0x0000ff00)>>8);
|
||||
pcmd[3] = (uint8_t)ReadAddr;
|
||||
#endif
|
||||
|
||||
#ifdef FLASH_W25Q128
|
||||
pcmd[0] = (uint8_t)((ReadAddr&0x00ff0000)>>16);
|
||||
pcmd[1] = (uint8_t)((ReadAddr&0x0000ff00)>>8);
|
||||
pcmd[2] = (uint8_t)ReadAddr;
|
||||
#endif
|
||||
|
||||
Flash_Write_CMD(pcmd);
|
||||
|
||||
for(uint32_t i = 0;i < ReadBytesNum; i++)
|
||||
{
|
||||
pBuffer[i] = Flash_ReadOneByte(); //读取SPIflash中指定bytes字节数据
|
||||
|
||||
}
|
||||
FLASH_CS_DISABLE;
|
||||
|
||||
return ;
|
||||
}
|
|
@ -161,17 +161,25 @@ void W25QXX_ReadUniqueID(uint8_t UID[8])
|
|||
//NumByteToRead:要读取的字节数(最大65535)
|
||||
void W25QXX_Read(uint8_t *pBuffer, uint32_t ReadAddr, uint16_t NumByteToRead)
|
||||
{
|
||||
volatile static int timeReadTemp1, timeReadTemp2, timeReadTemp3, timeReadTemp4, timeReadTemp5;
|
||||
timeReadTemp1 = HAL_GetTick();
|
||||
|
||||
uint16_t i;
|
||||
W25QXX_CS_L(); //使能器件
|
||||
W25QXX_SPI_ReadWriteByte(W25X_ReadData); //发送读取命令
|
||||
W25QXX_SPI_ReadWriteByte((uint8_t)((ReadAddr) >> 16)); //发送24bit地址
|
||||
W25QXX_SPI_ReadWriteByte((uint8_t)((ReadAddr) >> 8));
|
||||
W25QXX_SPI_ReadWriteByte((uint8_t)ReadAddr);
|
||||
timeReadTemp2 = HAL_GetTick();
|
||||
for (i = 0; i < NumByteToRead; i++)
|
||||
{
|
||||
pBuffer[i] = W25QXX_SPI_ReadWriteByte(0XFF); //循环读数
|
||||
}
|
||||
W25QXX_CS_H();
|
||||
|
||||
timeReadTemp3 = HAL_GetTick();
|
||||
timeReadTemp4 = NumByteToRead;
|
||||
timeReadTemp5 = ReadAddr;
|
||||
}
|
||||
//SPI在一页(0~65535)内写入少于256个字节的数据
|
||||
//在指定地址开始写入最大256字节的数据
|
||||
|
@ -233,6 +241,8 @@ void W25QXX_Write_NoCheck(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByte
|
|||
uint8_t W25QXX_BUFFER[4096];
|
||||
void W25QXX_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
|
||||
{
|
||||
// volatile static int timeReadTemp1, timeReadTemp2, timeReadTemp3, timeReadTemp4, timeReadTemp5, timeReadTemp6;
|
||||
|
||||
uint32_t secpos;
|
||||
uint16_t secoff;
|
||||
uint16_t secremain;
|
||||
|
@ -246,7 +256,10 @@ void W25QXX_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
|
|||
secremain = NumByteToWrite; //不大于4096个字节
|
||||
while (1)
|
||||
{
|
||||
|
||||
// timeReadTemp1 = HAL_GetTick();
|
||||
W25QXX_Read(W25QXX_BUF, secpos * 4096, 4096); //读出整个扇区的内容
|
||||
// timeReadTemp2 = HAL_GetTick();
|
||||
for (i = 0; i < secremain; i++) //校验数据
|
||||
{
|
||||
if (W25QXX_BUF[secoff + i] != 0XFF)
|
||||
|
@ -255,12 +268,15 @@ void W25QXX_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
|
|||
if (i < secremain) //需要擦除
|
||||
{
|
||||
W25QXX_Erase_Sector(secpos); //擦除这个扇区
|
||||
// timeReadTemp3 = HAL_GetTick();
|
||||
for (i = 0; i < secremain; i++) //复制
|
||||
{
|
||||
W25QXX_BUF[i + secoff] = pBuffer[i];
|
||||
}
|
||||
W25QXX_Write_NoCheck(W25QXX_BUF, secpos * 4096, 4096); //写入整个扇区
|
||||
|
||||
// timeReadTemp4 = HAL_GetTick();
|
||||
// timeReadTemp5 = NumByteToWrite;
|
||||
// timeReadTemp6 = WriteAddr;
|
||||
}
|
||||
else
|
||||
W25QXX_Write_NoCheck(pBuffer, WriteAddr, secremain); //写已经擦除了的,直接写入扇区剩余区间.
|
||||
|
@ -280,6 +296,42 @@ void W25QXX_Write(uint8_t *pBuffer, uint32_t WriteAddr, uint16_t NumByteToWrite)
|
|||
secremain = NumByteToWrite; //下一个扇区可以写完了
|
||||
}
|
||||
};
|
||||
|
||||
// while (1) {
|
||||
// W25QXX_Read(W25QXX_BUF, secpos * 4096, 4096); //读出整个扇区的内容
|
||||
// // for (i = 0; i < secremain; i++) //校验数据
|
||||
// // {
|
||||
// // if (W25QXX_BUF[secoff + i] != 0XFF)
|
||||
// // break; //需要擦除
|
||||
// // }
|
||||
// // if (i < secremain) //需要擦除
|
||||
// // {
|
||||
// W25QXX_Erase_Sector(secpos); //擦除这个扇区
|
||||
// for (i = 0; i < secremain; i++) //复制
|
||||
// {
|
||||
// W25QXX_BUF[i + secoff] = pBuffer[i];
|
||||
// }
|
||||
// W25QXX_Write_NoCheck(W25QXX_BUF, secpos * 4096, 4096); //写入整个扇区
|
||||
|
||||
// // }
|
||||
// // else
|
||||
// // W25QXX_Write_NoCheck(pBuffer, WriteAddr, secremain); //写已经擦除了的,直接写入扇区剩余区间.
|
||||
// if (NumByteToWrite == secremain)
|
||||
// break; //写入结束了
|
||||
// else //写入未结束
|
||||
// {
|
||||
// secpos++; //扇区地址增1
|
||||
// secoff = 0; //偏移位置为0
|
||||
|
||||
// pBuffer += secremain; //指针偏移
|
||||
// WriteAddr += secremain; //写地址偏移
|
||||
// NumByteToWrite -= secremain; //字节数递减
|
||||
// if (NumByteToWrite > 4096)
|
||||
// secremain = 4096; //下一个扇区还是写不完
|
||||
// else
|
||||
// secremain = NumByteToWrite; //下一个扇区可以写完了
|
||||
// }
|
||||
// };
|
||||
}
|
||||
|
||||
//擦除整个芯片
|
||||
|
|
|
@ -64,6 +64,8 @@ void Error_Handler(void);
|
|||
#define WORK_VOLT_GPIO_Port GPIOC
|
||||
#define DSG_CURR_Pin GPIO_PIN_2
|
||||
#define DSG_CURR_GPIO_Port GPIOC
|
||||
#define OUT_VOLT_IN_Pin GPIO_PIN_3
|
||||
#define OUT_VOLT_IN_GPIO_Port GPIOC
|
||||
#define SYS_VOLT_IN_Pin GPIO_PIN_0
|
||||
#define SYS_VOLT_IN_GPIO_Port GPIOA
|
||||
#define GW485_RDE_Pin GPIO_PIN_1
|
||||
|
@ -74,8 +76,8 @@ void Error_Handler(void);
|
|||
#define GW485_RX_GPIO_Port GPIOA
|
||||
#define FLASH_CS_Pin GPIO_PIN_4
|
||||
#define FLASH_CS_GPIO_Port GPIOA
|
||||
#define FLASH_CLK_Pin GPIO_PIN_5
|
||||
#define FLASH_CLK_GPIO_Port GPIOA
|
||||
#define FLASH_SCK_Pin GPIO_PIN_5
|
||||
#define FLASH_SCK_GPIO_Port GPIOA
|
||||
#define FLASH_MISO_Pin GPIO_PIN_6
|
||||
#define FLASH_MISO_GPIO_Port GPIOA
|
||||
#define FLASH_MOSI_Pin GPIO_PIN_7
|
||||
|
@ -111,7 +113,7 @@ void Error_Handler(void);
|
|||
#define RUN_LED_GPIO_Port GPIOB
|
||||
#define POW_FF_CON_Pin GPIO_PIN_7
|
||||
#define POW_FF_CON_GPIO_Port GPIOB
|
||||
#define POW_OUT_CON_Pin GPIO_PIN_8
|
||||
#define POW_OUT_CON_Pin GPIO_PIN_9
|
||||
#define POW_OUT_CON_GPIO_Port GPIOB
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rtc.h
|
||||
* @brief This file contains all the function prototypes for
|
||||
* the rtc.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __RTC_H__
|
||||
#define __RTC_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "main.h"
|
||||
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
extern RTC_HandleTypeDef hrtc;
|
||||
|
||||
/* USER CODE BEGIN Private defines */
|
||||
|
||||
/* USER CODE END Private defines */
|
||||
|
||||
void MX_RTC_Init(void);
|
||||
|
||||
/* USER CODE BEGIN Prototypes */
|
||||
|
||||
/* USER CODE END Prototypes */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __RTC_H__ */
|
||||
|
|
@ -7,7 +7,7 @@
|
|||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
/*#define HAL_PCD_MODULE_ENABLED */
|
||||
/*#define HAL_QSPI_MODULE_ENABLED */
|
||||
/*#define HAL_RNG_MODULE_ENABLED */
|
||||
/*#define HAL_RTC_MODULE_ENABLED */
|
||||
#define HAL_RTC_MODULE_ENABLED
|
||||
/*#define HAL_SAI_MODULE_ENABLED */
|
||||
/*#define HAL_SMARTCARD_MODULE_ENABLED */
|
||||
/*#define HAL_SMBUS_MODULE_ENABLED */
|
||||
|
|
|
@ -263,12 +263,19 @@ void HAL_ADC_MspInit(ADC_HandleTypeDef* adcHandle)
|
|||
__HAL_RCC_ADC12_CLK_ENABLE();
|
||||
}
|
||||
|
||||
__HAL_RCC_GPIOC_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOA_CLK_ENABLE();
|
||||
__HAL_RCC_GPIOB_CLK_ENABLE();
|
||||
/**ADC2 GPIO Configuration
|
||||
PC3 ------> ADC2_IN9
|
||||
PA0 ------> ADC2_IN1
|
||||
PB15 ------> ADC2_IN15
|
||||
*/
|
||||
GPIO_InitStruct.Pin = OUT_VOLT_IN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
HAL_GPIO_Init(OUT_VOLT_IN_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
GPIO_InitStruct.Pin = SYS_VOLT_IN_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
|
@ -327,9 +334,12 @@ void HAL_ADC_MspDeInit(ADC_HandleTypeDef* adcHandle)
|
|||
}
|
||||
|
||||
/**ADC2 GPIO Configuration
|
||||
PC3 ------> ADC2_IN9
|
||||
PA0 ------> ADC2_IN1
|
||||
PB15 ------> ADC2_IN15
|
||||
*/
|
||||
HAL_GPIO_DeInit(OUT_VOLT_IN_GPIO_Port, OUT_VOLT_IN_Pin);
|
||||
|
||||
HAL_GPIO_DeInit(SYS_VOLT_IN_GPIO_Port, SYS_VOLT_IN_Pin);
|
||||
|
||||
HAL_GPIO_DeInit(MOSFET_Temper_GPIO_Port, MOSFET_Temper_Pin);
|
||||
|
|
|
@ -65,12 +65,12 @@ void MX_GPIO_Init(void)
|
|||
GPIO_InitStruct.Pull = GPIO_PULLUP;
|
||||
HAL_GPIO_Init(DSG_PROT_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : FLASH_CS_Pin EN_PWMOUT_Pin FFMOS_CON_Pin */
|
||||
GPIO_InitStruct.Pin = FLASH_CS_Pin|EN_PWMOUT_Pin|FFMOS_CON_Pin;
|
||||
/*Configure GPIO pin : FLASH_CS_Pin */
|
||||
GPIO_InitStruct.Pin = FLASH_CS_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
HAL_GPIO_Init(FLASH_CS_GPIO_Port, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : WDI_INPUT_Pin RUN_LED_Pin POW_FF_CON_Pin POW_OUT_CON_Pin */
|
||||
GPIO_InitStruct.Pin = WDI_INPUT_Pin|RUN_LED_Pin|POW_FF_CON_Pin|POW_OUT_CON_Pin;
|
||||
|
@ -79,6 +79,13 @@ void MX_GPIO_Init(void)
|
|||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pins : EN_PWMOUT_Pin FFMOS_CON_Pin */
|
||||
GPIO_InitStruct.Pin = EN_PWMOUT_Pin|FFMOS_CON_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
/*Configure GPIO pin : WORK_VOLT_INT_Pin */
|
||||
GPIO_InitStruct.Pin = WORK_VOLT_INT_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "main.h"
|
||||
#include "adc.h"
|
||||
#include "dma.h"
|
||||
#include "rtc.h"
|
||||
#include "spi.h"
|
||||
#include "tim.h"
|
||||
#include "usart.h"
|
||||
|
@ -94,19 +95,20 @@ int main(void)
|
|||
/* USER CODE END SysInit */
|
||||
|
||||
/* Initialize all configured peripherals */
|
||||
// MX_GPIO_Init();
|
||||
// MX_DMA_Init();
|
||||
// MX_ADC1_Init();
|
||||
// MX_ADC2_Init();
|
||||
// MX_SPI1_Init();
|
||||
// MX_TIM3_Init();
|
||||
// MX_TIM6_Init();
|
||||
// MX_UART4_Init();
|
||||
// MX_USART2_UART_Init();
|
||||
// MX_USART3_UART_Init();
|
||||
// MX_TIM7_Init();
|
||||
// MX_TIM16_Init();
|
||||
// MX_TIM15_Init();
|
||||
// MX_GPIO_Init();
|
||||
// MX_DMA_Init();
|
||||
// MX_ADC1_Init();
|
||||
// MX_ADC2_Init();
|
||||
// MX_TIM3_Init();
|
||||
// MX_TIM6_Init();
|
||||
// MX_UART4_Init();
|
||||
// MX_USART2_UART_Init();
|
||||
// MX_USART3_UART_Init();
|
||||
// MX_TIM7_Init();
|
||||
// MX_TIM16_Init();
|
||||
// MX_TIM15_Init();
|
||||
// MX_RTC_Init();
|
||||
// MX_SPI1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
start();
|
||||
|
@ -140,15 +142,22 @@ void SystemClock_Config(void)
|
|||
*/
|
||||
HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1);
|
||||
|
||||
/** Configure LSE Drive Capability
|
||||
*/
|
||||
HAL_PWR_EnableBkUpAccess();
|
||||
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
|
||||
|
||||
/** Initializes the RCC Oscillators according to the specified parameters
|
||||
* in the RCC_OscInitTypeDef structure.
|
||||
*/
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
|
||||
RCC_OscInitStruct.HSEState = RCC_HSE_ON;
|
||||
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_LSE;
|
||||
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
||||
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
|
||||
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
|
||||
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
|
||||
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
|
||||
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;
|
||||
RCC_OscInitStruct.PLL.PLLN = 18;
|
||||
RCC_OscInitStruct.PLL.PLLN = 9;
|
||||
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
|
||||
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
|
||||
|
|
|
@ -0,0 +1,139 @@
|
|||
/* USER CODE BEGIN Header */
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file rtc.c
|
||||
* @brief This file provides code for the configuration
|
||||
* of the RTC instances.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
/* USER CODE END Header */
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "rtc.h"
|
||||
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
RTC_HandleTypeDef hrtc;
|
||||
|
||||
/* RTC init function */
|
||||
void MX_RTC_Init(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN RTC_Init 0 */
|
||||
|
||||
/* USER CODE END RTC_Init 0 */
|
||||
|
||||
RTC_TimeTypeDef sTime = {0};
|
||||
RTC_DateTypeDef sDate = {0};
|
||||
|
||||
/* USER CODE BEGIN RTC_Init 1 */
|
||||
|
||||
/* USER CODE END RTC_Init 1 */
|
||||
|
||||
/** Initialize RTC Only
|
||||
*/
|
||||
hrtc.Instance = RTC;
|
||||
hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
|
||||
hrtc.Init.AsynchPrediv = 127;
|
||||
hrtc.Init.SynchPrediv = 255;
|
||||
hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
|
||||
hrtc.Init.OutPutRemap = RTC_OUTPUT_REMAP_NONE;
|
||||
hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
|
||||
hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
|
||||
hrtc.Init.OutPutPullUp = RTC_OUTPUT_PULLUP_NONE;
|
||||
if (HAL_RTC_Init(&hrtc) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN Check_RTC_BKUP */
|
||||
|
||||
/* USER CODE END Check_RTC_BKUP */
|
||||
|
||||
/** Initialize RTC and set the Time and Date
|
||||
*/
|
||||
sTime.Hours = 0;
|
||||
sTime.Minutes = 0;
|
||||
sTime.Seconds = 0;
|
||||
sTime.SubSeconds = 0;
|
||||
sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
|
||||
sTime.StoreOperation = RTC_STOREOPERATION_RESET;
|
||||
if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BIN) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
sDate.WeekDay = RTC_WEEKDAY_MONDAY;
|
||||
sDate.Month = RTC_MONTH_JANUARY;
|
||||
sDate.Date = 1;
|
||||
sDate.Year = 0;
|
||||
|
||||
if (HAL_RTC_SetDate(&hrtc, &sDate, RTC_FORMAT_BIN) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
/* USER CODE BEGIN RTC_Init 2 */
|
||||
|
||||
/* USER CODE END RTC_Init 2 */
|
||||
|
||||
}
|
||||
|
||||
void HAL_RTC_MspInit(RTC_HandleTypeDef* rtcHandle)
|
||||
{
|
||||
|
||||
RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};
|
||||
if(rtcHandle->Instance==RTC)
|
||||
{
|
||||
/* USER CODE BEGIN RTC_MspInit 0 */
|
||||
|
||||
/* USER CODE END RTC_MspInit 0 */
|
||||
|
||||
/** Initializes the peripherals clocks
|
||||
*/
|
||||
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_RTC;
|
||||
PeriphClkInit.RTCClockSelection = RCC_RTCCLKSOURCE_LSE;
|
||||
|
||||
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
}
|
||||
|
||||
/* RTC clock enable */
|
||||
__HAL_RCC_RTC_ENABLE();
|
||||
__HAL_RCC_RTCAPB_CLK_ENABLE();
|
||||
/* USER CODE BEGIN RTC_MspInit 1 */
|
||||
|
||||
/* USER CODE END RTC_MspInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
void HAL_RTC_MspDeInit(RTC_HandleTypeDef* rtcHandle)
|
||||
{
|
||||
|
||||
if(rtcHandle->Instance==RTC)
|
||||
{
|
||||
/* USER CODE BEGIN RTC_MspDeInit 0 */
|
||||
|
||||
/* USER CODE END RTC_MspDeInit 0 */
|
||||
/* Peripheral clock disable */
|
||||
__HAL_RCC_RTC_DISABLE();
|
||||
__HAL_RCC_RTCAPB_CLK_DISABLE();
|
||||
/* USER CODE BEGIN RTC_MspDeInit 1 */
|
||||
|
||||
/* USER CODE END RTC_MspDeInit 1 */
|
||||
}
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
|
@ -7,7 +7,7 @@
|
|||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* Copyright (c) 2024 STMicroelectronics.
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
|
@ -41,16 +41,16 @@ void MX_SPI1_Init(void)
|
|||
hspi1.Init.Mode = SPI_MODE_MASTER;
|
||||
hspi1.Init.Direction = SPI_DIRECTION_2LINES;
|
||||
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_HIGH;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_2EDGE;
|
||||
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
||||
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
||||
hspi1.Init.NSS = SPI_NSS_SOFT;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
|
||||
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
||||
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
||||
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
||||
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
||||
hspi1.Init.CRCPolynomial = 7;
|
||||
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
|
||||
hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
|
||||
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
|
||||
if (HAL_SPI_Init(&hspi1) != HAL_OK)
|
||||
{
|
||||
Error_Handler();
|
||||
|
@ -79,10 +79,10 @@ void HAL_SPI_MspInit(SPI_HandleTypeDef* spiHandle)
|
|||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
GPIO_InitStruct.Pin = FLASH_CLK_Pin|FLASH_MISO_Pin|FLASH_MOSI_Pin;
|
||||
GPIO_InitStruct.Pin = FLASH_SCK_Pin|FLASH_MISO_Pin|FLASH_MOSI_Pin;
|
||||
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||||
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||||
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
|
||||
GPIO_InitStruct.Alternate = GPIO_AF5_SPI1;
|
||||
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||||
|
||||
|
@ -108,7 +108,7 @@ void HAL_SPI_MspDeInit(SPI_HandleTypeDef* spiHandle)
|
|||
PA6 ------> SPI1_MISO
|
||||
PA7 ------> SPI1_MOSI
|
||||
*/
|
||||
HAL_GPIO_DeInit(GPIOA, FLASH_CLK_Pin|FLASH_MISO_Pin|FLASH_MOSI_Pin);
|
||||
HAL_GPIO_DeInit(GPIOA, FLASH_SCK_Pin|FLASH_MISO_Pin|FLASH_MOSI_Pin);
|
||||
|
||||
/* USER CODE BEGIN SPI1_MspDeInit 1 */
|
||||
|
||||
|
|
|
@ -248,7 +248,7 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
|
|||
__HAL_RCC_TIM7_CLK_ENABLE();
|
||||
|
||||
/* TIM7 interrupt Init */
|
||||
HAL_NVIC_SetPriority(TIM7_IRQn, 0, 0);
|
||||
HAL_NVIC_SetPriority(TIM7_IRQn, 1, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM7_IRQn);
|
||||
/* USER CODE BEGIN TIM7_MspInit 1 */
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -328,7 +328,7 @@
|
|||
<option>
|
||||
<name>CMSISDAPResetList</name>
|
||||
<version>1</version>
|
||||
<state>10</state>
|
||||
<state>9</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>CMSISDAPHWResetDuration</name>
|
||||
|
@ -348,7 +348,7 @@
|
|||
</option>
|
||||
<option>
|
||||
<name>CMSISDAPInterfaceRadio</name>
|
||||
<state>0</state>
|
||||
<state>1</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>CMSISDAPInterfaceCmdLine</name>
|
||||
|
@ -469,7 +469,7 @@
|
|||
</option>
|
||||
<option>
|
||||
<name>CMSISDAPSelectedCPUBehaviour</name>
|
||||
<state>0</state>
|
||||
<state />
|
||||
</option>
|
||||
<option>
|
||||
<name>ICpuName</name>
|
||||
|
@ -1163,7 +1163,7 @@
|
|||
</option>
|
||||
<option>
|
||||
<name>CCSwoClockAuto</name>
|
||||
<state>0</state>
|
||||
<state>1</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>CCSwoClockEdit</name>
|
||||
|
@ -1253,7 +1253,7 @@
|
|||
<option>
|
||||
<name>CCSTLinkProbeList</name>
|
||||
<version>2</version>
|
||||
<state>0</state>
|
||||
<state>2</state>
|
||||
</option>
|
||||
<option>
|
||||
<name>CCSTLinkTargetVccEnable</name>
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1433,9 +1433,6 @@
|
|||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\application\Src\chargControl.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\application\Src\comm.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\application\Src\start.c</name>
|
||||
</file>
|
||||
|
@ -1452,10 +1449,7 @@
|
|||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\bl_comm.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\cfg_protocol.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\hy_protocol.c</name>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\bl_usart.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\inFlash.c</name>
|
||||
|
@ -1463,9 +1457,15 @@
|
|||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\Init.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\interruptSend.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\parameter.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\SOE.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\businessLogic\Src\task.c</name>
|
||||
</file>
|
||||
|
@ -1484,6 +1484,9 @@
|
|||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_GPIO.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_RTC.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_TIM.c</name>
|
||||
</file>
|
||||
|
@ -1502,6 +1505,9 @@
|
|||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_GPIO.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_RTC.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_TIM.c</name>
|
||||
</file>
|
||||
|
@ -1534,6 +1540,9 @@
|
|||
<file>
|
||||
<name>$PROJ_DIR$\..\Core\Src\main.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\Core\Src\rtc.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\Core\Src\spi.c</name>
|
||||
</file>
|
||||
|
@ -1607,6 +1616,12 @@
|
|||
<file>
|
||||
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rtc.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rtc_ex.c</name>
|
||||
</file>
|
||||
<file>
|
||||
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c</name>
|
||||
</file>
|
||||
|
|
|
@ -85,45 +85,49 @@ Mcu.IPNb=16
|
|||
Mcu.Name=STM32G431R(6-8-B)Tx
|
||||
Mcu.Package=LQFP64
|
||||
Mcu.Pin0=PC13
|
||||
Mcu.Pin1=PF0-OSC_IN
|
||||
Mcu.Pin10=PA5
|
||||
Mcu.Pin11=PA6
|
||||
Mcu.Pin12=PA7
|
||||
Mcu.Pin13=PB0
|
||||
Mcu.Pin14=PB1
|
||||
Mcu.Pin15=PB10
|
||||
Mcu.Pin16=PB11
|
||||
Mcu.Pin17=PB12
|
||||
Mcu.Pin18=PB14
|
||||
Mcu.Pin19=PB15
|
||||
Mcu.Pin2=PF1-OSC_OUT
|
||||
Mcu.Pin20=PC9
|
||||
Mcu.Pin21=PA10
|
||||
Mcu.Pin22=PA11
|
||||
Mcu.Pin23=PA12
|
||||
Mcu.Pin24=PA13
|
||||
Mcu.Pin25=PA14
|
||||
Mcu.Pin26=PC10
|
||||
Mcu.Pin27=PC11
|
||||
Mcu.Pin28=PB6
|
||||
Mcu.Pin29=PB7
|
||||
Mcu.Pin3=PC1
|
||||
Mcu.Pin30=PB8-BOOT0
|
||||
Mcu.Pin31=VP_RTC_VS_RTC_Activate
|
||||
Mcu.Pin32=VP_SYS_VS_Systick
|
||||
Mcu.Pin33=VP_SYS_VS_DBSignals
|
||||
Mcu.Pin34=VP_TIM6_VS_ClockSourceINT
|
||||
Mcu.Pin35=VP_TIM7_VS_ClockSourceINT
|
||||
Mcu.Pin36=VP_TIM15_VS_ClockSourceINT
|
||||
Mcu.Pin37=VP_TIM16_VS_ClockSourceINT
|
||||
Mcu.Pin38=VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0
|
||||
Mcu.Pin4=PC2
|
||||
Mcu.Pin5=PA0
|
||||
Mcu.Pin6=PA1
|
||||
Mcu.Pin7=PA2
|
||||
Mcu.Pin8=PA3
|
||||
Mcu.Pin9=PA4
|
||||
Mcu.PinsNb=39
|
||||
Mcu.Pin1=PC14-OSC32_IN
|
||||
Mcu.Pin10=PA2
|
||||
Mcu.Pin11=PA3
|
||||
Mcu.Pin12=PA4
|
||||
Mcu.Pin13=PA5
|
||||
Mcu.Pin14=PA6
|
||||
Mcu.Pin15=PA7
|
||||
Mcu.Pin16=PB0
|
||||
Mcu.Pin17=PB1
|
||||
Mcu.Pin18=PB10
|
||||
Mcu.Pin19=PB11
|
||||
Mcu.Pin2=PC15-OSC32_OUT
|
||||
Mcu.Pin20=PB12
|
||||
Mcu.Pin21=PB14
|
||||
Mcu.Pin22=PB15
|
||||
Mcu.Pin23=PC9
|
||||
Mcu.Pin24=PA10
|
||||
Mcu.Pin25=PA11
|
||||
Mcu.Pin26=PA12
|
||||
Mcu.Pin27=PA13
|
||||
Mcu.Pin28=PA14
|
||||
Mcu.Pin29=PC10
|
||||
Mcu.Pin3=PF0-OSC_IN
|
||||
Mcu.Pin30=PC11
|
||||
Mcu.Pin31=PB6
|
||||
Mcu.Pin32=PB7
|
||||
Mcu.Pin33=PB9
|
||||
Mcu.Pin34=VP_RTC_VS_RTC_Activate
|
||||
Mcu.Pin35=VP_RTC_VS_RTC_Calendar
|
||||
Mcu.Pin36=VP_SYS_VS_Systick
|
||||
Mcu.Pin37=VP_SYS_VS_DBSignals
|
||||
Mcu.Pin38=VP_TIM6_VS_ClockSourceINT
|
||||
Mcu.Pin39=VP_TIM7_VS_ClockSourceINT
|
||||
Mcu.Pin4=PF1-OSC_OUT
|
||||
Mcu.Pin40=VP_TIM15_VS_ClockSourceINT
|
||||
Mcu.Pin41=VP_TIM16_VS_ClockSourceINT
|
||||
Mcu.Pin42=VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0
|
||||
Mcu.Pin5=PC1
|
||||
Mcu.Pin6=PC2
|
||||
Mcu.Pin7=PC3
|
||||
Mcu.Pin8=PA0
|
||||
Mcu.Pin9=PA1
|
||||
Mcu.PinsNb=43
|
||||
Mcu.ThirdParty0=STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0
|
||||
Mcu.ThirdPartyNb=1
|
||||
Mcu.UserConstants=
|
||||
|
@ -144,7 +148,7 @@ NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
|||
NVIC.SysTick_IRQn=true\:15\:0\:false\:false\:true\:false\:true\:false
|
||||
NVIC.TIM1_BRK_TIM15_IRQn=true\:4\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.TIM1_UP_TIM16_IRQn=true\:4\:0\:true\:false\:true\:false\:true\:true
|
||||
NVIC.TIM7_IRQn=true\:0\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.TIM7_IRQn=true\:1\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.USART2_IRQn=true\:2\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.USART3_IRQn=true\:2\:0\:true\:false\:true\:true\:true\:true
|
||||
NVIC.UsageFault_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false
|
||||
|
@ -190,20 +194,24 @@ PA3.GPIO_PuPd=GPIO_PULLUP
|
|||
PA3.GPIO_Speed=GPIO_SPEED_FREQ_MEDIUM
|
||||
PA3.Mode=Asynchronous
|
||||
PA3.Signal=USART2_RX
|
||||
PA4.GPIOParameters=GPIO_Label
|
||||
PA4.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||
PA4.GPIO_Label=FLASH_CS
|
||||
PA4.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||
PA4.Locked=true
|
||||
PA4.Signal=GPIO_Output
|
||||
PA5.GPIOParameters=GPIO_Label
|
||||
PA5.GPIO_Label=FLASH_CLK
|
||||
PA5.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||
PA5.GPIO_Label=FLASH_SCK
|
||||
PA5.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||
PA5.Mode=Full_Duplex_Master
|
||||
PA5.Signal=SPI1_SCK
|
||||
PA6.GPIOParameters=GPIO_Label
|
||||
PA6.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||
PA6.GPIO_Label=FLASH_MISO
|
||||
PA6.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||
PA6.Mode=Full_Duplex_Master
|
||||
PA6.Signal=SPI1_MISO
|
||||
PA7.GPIOParameters=GPIO_Label
|
||||
PA7.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||
PA7.GPIO_Label=FLASH_MOSI
|
||||
PA7.GPIO_Speed=GPIO_SPEED_FREQ_HIGH
|
||||
PA7.Mode=Full_Duplex_Master
|
||||
PA7.Signal=SPI1_MOSI
|
||||
PB0.GPIOParameters=GPIO_Label
|
||||
|
@ -246,10 +254,10 @@ PB7.GPIOParameters=GPIO_Label
|
|||
PB7.GPIO_Label=POW_FF_CON
|
||||
PB7.Locked=true
|
||||
PB7.Signal=GPIO_Output
|
||||
PB8-BOOT0.GPIOParameters=GPIO_Label
|
||||
PB8-BOOT0.GPIO_Label=POW_OUT_CON
|
||||
PB8-BOOT0.Locked=true
|
||||
PB8-BOOT0.Signal=GPIO_Output
|
||||
PB9.GPIOParameters=GPIO_Label
|
||||
PB9.GPIO_Label=POW_OUT_CON
|
||||
PB9.Locked=true
|
||||
PB9.Signal=GPIO_Output
|
||||
PC1.GPIOParameters=GPIO_Label
|
||||
PC1.GPIO_Label=WORK_VOLT
|
||||
PC1.Locked=true
|
||||
|
@ -269,10 +277,19 @@ PC13.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING
|
|||
PC13.GPIO_PuPd=GPIO_PULLUP
|
||||
PC13.Locked=true
|
||||
PC13.Signal=GPXTI13
|
||||
PC14-OSC32_IN.Mode=LSE-External-Oscillator
|
||||
PC14-OSC32_IN.Signal=RCC_OSC32_IN
|
||||
PC15-OSC32_OUT.Mode=LSE-External-Oscillator
|
||||
PC15-OSC32_OUT.Signal=RCC_OSC32_OUT
|
||||
PC2.GPIOParameters=GPIO_Label
|
||||
PC2.GPIO_Label=DSG_CURR
|
||||
PC2.Mode=IN8-Single-Ended
|
||||
PC2.Signal=ADC1_IN8
|
||||
PC3.GPIOParameters=GPIO_Label
|
||||
PC3.GPIO_Label=OUT_VOLT_IN
|
||||
PC3.Locked=true
|
||||
PC3.Mode=IN9-Single-Ended
|
||||
PC3.Signal=ADC2_IN9
|
||||
PC9.GPIOParameters=GPIO_Speed,GPIO_Label
|
||||
PC9.GPIO_Label=CHG_CONH
|
||||
PC9.GPIO_Speed=GPIO_SPEED_FREQ_VERY_HIGH
|
||||
|
@ -313,7 +330,7 @@ ProjectManager.ToolChainLocation=
|
|||
ProjectManager.UAScriptAfterPath=
|
||||
ProjectManager.UAScriptBeforePath=
|
||||
ProjectManager.UnderRoot=false
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_ADC2_Init-ADC2-false-HAL-true,6-MX_SPI1_Init-SPI1-false-HAL-true,7-MX_TIM3_Init-TIM3-false-HAL-true,8-MX_TIM6_Init-TIM6-false-HAL-true,9-MX_UART4_Init-UART4-false-HAL-true,10-MX_USART2_UART_Init-USART2-false-HAL-true,11-MX_USART3_UART_Init-USART3-false-HAL-true,12-MX_TIM7_Init-TIM7-false-HAL-true,13-MX_TIM16_Init-TIM16-false-HAL-true,14-MX_TIM15_Init-TIM15-false-HAL-true,15-MX_RTC_Init-RTC-false-HAL-true
|
||||
ProjectManager.functionlistsort=1-SystemClock_Config-RCC-false-HAL-false,2-MX_GPIO_Init-GPIO-false-HAL-true,3-MX_DMA_Init-DMA-false-HAL-true,4-MX_ADC1_Init-ADC1-false-HAL-true,5-MX_ADC2_Init-ADC2-false-HAL-true,6-MX_TIM3_Init-TIM3-false-HAL-true,7-MX_TIM6_Init-TIM6-false-HAL-true,8-MX_UART4_Init-UART4-false-HAL-true,9-MX_USART2_UART_Init-USART2-false-HAL-true,10-MX_USART3_UART_Init-USART3-false-HAL-true,11-MX_TIM7_Init-TIM7-false-HAL-true,12-MX_TIM16_Init-TIM16-false-HAL-true,13-MX_TIM15_Init-TIM15-false-HAL-true,14-MX_RTC_Init-RTC-false-HAL-true
|
||||
RCC.ADC12Freq_Value=72000000
|
||||
RCC.AHBFreq_Value=72000000
|
||||
RCC.APB1Freq_Value=72000000
|
||||
|
@ -334,20 +351,20 @@ RCC.I2C1Freq_Value=72000000
|
|||
RCC.I2C2Freq_Value=72000000
|
||||
RCC.I2C3Freq_Value=72000000
|
||||
RCC.I2SFreq_Value=72000000
|
||||
RCC.IPParameters=ADC12Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSE_VALUE,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PLLSourceVirtual,PWRFreq_Value,RNGFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value
|
||||
RCC.IPParameters=ADC12Freq_Value,AHBFreq_Value,APB1Freq_Value,APB1TimFreq_Value,APB2Freq_Value,APB2TimFreq_Value,CRSFreq_Value,CortexFreq_Value,EXTERNAL_CLOCK_VALUE,FCLKCortexFreq_Value,FDCANFreq_Value,FamilyName,HCLKFreq_Value,HSE_VALUE,HSI48_VALUE,HSI_VALUE,I2C1Freq_Value,I2C2Freq_Value,I2C3Freq_Value,I2SFreq_Value,LPTIM1Freq_Value,LPUART1Freq_Value,LSCOPinFreq_Value,LSI_VALUE,MCO1PinFreq_Value,PLLN,PLLPoutputFreq_Value,PLLQoutputFreq_Value,PLLRCLKFreq_Value,PWRFreq_Value,RNGFreq_Value,RTCClockSelection,RTCFreq_Value,SAI1Freq_Value,SYSCLKFreq_VALUE,SYSCLKSource,UART4Freq_Value,USART1Freq_Value,USART2Freq_Value,USART3Freq_Value,USBFreq_Value,VCOInputFreq_Value,VCOOutputFreq_Value
|
||||
RCC.LPTIM1Freq_Value=72000000
|
||||
RCC.LPUART1Freq_Value=72000000
|
||||
RCC.LSCOPinFreq_Value=32000
|
||||
RCC.LSE_VALUE=32768
|
||||
RCC.LSI_VALUE=32000
|
||||
RCC.MCO1PinFreq_Value=16000000
|
||||
RCC.PLLN=18
|
||||
RCC.PLLN=9
|
||||
RCC.PLLPoutputFreq_Value=72000000
|
||||
RCC.PLLQoutputFreq_Value=72000000
|
||||
RCC.PLLRCLKFreq_Value=72000000
|
||||
RCC.PLLSourceVirtual=RCC_PLLSOURCE_HSE
|
||||
RCC.PWRFreq_Value=72000000
|
||||
RCC.RNGFreq_Value=72000000
|
||||
RCC.RTCClockSelection=RCC_RTCCLKSOURCE_LSE
|
||||
RCC.RTCFreq_Value=32768
|
||||
RCC.SAI1Freq_Value=72000000
|
||||
RCC.SYSCLKFreq_VALUE=72000000
|
||||
RCC.SYSCLKSource=RCC_SYSCLKSOURCE_PLLCLK
|
||||
|
@ -356,21 +373,21 @@ RCC.USART1Freq_Value=72000000
|
|||
RCC.USART2Freq_Value=72000000
|
||||
RCC.USART3Freq_Value=72000000
|
||||
RCC.USBFreq_Value=72000000
|
||||
RCC.VCOInputFreq_Value=8000000
|
||||
RCC.VCOInputFreq_Value=16000000
|
||||
RCC.VCOOutputFreq_Value=144000000
|
||||
RTC.Format=RTC_FORMAT_BIN
|
||||
RTC.IPParameters=Format,WeekDay
|
||||
RTC.WeekDay=RTC_WEEKDAY_MONDAY
|
||||
SH.GPXTI12.0=GPIO_EXTI12
|
||||
SH.GPXTI12.ConfNb=1
|
||||
SH.GPXTI13.0=GPIO_EXTI13
|
||||
SH.GPXTI13.ConfNb=1
|
||||
SH.S_TIM3_CH4.0=TIM3_CH4,PWM Generation4 CH4
|
||||
SH.S_TIM3_CH4.ConfNb=1
|
||||
SPI1.BaudRatePrescaler=SPI_BAUDRATEPRESCALER_4
|
||||
SPI1.CLKPhase=SPI_PHASE_2EDGE
|
||||
SPI1.CLKPolarity=SPI_POLARITY_HIGH
|
||||
SPI1.CalculateBaudRate=18.0 MBits/s
|
||||
SPI1.CalculateBaudRate=36.0 MBits/s
|
||||
SPI1.DataSize=SPI_DATASIZE_8BIT
|
||||
SPI1.Direction=SPI_DIRECTION_2LINES
|
||||
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize,BaudRatePrescaler,CLKPolarity,CLKPhase
|
||||
SPI1.IPParameters=VirtualType,Mode,Direction,CalculateBaudRate,DataSize
|
||||
SPI1.Mode=SPI_MODE_MASTER
|
||||
SPI1.VirtualType=VM_MASTER
|
||||
STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0.DSPOoLibraryJjLibrary_Checked=true
|
||||
|
@ -402,6 +419,8 @@ USART3.VirtualMode-Asynchronous=VM_ASYNC
|
|||
USART3.VirtualMode-Hardware\ Flow\ Control\ (RS485)=VM_ASYNC
|
||||
VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled
|
||||
VP_RTC_VS_RTC_Activate.Signal=RTC_VS_RTC_Activate
|
||||
VP_RTC_VS_RTC_Calendar.Mode=RTC_Calendar
|
||||
VP_RTC_VS_RTC_Calendar.Signal=RTC_VS_RTC_Calendar
|
||||
VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0.Mode=DSPOoLibraryJjLibrary
|
||||
VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0.Signal=STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0
|
||||
VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
|
||||
#ifndef CHARG_CONTROL_ENUM_
|
||||
#define CHARG_CONTROL_ENUM_
|
||||
|
||||
typedef enum _chargMode{
|
||||
noWork = 0, /* 未进行充电 */
|
||||
MPPT = 1, /* 最大功率充电 */
|
||||
constantVoltage = 2, /* 恒压充电 */
|
||||
floatCharg = 3 /* 浮充充电 */
|
||||
}chargMode;
|
||||
|
||||
typedef enum {
|
||||
mosTemperStart = 0, /* 满功率充电mos状态 */
|
||||
mosTemperEnd = 1, /* 降功率充电mos状态 */
|
||||
mosTemperStop = 2, /* 停止充电mos状态 */
|
||||
}mosTState;
|
||||
|
||||
|
||||
/* 注册状态 */
|
||||
typedef enum {
|
||||
UNREGISTER = 0, /* 未注册 */
|
||||
REGISTER_FAIL = 1, /* 注册失败 */
|
||||
REGISTER_SUCCESS = 2, /* 注册成功 */
|
||||
}SL_REGISTERSTATUS;
|
||||
|
||||
/* 接入节点类型 */
|
||||
typedef enum {
|
||||
POWERBOX = 1, /* 电源箱子 */
|
||||
MICROMETEOROLOGY = 2, /* 微气象 */
|
||||
}SL_ACCESSNODETYPE;
|
||||
|
||||
/* 通信方式 */
|
||||
typedef enum {
|
||||
RS485 = 1,
|
||||
RJ45 = 2,
|
||||
// Lora = 3, //暂时未使用
|
||||
}SL_COMMUNICATIONMETHODS;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,71 @@
|
|||
|
||||
#ifndef CHARG_CONTROL_TYPES_
|
||||
#define CHARG_CONTROL_TYPES_
|
||||
|
||||
#include "comm_types.h"
|
||||
|
||||
typedef enum _chargMode{
|
||||
noWork = 0, /* 未进行充电 */
|
||||
MPPT = 1, /* 最大功率充电 */
|
||||
constantVoltage = 2, /* 恒压充电 */
|
||||
floatCharg = 3, /* 浮充充电 */
|
||||
noBattery = 4, /* 无电池 */
|
||||
}chargMode;
|
||||
|
||||
typedef enum {
|
||||
mosTemperFull = 0, /* 满功率充电mos状态 */
|
||||
mosTemperReduce = 1, /* 降功率充电mos状态 */
|
||||
mosTemperStop = 2, /* 停止充电mos状态 */
|
||||
}mosTState;
|
||||
|
||||
/* 注册状态 */
|
||||
typedef enum {
|
||||
UNREGISTER = 0, /* 未注册 */
|
||||
REGISTER_FAIL = 1, /* 注册失败 */
|
||||
REGISTER_SUCCESS = 2, /* 注册成功 */
|
||||
}SL_REGISTERSTATUS;
|
||||
|
||||
/* 接入节点类型 */
|
||||
typedef enum {
|
||||
POWERBOX = 1, /* 电源箱子 */
|
||||
MICROMETEOROLOGY = 2, /* 微气象 */
|
||||
}SL_ACCESSNODETYPE;
|
||||
|
||||
/* 通信方式 */
|
||||
typedef enum {
|
||||
RS485 = 1,
|
||||
RJ45 = 2,
|
||||
// Lora = 3, //暂时未使用
|
||||
}SL_COMMUNICATIONMETHODS;
|
||||
|
||||
/* 时间信息:年月日时分秒 */
|
||||
typedef struct _timeInfo {
|
||||
uint8_t year;
|
||||
uint8_t month;
|
||||
uint8_t day;
|
||||
uint8_t hour;
|
||||
uint8_t minute;
|
||||
uint8_t second;
|
||||
}timeInfo;
|
||||
|
||||
/* 方式 */
|
||||
typedef enum {
|
||||
runLedChargMode = 1, //充电模式
|
||||
runLedOtherMode = 2, //其他模式
|
||||
}runLedMode;
|
||||
|
||||
|
||||
/* 顺序事件记录 */
|
||||
typedef enum {
|
||||
firstStageProtection = 1, //第一段保护,短路保护
|
||||
secondStageProtection , //第二段保护,介于过载和短路之间
|
||||
thirdStageProtection, //第三段保护,过载保护
|
||||
lowInputLoad, //输入功率不足保护
|
||||
overTemperature, //过温保护
|
||||
stopTemperature, //停止温度保护
|
||||
overchargCurr, //充电电流过大保护
|
||||
overInputVolt, //太阳能输入电压过大保护
|
||||
}eventsOrderRecordMode;
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,72 @@
|
|||
#ifndef CONFIG_PARAMETER_
|
||||
#define CONFIG_PARAMETER_
|
||||
|
||||
#include "comm_types.h"
|
||||
|
||||
|
||||
#define softVer "SV01_24101501"
|
||||
|
||||
// /* 第一段保护的延时时间(单位100uS) */
|
||||
// const uint32_t firstStageProtectionDelay = 2; // 200uS
|
||||
// /* 第一段保护的电流(单位A) */
|
||||
// const float_t firstStageProtectionCurr = 50.0f;
|
||||
|
||||
// /* 第二段保护的延时时间(单位100uS) */
|
||||
// const uint32_t secondStageProtectionDelay = 50000; // 5S
|
||||
// /* 第二段保护的电流(单位A) */
|
||||
// const float_t secondStageProtectionCurr = 30.0f;
|
||||
|
||||
// /* 第三段保护的延时时间(单位100uS) */
|
||||
// const uint32_t thirdStageProtectionDelay = 1200000; // 120S
|
||||
// /* 第三段保护的电流(单位A) */
|
||||
// const uint32_t thirdStageProtectionCurr = 35.0f;
|
||||
|
||||
// /* 检测回路阻抗时的充电电流要大于该值(单位A) */
|
||||
// const float_t checkLoopImpedanceChargCurr = 10.0f;
|
||||
|
||||
|
||||
// /* 第三段保护的延时时间(单位100uS) */
|
||||
// const uint32_t lowInputLoadDetectionDelay = 30; // 120S
|
||||
|
||||
|
||||
// /* 第一段保护的延时时间(单位100uS) */
|
||||
/* 第一段保护的延时时间(单位10uS) */
|
||||
#define firstStageProtectionDelayMacro 2
|
||||
// /* 第一段保护的电流(单位A) */
|
||||
// #define firstStageProtectionCurr 50.0f
|
||||
//#define firstStageProtectionCurr 40.0f
|
||||
#define firstStageProtectionCurrMacro 45.0f
|
||||
/* 第一段保护的电流采集的ADC的值 */
|
||||
// #define firstStageProtectionValue 3412
|
||||
//#define firstStageProtectionValue 2730
|
||||
#define firstStageProtectionValueMacro 3071
|
||||
|
||||
/* 第二段保护的延时时间(单位100uS) */
|
||||
#define secondStageProtectionDelayMacro 50000 // 5S
|
||||
/* 第二段保护的电流(单位A) */
|
||||
#define secondStageProtectionCurrMacro 8.0f
|
||||
|
||||
/* 第三段保护的延时时间(单位100uS) */
|
||||
#define thirdStageProtectionDelayMacro 200000 // 20S
|
||||
/* 第三段保护的电流(单位A) */
|
||||
#define thirdStageProtectionCurrMacro 5.0f
|
||||
|
||||
/* 检测回路阻抗时的充电电流要大于该值(单位A) */
|
||||
#define checkLoopImpedanceChargCurrMacro 5.0f
|
||||
|
||||
/* 输入功率较低延时(单位100uS) */
|
||||
#define lowInputLoadDetectionDelayMacro 30 // 3ms
|
||||
/* 输入功率较低延时电压(单位V) */
|
||||
#define lowInputLoadDetectionVoltMacro 10.0f
|
||||
|
||||
/* 最大充电电流(A) */
|
||||
#define maxChargCurrMacro 25.0f
|
||||
|
||||
/* 最大充电电压(V) */
|
||||
#define maxOpenSolarOpenCircuitVMacro 25.0f
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -11,8 +11,8 @@
|
|||
// #define NDEBUG
|
||||
|
||||
#define log_info_enable 1
|
||||
#define log_warn_enable 0
|
||||
#define log_error_enable 0
|
||||
#define log_warn_enable 1
|
||||
#define log_error_enable 1
|
||||
|
||||
/* Comment out this define to include log messages */
|
||||
// #define NLOG
|
||||
|
|
Loading…
Reference in New Issue