chargeController/APP/businessLogic/Src/task.c

213 lines
4.5 KiB
C
Raw Normal View History

#include "task.h"
#include "inFlash.h"
#include "parameter.h"
#include "FM_GPIO.h"
#include "chargControlEnum.h"
#include "bl_chargControl.h"
/**
* @brief
* @param None
* @retval None
*
*/
void task_Init(void)
{
TimeSliceOffset_Register(&m_runled, Task_Runled, runled_reloadVal, runled_offset);
TimeSliceOffset_Register(&m_wdi, Task_wdi, wdi_reloadVal, wdi_offset);
}
/**
* @brief
* @param None
* @retval None
*
*/
STR_TimeSliceOffset m_runled;
void Task_Runled(void)
{
RUN_LED();
}
/**
* @brief
* @param None
* @retval None
*/
STR_TimeSliceOffset m_wdi;
void Task_wdi(void)
{
/* 每天复位一次复位前将电量信息写入flash中 */
static uint32_t temp = 60 * 60 * 24;
if (!(--temp)) {
temp = 0;
float tempF;
tempF = getTotalElectricityConsumption();
savetotalElectricityConsumption(&tempF);
tempF = getTotalChargCapacity();
savetotalChargCapacity(&tempF);
NVIC_SystemReset();
}
feedDog();
}
/**
* @brief
* @param None
* @retval None
*
*/
STR_TimeSliceOffset m_refreshJudgeData;
void Task_refreshJudgeData(void)
{
/* 获取数据 */
setInputVoltage();
setHighSideMosTemperature();
/* 判断有无电池 */
if (getBatteryState() == FALSE && (getChargBatteryCurrent() > 1 || getChargBatteryCurrent() < -1)
&& getOutputVoltage() < 14.2f) {
setBatteryState(TRUE);
}
/* 温度检测 */
if () {
}
}
/**
* @brief
*
*
*
* @param None
* @retval None
*
*/
STR_TimeSliceOffset g_startControl;
void Task_startControl(void)
{
if (getSolarInCircuitVoltage() > g_cfgParameter.startSolarOpenCircuitV) {
TimeSliceOffset_Unregister(&g_startControl);
g_startControl.runFlag = 0;
if (getOutputVoltage() > 10) {
setBatteryState(TRUE);
} else {
setBatteryState(FALSE);
}
TimeSliceOffset_Register(&m_softStart, Task_softStart, softStart_reloadVal, softStart_offset);
}
}
/**
* @brief
* @param
* @retval
*
*/
STR_TimeSliceOffset m_softStart;
void Task_softStart(void)
{
static uint16_t num = 0;
static float dutyRatio = 0;
num++;
if (num < 5) {
set_pwmPulse(100);
}
else if (num > 70 || dutyRatio > 0.75f) {
TimeSliceOffset_Unregister(&m_softStart);
m_softStart.runFlag = 0;
dutyRatio = 0;
num = 0;
setDutyRatio(0.75);
set_pwmDutyRatio(getDutyRatio());
if (getBatteryState() == TRUE) {
setMPPT_Mode(MPPT);
} else {
setMPPT_Mode(floatCharg);
}
setChargControlFlag(TRUE);
}
else {
setDutyRatio(getDutyRatio() + 0.05f);
set_pwmDutyRatio(getDutyRatio());
}
}
/**
* @brief
* @param
* @retval
*/
STR_TimeSliceOffset m_impedanceCalculation;
void Task_impedanceCalculation(void)
{
static uint8_t num = 0;
static float currOne = 0;
static float voltOne = 0;
static float currTwo = 0;
static float voltTwo = 0;
num++;
if (num == 1) {
setChargControlFlag(FALSE);
setDutyRatio(0.7);
set_pwmDutyRatio(getDutyRatio());
return;
}
if (num == 11) {
currOne = getChargCurrent() - getDischargCurrent();
voltOne = getOutputVoltage();
setDutyRatio(0.85);
set_pwmDutyRatio(getDutyRatio());
return;
}
if (num == 21) {
TimeSliceOffset_Unregister(&m_impedanceCalculation);
m_impedanceCalculation.runFlag = 0;
currTwo = getChargCurrent() - getDischargCurrent();
voltTwo = getOutputVoltage();
float tempLoopImpedance = 0;
tempLoopImpedance = (voltOne - voltTwo) / (currOne - currTwo);
/* 判断回路阻抗是否合理 */
if (tempLoopImpedance < 1.0f && tempLoopImpedance > 0.05f) {
g_cfgParameter.loopImpedance = tempLoopImpedance;
saveLoopImpedance(&g_cfgParameter.loopImpedance);
}
num = 0;
setMPPT_Mode(MPPT);
setChargControlFlag(TRUE);
return;
}
}