mppt/App/src/inflash.c

112 lines
3.5 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
* inflash.c
*
* Created on: 2024年6月24日
* Author: psx
*/
#include "inflash.h"
#include "flash.h"
#include "sl_protocol.h"
config_info g_slConfigInfo = {
.constantCurrentV = 1000,
.constantVoltageV = 1420,
.floatI = 20,
.startSolarOpenCircuitV = 1700,
.stopSolarOpenCircuitV = 1500,
.constantVoltageChargeV = 1440,
.trickleChargeC = 100,
// .FloatTime = 10,
.FloatV = 1420,
.checkSolarOpenCircuitVTime = 10,
.registerRefreshTime = 1,
.loopImpedance = 20,
// .resRefreshTime = 1,
.sensorEnableBroadcastTime = 20,
.HighSideMosTemperature_stop = 70,
.HighSideMosTemperature_end = 50,
.HighSideMosTemperature_start = 40,
.outputAgainFlagTime = 10,
.excessiveLoadFlagTime = 60,
.eLAgainTime = 3600,
};
/**
* @brief 保存配置信息
* @param save_config_info 需要保存的配置信息
* @retval
*/
void save_config_info(config_info *save_config_info)
{
SPI_Flash_Write((uint8_t *)save_config_info, FLASH_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
}
/**
* @brief 读取配置信息
* @param read_config_info 读取的配置信息
* @retval 0 flash中读取配置失败
* 1 flash中读取配置成功
*/
uint8_t read_config_info(void)
{
config_info temp_config_info;
SPI_Flash_Read((uint8_t *)&temp_config_info, FLASH_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
if (temp_config_info.start_Flag[0] == 'S'
&& temp_config_info.start_Flag[1] == 'L'
&& temp_config_info.end_Flag == 0x16) {
g_slConfigInfo = temp_config_info;
return 1;
}
else {
g_slConfigInfo.start_Flag[0] = defaultValue.start_Flag[0];
g_slConfigInfo.start_Flag[1] = defaultValue.start_Flag[1];
g_slConfigInfo.address[0] = defaultValue.address[0];
g_slConfigInfo.address[1] = defaultValue.address[1];
g_slConfigInfo.address[2] = defaultValue.address[2];
g_slConfigInfo.address[3] = defaultValue.address[3];
g_slConfigInfo.address[4] = defaultValue.address[4];
g_slConfigInfo.address[5] = defaultValue.address[5];
g_slConfigInfo.address[6] = defaultValue.address[6];
g_slConfigInfo.end_Flag = defaultValue.end_Flag;
}
return 0;
}
/**
* @brief 读取配置信息
* @param read_config_info1 读取的配置信息并保存在in_config_info中
* @retval 0 flash中读取配置失败使用默认配置
* 1 flash中读取配置成功
*/
uint8_t read_config_info1(config_info *in_config_info)
{
config_info temp_config_info;
SPI_Flash_Read((uint8_t *)&temp_config_info, FLASH_SAVE_ADDR_BEGIN, CONFIG_INFO_SIZE);
if (temp_config_info.start_Flag[0] == 'S'
&& temp_config_info.start_Flag[1] == 'L'
&& temp_config_info.end_Flag == 0x16) {
*in_config_info = temp_config_info;
return 1;
} else {
in_config_info->start_Flag[0] = defaultValue.start_Flag[0];
in_config_info->start_Flag[1] = defaultValue.start_Flag[1];
in_config_info->address[0] = defaultValue.address[0];
in_config_info->address[1] = defaultValue.address[1];
in_config_info->address[2] = defaultValue.address[2];
in_config_info->address[3] = defaultValue.address[3];
in_config_info->address[4] = defaultValue.address[4];
in_config_info->address[5] = defaultValue.address[5];
in_config_info->address[6] = defaultValue.address[6];
in_config_info->end_Flag = defaultValue.end_Flag;
}
return 0;
}