rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Data Structures | Enumerations | Functions
storage.h File Reference

Detailed Description

Date
Jan 4, 2025
Author
Andrey Gusakov

Definition in file storage.h.

Data Structures

class  SettingStorageBase
 

Enumerations

enum class  StorageStatus {
  Ok , CrcFailed , IncompatibleVersion , NotSupported ,
  NotFound , Failed
}
 
enum  StorageType {
  STORAGE_INT_FLASH = 0 , STORAGE_MFS_INT_FLASH = 1 , STORAGE_MFS_EXT_FLASH = 2 , STORAGE_SD_CARD = 3 ,
  STORAGE_TOTAL
}
 
enum  StorageItemId { EFI_SETTINGS_RECORD_ID = 1 , EFI_SETTINGS_BACKUP_RECORD_ID = 2 , EFI_LTFT_RECORD_ID = 3 , EFI_STORAGE_TOTAL_ITEMS }
 

Functions

bool storageAllowWriteID (StorageItemId id)
 
StorageStatus storageWrite (StorageItemId id, const uint8_t *ptr, size_t size)
 
StorageStatus storageRead (StorageItemId id, uint8_t *ptr, size_t size)
 
bool storageRequestWriteID (StorageItemId id, bool forced)
 
bool storageReqestReadID (StorageItemId id)
 
bool storageRegisterStorage (StorageType type, SettingStorageBase *storage)
 
bool storageUnregisterStorage (StorageType type)
 
bool storageIsStorageRegistered (StorageType type)
 
bool storagRequestRegisterStorage (StorageType id)
 
bool storagRequestUnregisterStorage (StorageType id)
 
bool getNeedToWriteConfiguration ()
 
void initStorage ()
 

Enumeration Type Documentation

◆ StorageItemId

Enumerator
EFI_SETTINGS_RECORD_ID 
EFI_SETTINGS_BACKUP_RECORD_ID 
EFI_LTFT_RECORD_ID 
EFI_STORAGE_TOTAL_ITEMS 

Definition at line 47 of file storage.h.

47 {
48 /* 0 is reserved due to MFS limitation */
52
54};
@ EFI_SETTINGS_BACKUP_RECORD_ID
Definition storage.h:50
@ EFI_LTFT_RECORD_ID
Definition storage.h:51
@ EFI_STORAGE_TOTAL_ITEMS
Definition storage.h:53
@ EFI_SETTINGS_RECORD_ID
Definition storage.h:49

◆ StorageStatus

enum class StorageStatus
strong
Enumerator
Ok 
CrcFailed 
IncompatibleVersion 
NotSupported 
NotFound 
Failed 

Definition at line 12 of file storage.h.

12 {
13 Ok,
17 // all is well, but we're on a fresh chip with blank memory
19 // Write failed
20 Failed
21};

◆ StorageType

Enumerator
STORAGE_INT_FLASH 
STORAGE_MFS_INT_FLASH 
STORAGE_MFS_EXT_FLASH 
STORAGE_SD_CARD 
STORAGE_TOTAL 

Definition at line 37 of file storage.h.

37 {
42
44};
@ STORAGE_INT_FLASH
Definition storage.h:38
@ STORAGE_TOTAL
Definition storage.h:43
@ STORAGE_SD_CARD
Definition storage.h:41
@ STORAGE_MFS_EXT_FLASH
Definition storage.h:40
@ STORAGE_MFS_INT_FLASH
Definition storage.h:39

Function Documentation

◆ getNeedToWriteConfiguration()

bool getNeedToWriteConfiguration ( )
Returns
true if an persistentState write is pending

Definition at line 353 of file storage.cpp.

353 {
354 return (pendingWrites & BIT(EFI_SETTINGS_RECORD_ID)) != 0;
355}
static uint32_t pendingWrites
Definition storage.cpp:248

Referenced by updateFlags().

Here is the caller graph for this function:

◆ initStorage()

void initStorage ( )

Definition at line 357 of file storage.cpp.

357 {
358 bool settingsStorageReady = false;
359 // may be unused
360 (void)settingsStorageReady;
361
362#if EFI_STORAGE_INT_FLASH == TRUE
363 settingsStorageReady = initStorageFlash();
364#endif // EFI_STORAGE_INT_FLASH
365
366#if EFI_STORAGE_MFS == TRUE
367 if (settingsStorageReady) {
368 // Skip MFS if internal storage is used for persistentState
369 // Init of MFS may take significant time, lets postpone it until storage manager thread
371 } else {
372 // Set long timeout to watchdog as this code is called before any thread is started
373 // and no one is feeding watchdog
374 startWatchdog(WATCHDOG_MFS_START_TIMEOUT_MS);
375
377
378 // restart the watchdog with the default timeout
380 }
381#endif // EFI_STORAGE_MFS
382
383 chThdCreateStatic(storageManagerThreadStack, sizeof(storageManagerThreadStack), PRIO_STORAGE_MANAGER, storageManagerThread, nullptr);
384}
void startWatchdog(int)
static void storageManagerThread(void *)
Definition storage.cpp:258
bool storagRequestRegisterStorage(StorageType id)
Definition storage.cpp:238
bool initStorageFlash()
bool initStorageMfs()

Referenced by initFlash().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ storageAllowWriteID()

bool storageAllowWriteID ( StorageItemId  id)

Definition at line 19 of file storage.cpp.

