添加rtc

This commit is contained in:
起床就犯困 2024-12-16 17:28:12 +08:00
parent 7c32dae073
commit 8cd729d904
30 changed files with 12805 additions and 156 deletions

File diff suppressed because one or more lines are too long

View File

@ -28,6 +28,8 @@
"other.h": "c", "other.h": "c",
"hy_protocol.h": "c", "hy_protocol.h": "c",
"cfg_protocol.h": "c", "cfg_protocol.h": "c",
"chargcontrolenum.h": "c" "chargcontrolenum.h": "c",
"chargcontroltypes.h": "c",
"fm_rtc.h": "c"
} }
} }

View File

@ -4,13 +4,60 @@
#include "Init.h" #include "Init.h"
#include "task.h" #include "task.h"
#include "pDebug.h" #include "pDebug.h"
#include "parameter.h"
void startInfo(void)
{
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("stopSolarOpenCircuitV : %f \n", g_cfgParameter.stopSolarOpenCircuitV);
log_info("constantVoltageChargeV : %f \n", g_cfgParameter.constantVoltageChargeV);
log_info("FloatV : %f \n", g_cfgParameter.FloatV);
log_info("loopImpedance : %f \n", g_cfgParameter.loopImpedance);
log_info("HighSideMosTemperature_stop : %f \n", g_cfgParameter.HighSideMosTemperature_stop);
log_info("HighSideMosTemperature_end : %f \n", g_cfgParameter.HighSideMosTemperature_end);
log_info("HighSideMosTemperature_start : %f \n", g_cfgParameter.HighSideMosTemperature_start);
log_info("outputAgainFlagTime : %d \n", g_cfgParameter.outputAgainFlagTime);
log_info("excessiveLoadFlagTime : %d \n", g_cfgParameter.excessiveLoadFlagTime);
log_info("collectOpenCircuitVoltageTime : %d \n", g_cfgParameter.collectOpenCircuitVoltageTime);
log_info("Access_Node_Type : %d \n", g_cfgParameter.Access_Node_Type);
log_info("Communication_Methods : %d \n", g_cfgParameter.Communication_Methods);
log_info("Registration_Status : %d \n", g_cfgParameter.Registration_Status);
log_info("address : 0x%x%x%x%x%x%x%x \n", g_cfgParameter.address[0]
, g_cfgParameter.address[1]
, g_cfgParameter.address[2]
, g_cfgParameter.address[3]
, g_cfgParameter.address[4]
, g_cfgParameter.address[5]
, g_cfgParameter.address[6]);
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("hardwareID : 0x%x%x%x%x%x%x \n", g_cfgParameter.hardwareID[0]
, g_cfgParameter.hardwareID[1]
, g_cfgParameter.hardwareID[2]
, g_cfgParameter.hardwareID[3]
, g_cfgParameter.hardwareID[4]
, g_cfgParameter.hardwareID[5]);
log_info("communicationID : 0x%x%x%x%x \n", g_cfgParameter.communicationID[0]
, g_cfgParameter.communicationID[1]
, g_cfgParameter.communicationID[2]
, g_cfgParameter.communicationID[3]);
log_info("protocolType : 0x%x \n", g_cfgParameter.protocolType);
log_info("startFlagHY : 0x%x \n", g_cfgParameter.startFlagHY);
log_info("endFlagHY : 0x%x \n", g_cfgParameter.endFlagHY);
log_info("onlyPower : 0x%x \n", g_cfgParameter.onlyPower);
log_info("gw485_Baud : %d \n", g_cfgParameter.gw485_Baud);
log_info("gw485_Baud : %d \n", g_cfgParameter.gw485_Baud);
}
void start(void) void start(void)
{ {
Init(); Init();
task_Init(); task_Init();
debug("start\n"); startInfo();
TimeSliceOffset_Start(); TimeSliceOffset_Start();
} }

View File

@ -1,6 +1,6 @@
#ifndef BL_PARAMETER_H_ #ifndef BL_INIT_H_
#define BL_PARAMETER_H_ #define BL_INIT_H_

View File

@ -1,7 +1,7 @@
#ifndef BL_CHARG_CONTROL_H_ #ifndef BL_CHARG_CONTROL_H_
#define BL_CHARG_CONTROL_H_ #define BL_CHARG_CONTROL_H_
#include "chargControlEnum.h" #include "chargControlTypes.h"
#include "FM_TIM.h" #include "FM_TIM.h"
#include "comm_types.h" #include "comm_types.h"

View File

