// // Created by cfif on 07.10.22. // #include #include #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 "Storage" #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_param == DEVICE_DATA_VERSION_PARAM) { LoggerInfoStatic(LOGGER, LOG_SIGN, "Parameters loaded successfully"); return true; } } LoggerInfoStatic(LOGGER, LOG_SIGN, "Parameters: Reset settings"); 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_calib == DEVICE_DATA_VERSION_CALIB) { LoggerInfoStatic(LOGGER, LOG_SIGN, "Calibrations loaded successfully"); return true; } } LoggerInfoStatic(LOGGER, LOG_SIGN, "Calibrations: Reset settings"); DeviceDataCalib_InitDefaults(env->dataParam); bool resultParam = VarsTabDumpObserverParam_Dump(&env->dumpObserver); bool resultCalib = VarsTabDumpObserverCalib_Dump(&env->dumpObserver); if ((resultParam) || (resultCalib)) { return true; } return false; } void DeviceStorageCalib_ForceDump(tDeviceStorage *env) { VarsTabDumpObserverCalib_Dump(&env->dumpObserver); } void DeviceStorageParam_ForceDump(tDeviceStorage *env) { VarsTabDumpObserverParam_Dump(&env->dumpObserver); } void DeviceStorageParam_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 + 4; DeviceStorage_InitCommon(env, storageCalibInterface, nf_storage_calib_size, storageParamInterface, nf_storage_param_size); bool resultParam = DeviceStorage_LoadParam(env); bool resultCalib = DeviceStorage_LoadCalib(env); if ((resultParam) && (resultCalib)) { return true; } return false; }