20{
21#if (EFI_STORAGE_INT_FLASH == TRUE) || defined(EFI_UNIT_TEST)
22 if ((id == EFI_SETTINGS_RECORD_ID) ||
24 // special case, settings can be stored in internal flash
25
26 // writing internal flash can cause cpu freeze
27 // check if HW support flash writing while executing
29 return true;
30 }
31
32#if EFI_SHAFT_POSITION_INPUT
33 // MCU does not support write while executing, check if engine is stopped
35 return true;
36 } else {
37 // rusEfi usually runs on hardware which halts execution while writing to internal flash, so we
38 // postpone writes to until engine is stopped. Writes in case of self-stimulation are fine.
39 return false;
40 }
41#endif // EFI_SHAFT_POSITION_INPUT
42 }
43#endif // EFI_STORAGE_INT_FLASH
44
45 // TODO: we expect every other ID to be stored in external flash...
46 return true;
47}
bool mcuCanFlashWhileRunning()
Definition mpu_util.cpp:10
TriggerCentral triggerCentral
Definition engine.h:318
RpmCalculator rpmCalculator
Definition engine.h:306
bool isStopped() const override
static EngineAccessor engine
Definition engine.h:413

Referenced by storageManagerThread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ storageIsStorageRegistered()

bool storageIsStorageRegistered ( StorageType  type)

Definition at line 230 of file storage.cpp.

230 {
231 if (type >= STORAGE_TOTAL) {
232 return false;
233 }
234
235 return (storages[type] != nullptr);
236}
static SettingStorageBase * storages[storagesCount]
Definition storage.cpp:69

Referenced by hellenDisableEn(), storageRegisterStorage(), and storageUnregisterStorage().

Here is the caller graph for this function:

◆ storageRead()

StorageStatus storageRead ( StorageItemId  id,
uint8_t *  ptr,
size_t  size 
)

Definition at line 160 of file storage.cpp.

160 {
161 bool success = false;
163
164 for_all_storages {
165 if ((!storage->isReady()) || (!storage->isIdSupported(id))) {
166 continue;
167 }
168
169 status = storage->read(id, ptr, size);
170 if (status == StorageStatus::Ok) {
171 success = true;
172 }
173 }
174
175 return (success ? StorageStatus::Ok : status);
176}
StorageStatus
Definition storage.h:12
composite packet size

Referenced by LtftState::load(), and readConfiguration().

Here is the caller graph for this function:

◆ storageRegisterStorage()

bool storageRegisterStorage ( StorageType  type,
SettingStorageBase storage 
)

Definition at line 194 of file storage.cpp.

194 {
195 if (type >= STORAGE_TOTAL) {
196 return false;
197 }
198
199 if (storageIsStorageRegistered(type)) {
200 /* already registered */
201 efiPrintf("Trying to register already exist storage %s", storageTypeToName(type));
202 return false;
203 }
204
205 storages[type] = storage;
206 efiPrintf("Storage %s registered", storageTypeToName(type));
207
208 storageManagerSendCmd(MSG_CMD_PING, 0);
209
210 return true;
211}
static const char * storageTypeToName(StorageType type)
Definition storage.cpp:111
bool storageIsStorageRegistered(StorageType type)
Definition storage.cpp:230
static bool storageManagerSendCmd(uint32_t cmd, uint32_t arg)
Definition storage.cpp:178

Referenced by initStorageFlash(), initStorageMfs(), and initStorageSD().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ storageReqestReadID()

bool storageReqestReadID ( StorageItemId  id)

Definition at line 190 of file storage.cpp.

190 {
191 return storageManagerSendCmd(MSG_CMD_READ, (uint32_t)id);
192}

Referenced by LtftState::load().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ storageRequestWriteID()

bool storageRequestWriteID ( StorageItemId  id,
bool  forced 
)

Definition at line 186 of file storage.cpp.

186 {
187 return storageManagerSendCmd(forced ? MSG_CMD_WRITE_NOW : MSG_CMD_WRITE, (uint32_t)id);
188}

Referenced by setNeedToWriteConfiguration(), settingsLtftRequestWriteToFlash(), and writeToFlashNow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ storageUnregisterStorage()

bool storageUnregisterStorage ( StorageType  type)

Definition at line 213 of file storage.cpp.

213 {
214 if (type >= STORAGE_TOTAL) {
215 return false;
216 }
217
218 if (!storageIsStorageRegistered(type)) {
219 /* already unregistered */
220 efiPrintf("Trying to unregister non-exist storage %s", storageTypeToName(type));
221 return false;
222 }
223
224 storages[type] = nullptr;
225 efiPrintf("Storage %s unregistered", storageTypeToName(type));
226
227 return true;
228}

Referenced by deinitStorageSD(), and storageManagerThread().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ storageWrite()

StorageStatus storageWrite ( StorageItemId  id,
const uint8_t *  ptr,
size_t  size 
)

Definition at line 142 of file storage.cpp.

142 {
143 bool success = false;
145
146 for_all_storages {
147 if ((!storage->isReady()) || (!storage->isIdSupported(id))) {
148 continue;
149 }
150
151 status = storage->store(id, ptr, size);
152 if (status == StorageStatus::Ok) {
153 success = true;
154 }
155 }
156
157 return (success ? StorageStatus::Ok : status);
158}

Referenced by LtftState::save(), and writeToFlashNowImpl().

Here is the caller graph for this function:

◆ storagRequestRegisterStorage()

bool storagRequestRegisterStorage ( StorageType  id)

Definition at line 238 of file storage.cpp.

239{
240 return storageManagerSendCmd(MSG_CMD_REG, (uint32_t)id);
241}

Referenced by hellenEnableEn(), and initStorage().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ storagRequestUnregisterStorage()

bool storagRequestUnregisterStorage ( StorageType  id)

Definition at line 243 of file storage.cpp.

244{
245 return storageManagerSendCmd(MSG_CMD_UNREG, (uint32_t)id);
246}

Referenced by hellenDisableEn().

Here is the call graph for this function:
Here is the caller graph for this function:

Go to the source code of this file.