@ -22,7 +22,7 @@ typedef struct _config_parameter{
float HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 (°C) */ float HighSideMosTemperature_end; /* 当上桥温度上升到该值时,降低功率运行 (°C) */
float HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 (°C) */ float HighSideMosTemperature_start; /* 当上桥温度降低到该值时,按照正常情况输出 (°C) */
uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 (S) */ // uint16_t sensorEnableBroadcastTime; /* 传感器运行再次注册的间隔 (S) */
// uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测间隔时间 (S) */ // uint16_t checkSolarOpenCircuitVTime; /* 启动任务中太阳能板开路电压检测间隔时间 (S) */
uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */ uint16_t outputAgainFlagTime; /* 出现短路保护后延长该段时间再次检测是否短路,仍然短路则关闭输出 (S) */
uint16_t excessiveLoadFlagTime; /* 出现过载后在该间隔时间中多次2次出现过载则关闭输出 (S) */ uint16_t excessiveLoadFlagTime; /* 出现过载后在该间隔时间中多次2次出现过载则关闭输出 (S) */

View File

@ -27,10 +27,10 @@ void Init(void)
tim_Init(); tim_Init();
Init_debug_uart(); Init_debug_uart();
// Init_BAT485_uart(g_cfgParameter.bat485_Baud); Init_BAT485_uart(g_cfgParameter.bat485_Baud);
// Init_GW485_uart(g_cfgParameter.gw485_Baud); Init_GW485_uart(g_cfgParameter.gw485_Baud);
Init_BAT485_uart(115200); // Init_BAT485_uart(115200);
Init_GW485_uart(115200); // Init_GW485_uart(115200);
start_gw485Rx_It(); start_gw485Rx_It();
start_bat485Rx_It(); start_bat485Rx_It();

View File

@ -305,8 +305,8 @@ void mppt_readJust(void)
static float Power = 0; static float Power = 0;
Power = getOutputVoltage() * getChargCurrent(); Power = getOutputVoltage() * getChargCurrent();
static float lPower = 0; static float lPower = 0;
// static float lLPower = 0; static float lLPower = 0;
// static float lLLPower = 0; static float lLLPower = 0;
static float SolarInCircuitV = 17; //控制太阳能板的输出电压稳定在该值,初始为17V static float SolarInCircuitV = 17; //控制太阳能板的输出电压稳定在该值,初始为17V
// static float kp = 0.005; // static float kp = 0.005;
@ -340,9 +340,9 @@ void mppt_readJust(void)
powerT = -powerT; powerT = -powerT;
} }
// if ((lPower + 0.7 < Power) && (lLPower + 0.7 < Power) && (lLLPower + 0.7 < Power)) { if ((lPower + 0.8f < Power) && (lLPower + 0.8f < Power) && (lLLPower + 0.8f < Power)) {
// if ((lPower + 0.7 < Power) && (lLPower + 0.7 < Power)) { // if ((lPower + 0.7f < Power) && (lLPower + 0.7f < Power)) {
if ((lPower + 1.0f < Power)) { // if ((lPower + 1.0f < Power)) {
if (powerT > 5) { if (powerT > 5) {
if (flag1) { if (flag1) {
SolarInCircuitV += stepV1; SolarInCircuitV += stepV1;
@ -360,9 +360,9 @@ void mppt_readJust(void)
flag1 = 0; flag1 = 0;
} }
} }
// } else if ((lPower - 0.7 > Power) && (lLPower - 0.7 > Power) && (lLLPower - 0.7 > Power)) { } else if ((lPower - 0.8f > Power) && (lLPower - 0.8f > Power) && (lLLPower - 0.8f > Power)) {
// } else if ((lPower - 0.7 > Power) && (lLPower - 0.7 > Power)) { // } else if ((lPower - 0.7f > Power) && (lLPower - 0.7f > Power)) {
} else if ((lPower - 1.0f > Power)) { // else if ((lPower - 1.0f > Power)) {
if (powerT > 5) { if (powerT > 5) {
if (flag1) { if (flag1) {
SolarInCircuitV -= stepV1; SolarInCircuitV -= stepV1;
@ -389,6 +389,8 @@ void mppt_readJust(void)
SolarInCircuitV = 16.0f; SolarInCircuitV = 16.0f;
} }
lLLPower = lLPower;
lLPower = lPower;
lPower = Power; lPower = Power;
} }

View File

@ -4,7 +4,7 @@
#include "inFlash.h" #include "inFlash.h"
#include "parameter.h" #include "parameter.h"
#include "string.h" #include "string.h"
#include "chargControlEnum.h" #include "chargControlTypes.h"
#include "pDebug.h" #include "pDebug.h"
#define cfgBuffLen 200 #define cfgBuffLen 200
@ -87,14 +87,14 @@ void zeroConfigBuff(void)
*/ */
void read_and_process_config_data(void) void read_and_process_config_data(void)
{ {
static config_info save_configInfo = {0};
recv_config_info *pack = (recv_config_info *)configBuff; recv_config_info *pack = (recv_config_info *)configBuff;
static config_info save_configInfo;
while (cfigLen >= RECV_CONFIG_INFO) { while (cfigLen >= RECV_CONFIG_INFO) {
/* 判断起始标志是否正确 */ /* 判断起始标志是否正确 */
debug_printf(" start_Flag : 0x%x, 0x%x \n", pack->start_Flag[0], pack->start_Flag[1]); // 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] if (pack->start_Flag[0] != g_cfgParameter.startFlagSL[0]
|| pack->start_Flag[1] != g_cfgParameter.startFlagSL[1]) { || pack->start_Flag[1] != g_cfgParameter.startFlagSL[1]) {
// debug(" start_Flag : 0x%x, 0x%x \n", pack->start_Flag[0], pack->start_Flag[1]); debug(" start_Flag : 0x%x, 0x%x \n", pack->start_Flag[0], pack->start_Flag[1]);
goto err; goto err;
} }
@ -123,7 +123,7 @@ void read_and_process_config_data(void)
// debug(" gw485_Baud : 0x%x, %d \n", save_configInfo.gw485_Baud, save_configInfo.gw485_Baud); // debug(" gw485_Baud : 0x%x, %d \n", save_configInfo.gw485_Baud, save_configInfo.gw485_Baud);
if (save_configInfo.gw485_Baud != 9600 if (save_configInfo.gw485_Baud != 9600
&& save_configInfo.gw485_Baud != 115200) { && save_configInfo.gw485_Baud != 115200) {
// debug(" gw485_Baud : %d\n", save_configInfo.gw485_Baud); debug(" gw485_Baud : %d\n", save_configInfo.gw485_Baud);
goto err; goto err;
} }
@ -134,27 +134,27 @@ void read_and_process_config_data(void)
if (save_configInfo.bat485_Baud != 9600 if (save_configInfo.bat485_Baud != 9600
&& save_configInfo.bat485_Baud!= 115200 && save_configInfo.bat485_Baud!= 115200
&& save_configInfo.bat485_Baud!= 0) { && save_configInfo.bat485_Baud!= 0) {
// debug(" bat485_Baud : 0x%x, %d \n", save_configInfo.bat485_Baud, save_configInfo.bat485_Baud); debug(" bat485_Baud : 0x%x, %d \n", save_configInfo.bat485_Baud, save_configInfo.bat485_Baud);
goto err; goto err;
} }
/* 判断汇源协议类型是否正确 */ /* 判断汇源协议类型是否正确 */
if (pack->protocolType != 0x01 && pack->protocolType != 0x02) { if (pack->protocolType != 0x01 && pack->protocolType != 0x02) {
// debug(" protocolType : 0x%x \n", pack->protocolType); debug(" protocolType : 0x%x \n", pack->protocolType);
goto err; goto err;
} }
/* 判断通信协议类型是否正确 */ /* 判断通信协议类型是否正确 */
if (pack->CommunicationProtocolType != 0x00 if (pack->CommunicationProtocolType != 0x00
&& pack->CommunicationProtocolType != 0x01) { && pack->CommunicationProtocolType != 0x01) {
// debug(" CommunicationProtocolType : 0x%x \n", pack->CommunicationProtocolType); debug(" CommunicationProtocolType : 0x%x \n", pack->CommunicationProtocolType);
goto err; goto err;
} }
/* 判断电源盒类型是否正确 */ /* 判断电源盒类型是否正确 */
if (pack->onlyPower != 0x00 && pack->onlyPower != 0x01) { if (pack->onlyPower != 0x00 && pack->onlyPower != 0x01) {
// debug(" onlyPower : 0x%x \n", pack->onlyPower); debug(" onlyPower : 0x%x \n", pack->onlyPower);
goto err; goto err;
} }
@ -163,14 +163,14 @@ void read_and_process_config_data(void)
(float)(pack->ConstantVoltageV[0] << 8 | pack->ConstantVoltageV[1]) / enlargeScale; (float)(pack->ConstantVoltageV[0] << 8 | pack->ConstantVoltageV[1]) / enlargeScale;
if (!((save_configInfo.constantVoltageV < 14.4f && save_configInfo.constantVoltageV > 13.5f) if (!((save_configInfo.constantVoltageV < 14.4f && save_configInfo.constantVoltageV > 13.5f)
|| save_configInfo.constantVoltageV == 0)) { || save_configInfo.constantVoltageV == 0)) {
// debug(" constantVoltageV : %f \n", save_configInfo.constantVoltageV); debug(" constantVoltageV : %f \n", save_configInfo.constantVoltageV);
goto err; goto err;
} }
/* 判断浮充充电阈值是否正确 */ /* 判断浮充充电阈值是否正确 */
save_configInfo.floatI = (float)(pack->FloatI[0] << 8 | pack->FloatI[1]) / enlargeScale; save_configInfo.floatI = (float)(pack->FloatI[0] << 8 | pack->FloatI[1]) / enlargeScale;
if (save_configInfo.floatI > 0.2f || save_configInfo.floatI < 0) { if (save_configInfo.floatI > 0.2f || save_configInfo.floatI < 0) {
// debug(" floatI : %f \n", save_configInfo.floatI); debug(" floatI : %f \n", save_configInfo.floatI);
goto err; goto err;
} }
@ -179,16 +179,16 @@ void read_and_process_config_data(void)
(float)(pack->startSolarOpenCircuitV[0] << 8 | pack->startSolarOpenCircuitV[1]) / enlargeScale; (float)(pack->startSolarOpenCircuitV[0] << 8 | pack->startSolarOpenCircuitV[1]) / enlargeScale;
if (!((save_configInfo.startSolarOpenCircuitV < 24 && save_configInfo.startSolarOpenCircuitV > 14) if (!((save_configInfo.startSolarOpenCircuitV < 24 && save_configInfo.startSolarOpenCircuitV > 14)
|| save_configInfo.startSolarOpenCircuitV == 0)) { || save_configInfo.startSolarOpenCircuitV == 0)) {
// debug(" startSolarOpenCircuitV : %f \n", save_configInfo.startSolarOpenCircuitV); debug(" startSolarOpenCircuitV : %f \n", save_configInfo.startSolarOpenCircuitV);
goto err; goto err;
} }
/* 判断太阳能板关闭电压是否正确 */ /* 判断太阳能板关闭电压是否正确 */
save_configInfo.stopSolarOpenCircuitV = save_configInfo.stopSolarOpenCircuitV =
(float)(pack->stopSolarOpenCircuitV[0] << 8 | pack->stopSolarOpenCircuitV[1]) / enlargeScale; (float)(pack->stopSolarOpenCircuitV[0] << 8 | pack->stopSolarOpenCircuitV[1]) / enlargeScale;
if (!((save_configInfo.stopSolarOpenCircuitV > 17 && save_configInfo.stopSolarOpenCircuitV < 13) if (!((save_configInfo.stopSolarOpenCircuitV < 17 && save_configInfo.stopSolarOpenCircuitV > 13)
|| save_configInfo.stopSolarOpenCircuitV == 0)) { || save_configInfo.stopSolarOpenCircuitV == 0)) {
// debug(" stopSolarOpenCircuitV : %f \n", save_configInfo.stopSolarOpenCircuitV); debug(" stopSolarOpenCircuitV : %f \n", save_configInfo.stopSolarOpenCircuitV);
goto err; goto err;
} }
@ -197,7 +197,7 @@ void read_and_process_config_data(void)
(float)(pack->constantVoltageChargeV[0] << 8 | pack->constantVoltageChargeV[1]) / enlargeScale; (float)(pack->constantVoltageChargeV[0] << 8 | pack->constantVoltageChargeV[1]) / enlargeScale;
if (!((save_configInfo.constantVoltageChargeV < 14.6f && save_configInfo.constantVoltageChargeV > 14) if (!((save_configInfo.constantVoltageChargeV < 14.6f && save_configInfo.constantVoltageChargeV > 14)
|| save_configInfo.constantVoltageChargeV == 0)) { || save_configInfo.constantVoltageChargeV == 0)) {
// debug(" constantVoltageChargeV : %f \n", save_configInfo.constantVoltageChargeV); debug(" constantVoltageChargeV : %f \n", save_configInfo.constantVoltageChargeV);
goto err; goto err;
} }
@ -206,7 +206,7 @@ void read_and_process_config_data(void)
(float)(pack->FloatChargeV[0] << 8 | pack->FloatChargeV[1]) / enlargeScale; (float)(pack->FloatChargeV[0] << 8 | pack->FloatChargeV[1]) / enlargeScale;
if (!((save_configInfo.FloatChargeV < 14.4f && save_configInfo.FloatChargeV > 13.8f) if (!((save_configInfo.FloatChargeV < 14.4f && save_configInfo.FloatChargeV > 13.8f)
|| save_configInfo.FloatChargeV == 0)) { || save_configInfo.FloatChargeV == 0)) {
// debug(" FloatChargeV : %f \n", save_configInfo.FloatChargeV); debug(" FloatChargeV : %f \n", save_configInfo.FloatChargeV);
goto err; goto err;
} }
@ -214,7 +214,7 @@ void read_and_process_config_data(void)
save_configInfo.HighSideMosTemperature_stop = save_configInfo.HighSideMosTemperature_stop =
(float)(pack->HighSideMosTemperature_stop[0] << 8 | pack->HighSideMosTemperature_stop[1]) / enlargeScale; (float)(pack->HighSideMosTemperature_stop[0] << 8 | pack->HighSideMosTemperature_stop[1]) / enlargeScale;
if (save_configInfo.HighSideMosTemperature_stop < 50 && save_configInfo.HighSideMosTemperature_stop != 0) { if (save_configInfo.HighSideMosTemperature_stop < 50 && save_configInfo.HighSideMosTemperature_stop != 0) {
// debug(" HighSideMosTemperature_stop : %f \n", save_configInfo.HighSideMosTemperature_stop); debug(" HighSideMosTemperature_stop : %f \n", save_configInfo.HighSideMosTemperature_stop);
goto err; goto err;
} }
@ -222,7 +222,7 @@ void read_and_process_config_data(void)
save_configInfo.HighSideMosTemperature_end = save_configInfo.HighSideMosTemperature_end =
(float)(pack->HighSideMosTemperature_end[0] << 8 | pack->HighSideMosTemperature_end[1]) / enlargeScale; (float)(pack->HighSideMosTemperature_end[0] << 8 | pack->HighSideMosTemperature_end[1]) / enlargeScale;
if (save_configInfo.HighSideMosTemperature_end < 40 && save_configInfo.HighSideMosTemperature_end != 0) { if (save_configInfo.HighSideMosTemperature_end < 40 && save_configInfo.HighSideMosTemperature_end != 0) {
// debug(" HighSideMosTemperature_end : %f \n", save_configInfo.HighSideMosTemperature_end); debug(" HighSideMosTemperature_end : %f \n", save_configInfo.HighSideMosTemperature_end);
goto err; goto err;
} }
@ -255,7 +255,7 @@ void read_and_process_config_data(void)
pack->outputAgainFlagTime[0] << 8 | pack->outputAgainFlagTime[1]; pack->outputAgainFlagTime[0] << 8 | pack->outputAgainFlagTime[1];
if (!((save_configInfo.outputAgainFlagTime < 30 && save_configInfo.outputAgainFlagTime > 5) if (!((save_configInfo.outputAgainFlagTime < 30 && save_configInfo.outputAgainFlagTime > 5)
|| save_configInfo.outputAgainFlagTime == 0)) { || save_configInfo.outputAgainFlagTime == 0)) {
// debug(" outputAgainFlagTime : %d \n", save_configInfo.outputAgainFlagTime); debug(" outputAgainFlagTime : %d \n", save_configInfo.outputAgainFlagTime);
goto err; goto err;
} }
@ -264,7 +264,7 @@ void read_and_process_config_data(void)
pack->excessiveLoadFlagTime[0] << 8 | pack->excessiveLoadFlagTime[1]; pack->excessiveLoadFlagTime[0] << 8 | pack->excessiveLoadFlagTime[1];
if (!((save_configInfo.excessiveLoadFlagTime < 90 && save_configInfo.excessiveLoadFlagTime > 20) if (!((save_configInfo.excessiveLoadFlagTime < 90 && save_configInfo.excessiveLoadFlagTime > 20)
|| save_configInfo.excessiveLoadFlagTime == 0)) { || save_configInfo.excessiveLoadFlagTime == 0)) {
// debug(" excessiveLoadFlagTime : %d \n", save_configInfo.excessiveLoadFlagTime); debug(" excessiveLoadFlagTime : %d \n", save_configInfo.excessiveLoadFlagTime);
goto err; goto err;
} }

View File

@ -9,6 +9,10 @@
#include "inFlash.h" #include "inFlash.h"
#include "bl_chargControl.h" #include "bl_chargControl.h"
#include "bl_comm.h" #include "bl_comm.h"
#include "chargControlTypes.h"
#include "FM_RTC.h"
// #include "RingQueue.h" // #include "RingQueue.h"
// 声明 beginHYconfigMode 函数 // 声明 beginHYconfigMode 函数
@ -29,6 +33,8 @@ typedef enum
HY_chargingControlConfiguration = 0x6C, /* 充电控制配置 */ HY_chargingControlConfiguration = 0x6C, /* 充电控制配置 */
HY_chargingControlQuery = 0x6D, /* 充电控制查询 */ HY_chargingControlQuery = 0x6D, /* 充电控制查询 */
HY_configurationTime = 0x6E, /* 配置时间 */
HY_queryTime = 0x6F, /* 查询时间 */
HY_configureProtocolType = 0x70, /* 配置协议类型 */ HY_configureProtocolType = 0x70, /* 配置协议类型 */
HY_responseConfigureProtocolType = 0x71, /* 响应配置协议类型 */ HY_responseConfigureProtocolType = 0x71, /* 响应配置协议类型 */
@ -600,6 +606,64 @@ typedef struct _HY_checkMotherboardTemperatureResponse{
#define HY_checkMotherboardTemperatureResponse_PACK_SIZE (sizeof(HY_checkMotherboardTemperatureResponse)) #define HY_checkMotherboardTemperatureResponse_PACK_SIZE (sizeof(HY_checkMotherboardTemperatureResponse))
#define HY_checkMotherboardTemperatureResponse_dataLen 8 #define HY_checkMotherboardTemperatureResponse_dataLen 8
/* 配置时间 */
typedef struct _HY_configTime {
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
timeInfo time; /* 年月日时分秒 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_configTime;
#define HY_configTime_PACK_SIZE (sizeof(HY_configTime))
/* 配置时间响应 */
typedef struct _HY_configTimeResponse {
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint8_t state; /* 状态 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_configTimeResponse;
#define HY_configTimeResponse_PACK_SIZE (sizeof(HY_configTimeResponse))
#define HY_configTimeResponse_dataLen 5
/* 查询时间 */
typedef struct _HY_timeQuery {
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_timeQuery;
#define HY_timeQuery_PACK_SIZE (sizeof(HY_timeQuery))
/* 查询时间响应 */
typedef struct _HY_queryTimeResponse {
uint8_t start_Flag; /* 起始标志 */
uint8_t hardwareID[6]; /* 硬件ID高字节在前低字节在后 */
uint8_t communicationID[4]; /* 通信ID高字节在前低字节在后 */
uint8_t controlWord; /* 控制字 */
uint8_t dataLen[2]; /* 数据长度;高字节在前,低字节在后 */
timeInfo time; /* 年月日时分秒 */
uint32_t frameNumber; /* 帧序号 */
uint8_t check_Bit; /* 校验码 */
uint8_t end_Flag; /* 结束标志 */
}HY_queryTimeResponse;
#define HY_queryTimeResponse_PACK_SIZE (sizeof(HY_queryTimeResponse))
#define HY_queryTimeResponse_dataLen 10
/* 恢复默认的对齐设置 */ /* 恢复默认的对齐设置 */
#pragma pack(pop) #pragma pack(pop)
@ -644,6 +708,11 @@ static void HY_MsgProcFunc_resetInstruction(device_handle device, void *pMsg, ui
static void HY_MsgProcFunc_chargingControlConfiguration(device_handle device, void *pMsg, uint32_t MsgLen); static void HY_MsgProcFunc_chargingControlConfiguration(device_handle device, void *pMsg, uint32_t MsgLen);
/* 充电控制查询 */ /* 充电控制查询 */
static void HY_MsgProcFunc_chargingControlQuery(device_handle device, void *pMsg, uint32_t MsgLen); static void HY_MsgProcFunc_chargingControlQuery(device_handle device, void *pMsg, uint32_t MsgLen);
/* 配置时间 */
static void HY_MsgProcFunc_configTime(device_handle device, void *pMsg, uint32_t MsgLen);
/* 查询时间 */
static void HY_MsgProcFunc_queryTime(device_handle device, void *pMsg, uint32_t MsgLen);
/* 配置协议类型 */ /* 配置协议类型 */
static void HY_MsgProcFunc_configureProtocolType(device_handle device, void *pMsg, uint32_t MsgLen); static void HY_MsgProcFunc_configureProtocolType(device_handle device, void *pMsg, uint32_t MsgLen);
@ -686,9 +755,13 @@ HY_FuncionMsgProcTable g_hyMsgTbl[] =
{HY_configureHardwareID, HY_MsgProcFunc_configureHardwareID}, {HY_configureHardwareID, HY_MsgProcFunc_configureHardwareID},
{HY_hardwareID_communicationIDQuery, HY_MsgProcFunc_hardwareID_communicationIDQuery}, {HY_hardwareID_communicationIDQuery, HY_MsgProcFunc_hardwareID_communicationIDQuery},
{HY_modifyCommunicationID, HY_MsgProcFunc_modifyCommunicationID}, {HY_modifyCommunicationID, HY_MsgProcFunc_modifyCommunicationID},
{HY_checkMotherboardTemperature, HY_MsgProcFunc_checkMotherboardTemperature}, {HY_checkMotherboardTemperature, HY_MsgProcFunc_checkMotherboardTemperature},
{HY_configurationTime, HY_MsgProcFunc_configTime},
{HY_queryTime, HY_MsgProcFunc_queryTime},
}; };
/** /**
* @brief HY协议配置状态 * @brief HY协议配置状态
* @param None * @param None
@ -938,6 +1011,14 @@ static int HY_uart_read_climate_pack(device_handle uart_handle,uint8_t *buff, ui
len = HY_checkMotherboardTemperatureQuery_PACK_SIZE; len = HY_checkMotherboardTemperatureQuery_PACK_SIZE;
} }
else if (pack->controlWord == HY_configurationTime && hardwordIDType == 0x02) {
len = HY_configTime_PACK_SIZE;
}
else if (pack->controlWord == HY_queryTime && hardwordIDType == 0x02) {
len = HY_timeQuery_PACK_SIZE;
}
else { else {
if (flag_run < 3) { if (flag_run < 3) {
flag_run = 3; flag_run = 3;
@ -1736,3 +1817,82 @@ void HY_MsgProcFunc_checkMotherboardTemperature(device_handle device, void *pMsg
uart_dev_write(device, &pack, HY_checkMotherboardTemperatureResponse_PACK_SIZE); uart_dev_write(device, &pack, HY_checkMotherboardTemperatureResponse_PACK_SIZE);
} }
/* 配置时间 */
void HY_MsgProcFunc_configTime(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_configTime *Tpack = (HY_configTime *)pMsg;
setRTC_Time(&Tpack->time);
HY_configTimeResponse pack;
pack.start_Flag = g_cfgParameter.startFlagHY;
pack.hardwareID[0] = g_cfgParameter.hardwareID[0];
pack.hardwareID[1] = g_cfgParameter.hardwareID[1];
pack.hardwareID[2] = g_cfgParameter.hardwareID[2];
pack.hardwareID[3] = g_cfgParameter.hardwareID[3];
pack.hardwareID[4] = g_cfgParameter.hardwareID[4];
pack.hardwareID[5] = g_cfgParameter.hardwareID[5];
pack.communicationID[0] = g_cfgParameter.communicationID[0];
pack.communicationID[1] = g_cfgParameter.communicationID[1];
pack.communicationID[2] = g_cfgParameter.communicationID[2];
pack.communicationID[3] = g_cfgParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_configTimeResponse_dataLen >> 8;
pack.dataLen[1] = HY_configTimeResponse_dataLen;
pack.state = HY_success;
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_configTimeResponse_PACK_SIZE - 2);
pack.end_Flag = g_cfgParameter.endFlagHY;
uart_dev_write(device, &pack, HY_configTimeResponse_PACK_SIZE);
}
/* 查询时间 */
static void HY_MsgProcFunc_queryTime(device_handle device, void *pMsg, uint32_t MsgLen)
{
HY_timeQuery *Tpack = (HY_timeQuery *)pMsg;
HY_queryTimeResponse pack;
pack.start_Flag = g_cfgParameter.startFlagHY;
pack.hardwareID[0] = g_cfgParameter.hardwareID[0];
pack.hardwareID[1] = g_cfgParameter.hardwareID[1];
pack.hardwareID[2] = g_cfgParameter.hardwareID[2];
pack.hardwareID[3] = g_cfgParameter.hardwareID[3];
pack.hardwareID[4] = g_cfgParameter.hardwareID[4];
pack.hardwareID[5] = g_cfgParameter.hardwareID[5];
pack.communicationID[0] = g_cfgParameter.communicationID[0];
pack.communicationID[1] = g_cfgParameter.communicationID[1];
pack.communicationID[2] = g_cfgParameter.communicationID[2];
pack.communicationID[3] = g_cfgParameter.communicationID[3];
pack.controlWord = Tpack->controlWord;
pack.dataLen[0] = HY_queryTimeResponse_dataLen >> 8;
pack.dataLen[1] = HY_queryTimeResponse_dataLen;
timeInfo time;
getRTC_Time(&time);
pack.time = time;
pack.frameNumber = Tpack->frameNumber;
pack.check_Bit = HY_CheckFunc((uint8_t *)(&pack), HY_queryTimeResponse_PACK_SIZE - 2);
pack.end_Flag = g_cfgParameter.endFlagHY;
uart_dev_write(device, &pack, HY_queryTimeResponse_PACK_SIZE);
}

View File

@ -46,9 +46,9 @@ void read_config_info(config_info *output_config_info)
// read_Flash((uint8_t *)output_config_info, CONFIG_SAVE_addr, CONFIG_INFO_SIZE); // 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); // save_backups_config_info(config_info);
} }
@ -58,11 +58,19 @@ void saveConfigInfo(config_info *config_info)
* @retval None * @retval None
* *
*/ */
static void readFlashContent(config_info *config_info) static 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;
// static volatile config_info *tempConfigInfo1;
// tempConfigInfo1 = configInfo;
// 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; return;
} }
@ -74,48 +82,48 @@ static void readFlashContent(config_info *config_info)
// } // }
/* 配置文件错误使用默认配置 */ /* 配置文件错误使用默认配置 */
config_info->address[0] = 0x11; configInfo->address[0] = 0x11;
config_info->address[1] = 0x11; configInfo->address[1] = 0x11;
config_info->address[2] = 0x11; configInfo->address[2] = 0x11;
config_info->address[3] = 0x11; configInfo->address[3] = 0x11;
config_info->address[4] = 0x11; configInfo->address[4] = 0x11;
config_info->address[5] = 0x11; configInfo->address[5] = 0x11;
config_info->address[6] = 0x11; configInfo->address[6] = 0x11;
// config_info->Access_Node_Type = 0x01; // config_info->Access_Node_Type = 0x01;
// config_info->Communication_Methods = 0x02; // config_info->Communication_Methods = 0x02;
config_info->gw485_Baud = 9600; configInfo->gw485_Baud = 9600;
config_info->bat485_Baud = 115200; configInfo->bat485_Baud = 115200;
config_info->hardwareID[0] = 0x48; configInfo->hardwareID[0] = 0x48;
config_info->hardwareID[1] = 0x59; configInfo->hardwareID[1] = 0x59;
config_info->hardwareID[2] = 0x30; configInfo->hardwareID[2] = 0x30;
config_info->hardwareID[3] = 0x30; configInfo->hardwareID[3] = 0x30;
config_info->hardwareID[4] = 0x30; configInfo->hardwareID[4] = 0x30;
config_info->hardwareID[5] = 0x31; configInfo->hardwareID[5] = 0x31;
config_info->communicationID[0] = 0x00; configInfo->communicationID[0] = 0x00;
config_info->communicationID[1] = 0x00; configInfo->communicationID[1] = 0x00;
config_info->communicationID[2] = 0x00; configInfo->communicationID[2] = 0x00;
config_info->communicationID[3] = 0x01; configInfo->communicationID[3] = 0x01;
config_info->protocolType = 0x01; configInfo->protocolType = 0x01;
config_info->CommunicationProtocolType = 0x01; configInfo->CommunicationProtocolType = 0x01;
config_info->onlyPower = 0x01; configInfo->onlyPower = 0x01;
config_info->constantVoltageV = 14; configInfo->constantVoltageV = 14;
config_info->floatI = 0.02; configInfo->floatI = 0.02;
config_info->startSolarOpenCircuitV = 17; configInfo->startSolarOpenCircuitV = 17;
config_info->stopSolarOpenCircuitV = 15; configInfo->stopSolarOpenCircuitV = 15;
config_info->constantVoltageChargeV = 14.4; configInfo->constantVoltageChargeV = 14.4;
config_info->FloatChargeV = 14; configInfo->FloatChargeV = 14;
config_info->HighSideMosTemperature_stop = 100; configInfo->HighSideMosTemperature_stop = 100;
config_info->HighSideMosTemperature_end = 90; configInfo->HighSideMosTemperature_end = 90;
config_info->HighSideMosTemperature_start = 50; configInfo->HighSideMosTemperature_start = 50;
// config_info->checkSolarOpenCircuitVTime = 10; // configInfo->checkSolarOpenCircuitVTime = 10;
// config_info->sensorEnableBroadcastTime = 20; // configInfo->sensorEnableBroadcastTime = 20;
config_info->outputAgainFlagTime = 10; configInfo->outputAgainFlagTime = 10;
config_info->excessiveLoadFlagTime = 60; configInfo->excessiveLoadFlagTime = 60;
config_info->eLAgainTime = 1800; configInfo->eLAgainTime = 1800;
} }
/** /**
@ -203,6 +211,7 @@ void config_info_start(void)
totalElectricityConsumptionInt(fTemp); totalElectricityConsumptionInt(fTemp);
readtotalChargCapacity(&fTemp); readtotalChargCapacity(&fTemp);
totalChargCapacityInt(fTemp); totalChargCapacityInt(fTemp);
} }

View File

@ -3,7 +3,7 @@
#include "FM_TIM.h" #include "FM_TIM.h"
#include "FM_GPIO.h" #include "FM_GPIO.h"
#include "capture.h" #include "capture.h"
#include "chargControlEnum.h" #include "chargControlTypes.h"
config_parameter g_cfgParameter = {0}; config_parameter g_cfgParameter = {0};
static otherParameter g_otherParameter = {0}; static otherParameter g_otherParameter = {0};

View File

@ -3,7 +3,7 @@
#include "inFlash.h" #include "inFlash.h"
#include "parameter.h" #include "parameter.h"
#include "FM_GPIO.h" #include "FM_GPIO.h"
#include "chargControlEnum.h" #include "chargControlTypes.h"
#include "bl_chargControl.h" #include "bl_chargControl.h"
#include "hy_protocol.h" #include "hy_protocol.h"
#include "cfg_protocol.h" #include "cfg_protocol.h"
@ -108,7 +108,7 @@ void task_Init(void)
TimeSliceOffset_Register(&m_collectOpenCircuitVoltage, Task_collectOpenCircuitVoltage TimeSliceOffset_Register(&m_collectOpenCircuitVoltage, Task_collectOpenCircuitVoltage
, collectOpenCircuitVoltage_reloadVal, collectOpenCircuitVoltage_offset); , collectOpenCircuitVoltage_reloadVal, collectOpenCircuitVoltage_offset);
uartTaskInit(); uartTaskInit();
TimeSliceOffset_Register(&m_usartJudge, Task_usartJudge, usartJudge_reloadVal, usartJudge_offset); TimeSliceOffset_Register(&m_usartJudge, Task_usartJudge, usartJudge_reloadVal, usartJudge_offset);
TimeSliceOffset_Register(&m_usartCfg, Task_usartCfg, usartCfg_reloadVal, usartCfg_offset); TimeSliceOffset_Register(&m_usartCfg, Task_usartCfg, usartCfg_reloadVal, usartCfg_offset);
} }
@ -133,17 +133,17 @@ void Task_wdi(void)
{ {
feedDog(); feedDog();
// debug_printf("chargCurrent:%f \n", getChargCurrent()); debug_printf("chargCurrent:%f \n", getChargCurrent());
// debug_printf("outputVoltage:%f \n", getOutputVoltage()); debug_printf("outputVoltage:%f \n", getOutputVoltage());
// debug_printf("BatteryVoltage:%f \n", getBatteryVoltage()); debug_printf("BatteryVoltage:%f \n", getBatteryVoltage());
// debug_printf("dischargCurrent:%f \n", getDischargCurrent()); debug_printf("dischargCurrent:%f \n", getDischargCurrent());
// debug_printf("solarInCircuitVoltage:%f \n", getSolarInCircuitVoltage()); debug_printf("solarInCircuitVoltage:%f \n", getSolarInCircuitVoltage());
// debug_printf("HighSideMosTemperature:%f \n", getHighSideMosTemperature()); debug_printf("HighSideMosTemperature:%f \n", getHighSideMosTemperature());
// debug_printf("InputVoltage:%f \n", getInputVoltage()); debug_printf("InputVoltage:%f \n", getInputVoltage());
// debug_printf("DischargMosState:%d \n", getDischargMosState()); debug_printf("DischargMosState:%d \n", getDischargMosState());
// debug_printf("MPPT_Mode:%d \n", getMPPT_Mode()); debug_printf("MPPT_Mode:%d \n", getMPPT_Mode());
// debug_printf("loopImpedance:%f \n", g_cfgParameter.loopImpedance); debug_printf("loopImpedance:%f \n", g_cfgParameter.loopImpedance);
// debug_printf("DutyRatio:%f \n", getDutyRatio()); debug_printf("DutyRatio:%f \n", getDutyRatio());
/* 每天复位一次复位前将电量信息写入flash中 */ /* 每天复位一次复位前将电量信息写入flash中 */
static uint32_t temp = 60 * 60 * 24; static uint32_t temp = 60 * 60 * 24;

