HVAC_M7_DeviceStorage/DeviceStorage.c

115 lines
3.1 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.

//
// Created by cfif on 07.10.22.
//
#include <CmsisRtosThreadUtils.h>
#include <memory.h>
#include "DeviceStorage.h"
#include "DataNonVolatile.h"
#include "StorageOnFlashFlagchip.h"
#include "SystemDelayInterface.h"
#include "HVAC_preDefine.h"
#include "StorageOnFlash.h"
#define LOGGER env->logger
#define LOG_SIGN "Хран."
#define VARIABLE_GROUP_UNTRACKED 0
#define VARIABLE_GROUP_FLASH (1 << 0)
void DeviceStorage_InitVariablesTable(tDeviceStorage *env) {
env->trackableVarsTab = 0;
DeviceDataRuntime_InitDefaults(&env->runtime);
}
bool DeviceStorage_LoadParam(tDeviceStorage *env) {
bool isLoad = VarsTabDumpObserverParam_Load(&env->dumpObserver);
if (isLoad) {
if (env->dataParam->version == DEVICE_DATA_NO_VOLATILE_VERSION) {
LoggerInfoStatic(LOGGER, LOG_SIGN, "Параметры. Загружены успешно");
return true;
}
}
LoggerInfoStatic(LOGGER, LOG_SIGN, "Параметры. Сброс настроек");
DeviceDataParam_InitDefaults(env->dataParam);
return VarsTabDumpObserverParam_Dump(&env->dumpObserver);
}
bool DeviceStorage_LoadCalib(tDeviceStorage *env) {
bool isLoad = VarsTabDumpObserverCalib_Load(&env->dumpObserver);
if (isLoad) {
LoggerInfoStatic(LOGGER, LOG_SIGN, "Калибровки. Загружены успешно");
return true;
}
LoggerInfoStatic(LOGGER, LOG_SIGN, "Калибровки. Сброс настроек");
DeviceDataCalib_InitDefaults(env->dataCalib);
return VarsTabDumpObserverCalib_Dump(&env->dumpObserver);
}
void DeviceStorage_ForceDump(tDeviceStorage *env) {
VarsTabDumpObserverParam_Dump(&env->dumpObserver);
}
void DeviceStorage_DelayedDump(tDeviceStorage *env) {
env->trackableVarsTab = 1;
}
void DeviceStorage_InitCommon(tDeviceStorage *env, tStorageInterface *storageCalibInterface, size_t sizeCalib,
tStorageInterface *storageParamInterface, size_t sizeParam) {
VarsTabDumpObserver_Init(
&env->dumpObserver,
storageCalibInterface,
storageParamInterface,
5000,
env->dataCalib,
env->dataParam,
sizeCalib,
sizeParam,
&env->trackableVarsTab,
VARIABLE_GROUP_FLASH,
env->logger
);
DeviceStorage_InitVariablesTable(env);
}
SECT_SRAM_NVM uint8_t dataReservedParamStore[nf_storage_param_size];
bool DeviceStorage_Init(tDeviceStorage *env, tStorageInterface *storageCalibInterface,
tStorageInterface *storageParamInterface,
tLoggerInterface *logger) {
extern uint32_t __itcm_start[];
env->logger = logger;
env->dataParam = (tDeviceDataNonVolatile *) dataReservedParamStore;
env->dataCalib = (void *) __itcm_start;
DeviceStorage_InitCommon(env, storageParamInterface, nf_storage_param_size,
storageCalibInterface, nf_storage_calib_size);
bool resultParam = DeviceStorage_LoadParam(env);
bool resultCalib = DeviceStorage_LoadCalib(env);
if ((resultParam) && (resultCalib)) {
return true;
}
return false;
}