rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Functions
flash_main.h File Reference

Detailed Description

Date
Sep 19, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file flash_main.h.

Functions

void readFromFlash ()
 
void initFlash ()
 
void writeToFlashNow ()
 
bool writeToFlashNowImpl ()
 
void setNeedToWriteConfiguration ()
 
bool settingsLtftRequestWriteToFlash ()
 
bool flashAllowWriteID (uint32_t id)
 

Function Documentation

◆ flashAllowWriteID()

bool flashAllowWriteID ( uint32_t  id)

◆ initFlash()

void initFlash ( )

This would write NOW (you should not be doing this while connected to real engine)

This would schedule write to flash once the engine is stopped

Definition at line 163 of file flash_main.cpp.

163 {
164 // Init storage(s) if any
165 // Note: may take some time
166 initStorage();
167
168 addConsoleAction("readconfig", readFromFlash);
169 /**
170 * This would write NOW (you should not be doing this while connected to real engine)
171 */
173
174 addConsoleAction("ltftwrite", doWriteLTFT);
175#if EFI_TUNER_STUDIO
176 /**
177 * This would schedule write to flash once the engine is stopped
178 */
179 addConsoleAction(CMD_BURNCONFIG, requestBurn);
180#endif
182 addConsoleAction("rewriteconfig", doRewriteConfig);
183}
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
static void doWriteLTFT()
static void doRewriteConfig()
static void doResetConfiguration()
void readFromFlash()
static void doWriteConfigurationToFlash()
void initStorage()
Definition storage.cpp:357
void requestBurn()

Referenced by initHardwareNoConfig().

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

◆ readFromFlash()

void readFromFlash ( )

Definition at line 114 of file flash_main.cpp.

114 {
116
117 switch (result) {
120 efiPrintf("Need to reset flash to default due to CRC mismatch");
121 [[fallthrough]];
125 resetConfigurationExt(DEFAULT_ENGINE_TYPE);
126 break;
128 // Preserve engine type from old config
129 efiPrintf("Resetting due to version mismatch but preserving engine type [%d]", (int)engineConfiguration->engineType);
131 break;
133 // At this point we know that CRC and version number is what we expect. Safe to assume it's a valid configuration.
135 efiPrintf("Read valid configuration from flash!");
136 break;
137 }
138
139 // we can only change the state after the CRC check
142}
void preCalculate()
Definition engine.cpp:324
static EngineAccessor engine
Definition engine.h:413
void applyNonPersistentConfiguration()
void resetConfigurationExt(configuration_callback_t boardCallback, engine_type_e engineType)
static constexpr engine_configuration_s * engineConfiguration
bool warning(ObdCode code, const char *fmt,...)
int getRusEfiVersion()
static StorageStatus readConfiguration()
@ CUSTOM_ERR_FLASH_CRC_FAILED
StorageStatus
Definition storage.h:12

Referenced by initFlash(), and loadConfiguration().

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

◆ setNeedToWriteConfiguration()

void setNeedToWriteConfiguration ( )

Definition at line 43 of file flash_main.cpp.

43 {
44 efiPrintf("Scheduling write");
45
47}
bool storageRequestWriteID(StorageItemId id, bool forced)
Definition storage.cpp:186
@ EFI_SETTINGS_RECORD_ID
Definition storage.h:49

Referenced by LongTermIdleTrim::checkIfShouldSave(), and requestBurn().

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

◆ settingsLtftRequestWriteToFlash()

bool settingsLtftRequestWriteToFlash ( )

Definition at line 49 of file flash_main.cpp.

49 {
51}
@ EFI_LTFT_RECORD_ID
Definition storage.h:51

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

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

◆ writeToFlashNow()

void writeToFlashNow ( )

Because of hardware-related issues, some stm32f4/7 chips are totally frozen while we are writing to internal flash. Writing the configuration takes about 1-2 seconds, we cannot afford to do that while the engine is running so we postpone the write until the engine is stopped.

Definition at line 37 of file flash_main.cpp.

37 {
38 efiPrintf("Scheduling FORCED write");
39
41}

Referenced by doRewriteConfig(), doWriteConfigurationToFlash(), handleCommandX14(), loadConfiguration(), and setEngineType().

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

◆ writeToFlashNowImpl()

bool writeToFlashNowImpl ( )

Definition at line 54 of file flash_main.cpp.

54 {
55 engine->configBurnTimer.reset();
56
57 // Set up the container
59 persistentState.version = FLASH_DATA_VERSION;
61
62 // Do actual write
63 auto result1 = storageWrite(EFI_SETTINGS_RECORD_ID, (uint8_t *)&persistentState, sizeof(persistentState));
65
67
68 return ((result1 == StorageStatus::Ok) && (result2 == StorageStatus::Ok));
69}
Timer configBurnTimer
Definition engine.h:308
persistent_config_container_s persistentState
void resetMaxValues()
StorageStatus storageWrite(StorageItemId id, const uint8_t *ptr, size_t size)
Definition storage.cpp:142
@ EFI_SETTINGS_BACKUP_RECORD_ID
Definition storage.h:50

Referenced by storageWriteID().

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

Go to the source code of this file.