View File

@ -0,0 +1,12 @@
#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);
#endif

View File

@ -0,0 +1,62 @@
#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)
{
/* 日期结构体 */
RTC_DateTypeDef setData;
/* 时间结构体 */
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)
{
/* 日期结构体 */
RTC_DateTypeDef getData;
/* 时间结构体 */
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;
}

View File

@ -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

View File

@ -0,0 +1,12 @@
#include "HD_RTC.h"
void HD_RTC_Init(void)
{
MX_RTC_Init();
}

52
Core/Inc/rtc.h Normal file
View File

@ -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__ */

View File

@ -56,7 +56,7 @@
/*#define HAL_PCD_MODULE_ENABLED */ /*#define HAL_PCD_MODULE_ENABLED */
/*#define HAL_QSPI_MODULE_ENABLED */ /*#define HAL_QSPI_MODULE_ENABLED */
/*#define HAL_RNG_MODULE_ENABLED */ /*#define HAL_RNG_MODULE_ENABLED */
/*#define HAL_RTC_MODULE_ENABLED */ #define HAL_RTC_MODULE_ENABLED
/*#define HAL_SAI_MODULE_ENABLED */ /*#define HAL_SAI_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */ /*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SMBUS_MODULE_ENABLED */ /*#define HAL_SMBUS_MODULE_ENABLED */

