Обновление

This commit is contained in:
cfif 2025-10-29 11:17:05 +03:00
parent baf09ee366
commit 12283d586a
2 changed files with 59 additions and 30 deletions

View File

@ -8,6 +8,7 @@
#include "DataNonVolatile.h"
#include "StorageOnFlashFlagchip.h"
#include "SystemDelayInterface.h"
#include "HVAC_preDefine.h"
#define LOGGER env->logger
#define LOG_SIGN "Хран."
@ -21,44 +22,65 @@ void DeviceStorage_InitVariablesTable(tDeviceStorage *env) {
DeviceDataRuntime_InitDefaults(&env->runtime);
DeviceDataNonVolatile_AddToVarTab(env->nvm, &env->publicVariablesTable, VARIABLE_GROUP_FLASH);
DeviceDataNonVolatile_AddToVarTab(env->dataParam, &env->publicVariablesTable, VARIABLE_GROUP_FLASH);
DeviceDataRuntime_AddToVarTab(&env->runtime, &env->publicVariablesTable, VARIABLE_GROUP_UNTRACKED);
}
bool DeviceStorage_LoadNonVolatile(tDeviceStorage *env) {
bool DeviceStorage_LoadParam(tDeviceStorage *env) {
bool isLoad = VarsTabDumpObserver_Load(&env->dumpObserver);
bool isLoad = VarsTabDumpObserverParam_Load(&env->dumpObserver);
if (isLoad) {
if (env->nvm->version == DEVICE_DATA_NO_VOLATILE_VERSION) {
if (env->dataParam->version == DEVICE_DATA_NO_VOLATILE_VERSION) {
return true;
}
}
LoggerInfoStatic(LOGGER, LOG_SIGN, "Сброс настроек");
LoggerInfoStatic(LOGGER, LOG_SIGN, "Параметры. Сброс настроек");
DeviceDataNonVolatile_InitDefaults(env->nvm);
DeviceDataParam_InitDefaults(env->dataParam);
return VarsTabDumpObserver_Dump(&env->dumpObserver);
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) {
VarsTabDumpObserver_Dump(&env->dumpObserver);
VarsTabDumpObserverParam_Dump(&env->dumpObserver);
}
void DeviceStorage_DelayedDump(tDeviceStorage *env) {
env->publicVariablesTable.changes = 1;
}
void DeviceStorage_InitCommon(tDeviceStorage *env, tStorageInterface *storageInterface) {
void DeviceStorage_InitCommon(tDeviceStorage *env, tStorageInterface *storageCalibInterface, size_t sizeCalib,
tStorageInterface *storageParamInterface, size_t sizeParam ) {
VarsTabDumpObserver_Init(
&env->dumpObserver,
storageInterface,
storageCalibInterface,
storageParamInterface,
5000,
env->nvm,
// sizeof(env->nvm),
16000,
env->dataCalib,
env->dataParam,
sizeCalib,
sizeParam,
&env->publicVariablesTable,
VARIABLE_GROUP_FLASH
);
@ -68,16 +90,22 @@ void DeviceStorage_InitCommon(tDeviceStorage *env, tStorageInterface *storageInt
}
void DeviceStorage_InitDefaults(tDeviceStorage *env) {
DeviceStorage_InitCommon(env, NULL);
DeviceDataNonVolatile_InitDefaults(env->nvm);
}
uint8_t dataReservedStore[16000];
bool DeviceStorage_Init(tDeviceStorage *env, tStorageInterface *storageInterface) {
env->nvm = (tDeviceDataNonVolatile *) dataReservedStore;
DeviceStorage_InitCommon(env, storageInterface);
return DeviceStorage_LoadNonVolatile(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;
}

View File

@ -17,20 +17,21 @@
typedef struct {
tLoggerInterface *logger;
tDeviceDataRuntime runtime;
tDeviceDataNonVolatile *nvm;
tDeviceDataNonVolatile *dataParam;
void *dataCalib;
tVariablesTable publicVariablesTable;
tVarsTabDumpObserver dumpObserver;
struct {
tVariableDescriptor vartab[50];
} mem;
} tDeviceStorage;
bool DeviceStorage_Init(tDeviceStorage *env, tStorageInterface *storageInterface);
void DeviceStorage_InitDefaults(tDeviceStorage *env);
bool DeviceStorage_Init(tDeviceStorage *env, tStorageInterface *storageCalibInterface, tStorageInterface *storageParamInterface);
void DeviceStorage_ForceDump(tDeviceStorage *env);
void DeviceStorage_DelayedDump(tDeviceStorage *env);