HVAC_M7_DeviceStorage/DeviceStorage.c

112 lines
3.2 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"
#define LOGGER env->logger
#define LOG_SIGN "Хран."
#define VARIABLE_GROUP_UNTRACKED 0
#define VARIABLE_GROUP_FLASH (1 << 0)
void DeviceStorage_InitVariablesTable(tDeviceStorage *env) {
VariablesTableInitStatic(&env->publicVariablesTable, env->mem.vartab);
DeviceDataRuntime_InitDefaults(&env->runtime);
DeviceDataNonVolatile_AddToVarTab(env->dataParam, &env->publicVariablesTable, VARIABLE_GROUP_FLASH);
DeviceDataRuntime_AddToVarTab(&env->runtime, &env->publicVariablesTable, VARIABLE_GROUP_UNTRACKED);
}
bool DeviceStorage_LoadParam(tDeviceStorage *env) {
bool isLoad = VarsTabDumpObserverParam_Load(&env->dumpObserver);
if (isLoad) {
if (env->dataParam->version == DEVICE_DATA_NO_VOLATILE_VERSION) {
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) {
if (env->dataParam->version == DEVICE_DATA_NO_VOLATILE_VERSION) {
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->publicVariablesTable.changes = 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->publicVariablesTable,
VARIABLE_GROUP_FLASH
);
DeviceStorage_InitVariablesTable(env);
}
SECT_SRAM_NVM uint8_t dataReservedParamStore[2 * FLASH_PAGE_SIZE];
extern uint32_t __caldata_start[];
bool DeviceStorage_Init(tDeviceStorage *env, tStorageInterface *storageCalibInterface, tStorageInterface *storageParamInterface) {
env->dataParam = (tDeviceDataNonVolatile *) dataReservedParamStore;
env->dataCalib = (void *)__caldata_start;
DeviceStorage_InitCommon(env, storageParamInterface, sizeof(dataReservedParamStore),
storageCalibInterface, 7 * FLASH_PAGE_SIZE);
bool resultParam = DeviceStorage_LoadParam(env);
bool resultCalib = DeviceStorage_LoadCalib(env);
if ((resultParam) && (resultCalib)) {
return true;
}
return false;
}