View File

@ -20,6 +20,7 @@
#include "main.h" #include "main.h"
#include "adc.h" #include "adc.h"
#include "dma.h" #include "dma.h"
#include "rtc.h"
#include "spi.h" #include "spi.h"
#include "tim.h" #include "tim.h"
#include "usart.h" #include "usart.h"
@ -107,6 +108,7 @@ int main(void)
// MX_TIM7_Init(); // MX_TIM7_Init();
// MX_TIM16_Init(); // MX_TIM16_Init();
// MX_TIM15_Init(); // MX_TIM15_Init();
// MX_RTC_Init();
/* USER CODE BEGIN 2 */ /* USER CODE BEGIN 2 */
start(); start();
@ -143,8 +145,9 @@ void SystemClock_Config(void)
/** Initializes the RCC Oscillators according to the specified parameters /** Initializes the RCC Oscillators according to the specified parameters
* in the RCC_OscInitTypeDef structure. * in the RCC_OscInitTypeDef structure.
*/ */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_HSE;
RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSEState = RCC_HSE_ON;
RCC_OscInitStruct.LSIState = RCC_LSI_ON;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1; RCC_OscInitStruct.PLL.PLLM = RCC_PLLM_DIV1;

139
Core/Src/rtc.c Normal file
View File

@ -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_LSI;
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 */

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

