persistent_configuration: incapsulate crc calculation
This commit is contained in:
parent
11494cb665
commit
dc83659831
|
@ -9,9 +9,15 @@
|
||||||
|
|
||||||
#include "generated_lookup_engine_configuration.h"
|
#include "generated_lookup_engine_configuration.h"
|
||||||
|
|
||||||
|
#include "rusefi/crc.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int version;
|
int version;
|
||||||
int size;
|
int size;
|
||||||
persistent_config_s persistentConfiguration;
|
persistent_config_s persistentConfiguration;
|
||||||
uint32_t crc;
|
uint32_t crc;
|
||||||
|
|
||||||
|
uint32_t getCrc() {
|
||||||
|
return crc32(&persistentConfiguration, sizeof(persistent_config_s));
|
||||||
|
}
|
||||||
} persistent_config_container_s;
|
} persistent_config_container_s;
|
||||||
|
|
|
@ -63,10 +63,6 @@ extern const MFSConfig *boardGetMfsConfig(void);
|
||||||
* should be in a different sector of flash since complete flash sectors are erased on write.
|
* should be in a different sector of flash since complete flash sectors are erased on write.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static uint32_t flashStateCrc(const persistent_config_container_s& state) {
|
|
||||||
return crc32(&state.persistentConfiguration, sizeof(persistent_config_s));
|
|
||||||
}
|
|
||||||
|
|
||||||
#if (EFI_FLASH_WRITE_THREAD == TRUE)
|
#if (EFI_FLASH_WRITE_THREAD == TRUE)
|
||||||
chibios_rt::BinarySemaphore flashWriteSemaphore(/*taken =*/ true);
|
chibios_rt::BinarySemaphore flashWriteSemaphore(/*taken =*/ true);
|
||||||
|
|
||||||
|
@ -173,7 +169,7 @@ void writeToFlashNow() {
|
||||||
// Set up the container
|
// Set up the container
|
||||||
persistentState.size = sizeof(persistentState);
|
persistentState.size = sizeof(persistentState);
|
||||||
persistentState.version = FLASH_DATA_VERSION;
|
persistentState.version = FLASH_DATA_VERSION;
|
||||||
persistentState.crc = flashStateCrc(persistentState);
|
persistentState.crc = persistentState.getCrc();
|
||||||
|
|
||||||
// there's no wdgStop() for STM32, so we cannot disable it.
|
// there's no wdgStop() for STM32, so we cannot disable it.
|
||||||
// we just set a long timeout of 5 secs to wait until flash is done.
|
// we just set a long timeout of 5 secs to wait until flash is done.
|
||||||
|
@ -240,7 +236,7 @@ enum class FlashState {
|
||||||
};
|
};
|
||||||
|
|
||||||
static FlashState validatePersistentState() {
|
static FlashState validatePersistentState() {
|
||||||
auto flashCrc = flashStateCrc(persistentState);
|
auto flashCrc = persistentState.getCrc();
|
||||||
|
|
||||||
if (flashCrc != persistentState.crc) {
|
if (flashCrc != persistentState.crc) {
|
||||||
// If the stored crc is all 1s, that probably means the flash is actually blank, not that the crc failed.
|
// If the stored crc is all 1s, that probably means the flash is actually blank, not that the crc failed.
|
||||||
|
|
Loading…
Reference in New Issue