View File

@ -1162,6 +1162,9 @@
<file> <file>
<name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_GPIO.c</name> <name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_GPIO.c</name>
</file> </file>
<file>
<name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_RTC.c</name>
</file>
<file> <file>
<name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_TIM.c</name> <name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_TIM.c</name>
</file> </file>
@ -1180,6 +1183,9 @@
<file> <file>
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_GPIO.c</name> <name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_GPIO.c</name>
</file> </file>
<file>
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_RTC.c</name>
</file>
<file> <file>
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_TIM.c</name> <name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_TIM.c</name>
</file> </file>
@ -1212,6 +1218,9 @@
<file> <file>
<name>$PROJ_DIR$\..\Core\Src\main.c</name> <name>$PROJ_DIR$\..\Core\Src\main.c</name>
</file> </file>
<file>
<name>$PROJ_DIR$\..\Core\Src\rtc.c</name>
</file>
<file> <file>
<name>$PROJ_DIR$\..\Core\Src\spi.c</name> <name>$PROJ_DIR$\..\Core\Src\spi.c</name>
</file> </file>
@ -1285,6 +1294,12 @@
<file> <file>
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c</name> <name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c</name>
</file> </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> <file>
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c</name> <name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c</name>
</file> </file>

View File

@ -1484,6 +1484,9 @@
<file> <file>
<name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_GPIO.c</name> <name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_GPIO.c</name>
</file> </file>
<file>
<name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_RTC.c</name>
</file>
<file> <file>
<name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_TIM.c</name> <name>$PROJ_DIR$\..\APP\functionalModule\Src\FM_TIM.c</name>
</file> </file>
@ -1502,6 +1505,9 @@
<file> <file>
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_GPIO.c</name> <name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_GPIO.c</name>
</file> </file>
<file>
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_RTC.c</name>
</file>
<file> <file>
<name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_TIM.c</name> <name>$PROJ_DIR$\..\APP\hardwareDriver\Src\HD_TIM.c</name>
</file> </file>
@ -1534,6 +1540,9 @@
<file> <file>
<name>$PROJ_DIR$\..\Core\Src\main.c</name> <name>$PROJ_DIR$\..\Core\Src\main.c</name>
</file> </file>
<file>
<name>$PROJ_DIR$\..\Core\Src\rtc.c</name>
</file>
<file> <file>
<name>$PROJ_DIR$\..\Core\Src\spi.c</name> <name>$PROJ_DIR$\..\Core\Src\spi.c</name>
</file> </file>
@ -1607,6 +1616,12 @@
<file> <file>
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c</name> <name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_rcc_ex.c</name>
</file> </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> <file>
<name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c</name> <name>$PROJ_DIR$\..\Drivers\STM32G4xx_HAL_Driver\Src\stm32g4xx_hal_spi.c</name>
</file> </file>

View File

@ -85,45 +85,48 @@ Mcu.IPNb=16
Mcu.Name=STM32G431R(6-8-B)Tx Mcu.Name=STM32G431R(6-8-B)Tx
Mcu.Package=LQFP64 Mcu.Package=LQFP64
Mcu.Pin0=PC13 Mcu.Pin0=PC13
Mcu.Pin1=PF0-OSC_IN Mcu.Pin1=PC14-OSC32_IN
Mcu.Pin10=PA5 Mcu.Pin10=PA3
Mcu.Pin11=PA6 Mcu.Pin11=PA4
Mcu.Pin12=PA7 Mcu.Pin12=PA5
Mcu.Pin13=PB0 Mcu.Pin13=PA6
Mcu.Pin14=PB1 Mcu.Pin14=PA7
Mcu.Pin15=PB10 Mcu.Pin15=PB0
Mcu.Pin16=PB11 Mcu.Pin16=PB1
Mcu.Pin17=PB12 Mcu.Pin17=PB10
Mcu.Pin18=PB14 Mcu.Pin18=PB11
Mcu.Pin19=PB15 Mcu.Pin19=PB12
Mcu.Pin2=PF1-OSC_OUT Mcu.Pin2=PC15-OSC32_OUT
Mcu.Pin20=PC9 Mcu.Pin20=PB14
Mcu.Pin21=PA10 Mcu.Pin21=PB15
Mcu.Pin22=PA11 Mcu.Pin22=PC9
Mcu.Pin23=PA12 Mcu.Pin23=PA10
Mcu.Pin24=PA13 Mcu.Pin24=PA11
Mcu.Pin25=PA14 Mcu.Pin25=PA12
Mcu.Pin26=PC10 Mcu.Pin26=PA13
Mcu.Pin27=PC11 Mcu.Pin27=PA14
Mcu.Pin28=PB6 Mcu.Pin28=PC10
Mcu.Pin29=PB7 Mcu.Pin29=PC11
Mcu.Pin3=PC1 Mcu.Pin3=PF0-OSC_IN
Mcu.Pin30=PB8-BOOT0 Mcu.Pin30=PB6
Mcu.Pin31=VP_RTC_VS_RTC_Activate Mcu.Pin31=PB7
Mcu.Pin32=VP_SYS_VS_Systick Mcu.Pin32=PB8-BOOT0
Mcu.Pin33=VP_SYS_VS_DBSignals Mcu.Pin33=VP_RTC_VS_RTC_Activate
Mcu.Pin34=VP_TIM6_VS_ClockSourceINT Mcu.Pin34=VP_RTC_VS_RTC_Calendar
Mcu.Pin35=VP_TIM7_VS_ClockSourceINT Mcu.Pin35=VP_SYS_VS_Systick
Mcu.Pin36=VP_TIM15_VS_ClockSourceINT Mcu.Pin36=VP_SYS_VS_DBSignals
Mcu.Pin37=VP_TIM16_VS_ClockSourceINT Mcu.Pin37=VP_TIM6_VS_ClockSourceINT
Mcu.Pin38=VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0 Mcu.Pin38=VP_TIM7_VS_ClockSourceINT
Mcu.Pin4=PC2 Mcu.Pin39=VP_TIM15_VS_ClockSourceINT
Mcu.Pin5=PA0 Mcu.Pin4=PF1-OSC_OUT
Mcu.Pin6=PA1 Mcu.Pin40=VP_TIM16_VS_ClockSourceINT
Mcu.Pin7=PA2 Mcu.Pin41=VP_STMicroelectronics.X-CUBE-ALGOBUILD_VS_DSPOoLibraryJjLibrary_1.4.0_1.4.0
Mcu.Pin8=PA3 Mcu.Pin5=PC1
Mcu.Pin9=PA4 Mcu.Pin6=PC2
Mcu.PinsNb=39 Mcu.Pin7=PA0
Mcu.Pin8=PA1
Mcu.Pin9=PA2
Mcu.PinsNb=42
Mcu.ThirdParty0=STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0 Mcu.ThirdParty0=STMicroelectronics.X-CUBE-ALGOBUILD.1.4.0
Mcu.ThirdPartyNb=1 Mcu.ThirdPartyNb=1
Mcu.UserConstants= Mcu.UserConstants=
@ -269,6 +272,10 @@ PC13.GPIO_ModeDefaultEXTI=GPIO_MODE_IT_FALLING
PC13.GPIO_PuPd=GPIO_PULLUP PC13.GPIO_PuPd=GPIO_PULLUP
PC13.Locked=true PC13.Locked=true
PC13.Signal=GPXTI13 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.GPIOParameters=GPIO_Label
PC2.GPIO_Label=DSG_CURR PC2.GPIO_Label=DSG_CURR
PC2.Mode=IN8-Single-Ended PC2.Mode=IN8-Single-Ended
@ -334,11 +341,10 @@ RCC.I2C1Freq_Value=72000000
RCC.I2C2Freq_Value=72000000 RCC.I2C2Freq_Value=72000000
RCC.I2C3Freq_Value=72000000 RCC.I2C3Freq_Value=72000000
RCC.I2SFreq_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,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.LPTIM1Freq_Value=72000000 RCC.LPTIM1Freq_Value=72000000
RCC.LPUART1Freq_Value=72000000 RCC.LPUART1Freq_Value=72000000
RCC.LSCOPinFreq_Value=32000 RCC.LSCOPinFreq_Value=32000
RCC.LSE_VALUE=32768
RCC.LSI_VALUE=32000 RCC.LSI_VALUE=32000
RCC.MCO1PinFreq_Value=16000000 RCC.MCO1PinFreq_Value=16000000
RCC.PLLN=18 RCC.PLLN=18
@ -358,6 +364,9 @@ RCC.USART3Freq_Value=72000000
RCC.USBFreq_Value=72000000 RCC.USBFreq_Value=72000000
RCC.VCOInputFreq_Value=8000000 RCC.VCOInputFreq_Value=8000000
RCC.VCOOutputFreq_Value=144000000 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.0=GPIO_EXTI12
SH.GPXTI12.ConfNb=1 SH.GPXTI12.ConfNb=1
SH.GPXTI13.0=GPIO_EXTI13 SH.GPXTI13.0=GPIO_EXTI13
@ -402,6 +411,8 @@ USART3.VirtualMode-Asynchronous=VM_ASYNC
USART3.VirtualMode-Hardware\ Flow\ Control\ (RS485)=VM_ASYNC USART3.VirtualMode-Hardware\ Flow\ Control\ (RS485)=VM_ASYNC
VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled VP_RTC_VS_RTC_Activate.Mode=RTC_Enabled
VP_RTC_VS_RTC_Activate.Signal=RTC_VS_RTC_Activate 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.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_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 VP_SYS_VS_DBSignals.Mode=DisableDeadBatterySignals

View File

@ -1,6 +1,8 @@
#ifndef CHARG_CONTROL_ENUM_ #ifndef CHARG_CONTROL_TYPES_
#define CHARG_CONTROL_ENUM_ #define CHARG_CONTROL_TYPES_
#include "comm_types.h"
typedef enum _chargMode{ typedef enum _chargMode{
noWork = 0, /* 未进行充电 */ noWork = 0, /* 未进行充电 */
@ -36,7 +38,15 @@ typedef enum {
// Lora = 3, //暂时未使用 // Lora = 3, //暂时未使用
}SL_COMMUNICATIONMETHODS; }SL_COMMUNICATIONMETHODS;
/* 时间信息:年月日时分秒 */
typedef struct _timeInfo {
uint8_t year;
uint8_t month;
uint8_t day;
uint8_t hour;
uint8_t minute;
uint8_t second;
}timeInfo;