void readFromFlash(void) { efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "read f"); printMsg(logger, "readFromFlash()"); flashRead(FLASH_ADDR, (char *) &persistentState, PERSISTENT_SIZE); persisted_configuration_state_e result; if (!isValidCrc(&persistentState)) { result = CRC_FAILED; resetConfigurationExt(logger, DEFAULT_ENGINE_TYPE PASS_ENGINE_PARAMETER); } else if (persistentState.version != FLASH_DATA_VERSION || persistentState.size != PERSISTENT_SIZE) { result = INCOMPATIBLE_VERSION; resetConfigurationExt(logger, engineConfiguration->engineType PASS_ENGINE_PARAMETER); } else { /** * At this point we know that CRC and version number is what we expect. Safe to assume it's a valid configuration. */ result = OK; applyNonPersistentConfiguration(logger PASS_ENGINE_PARAMETER); } // we can only change the state after the CRC check engineConfiguration->firmwareVersion = getRusEfiVersion(); if (result == CRC_FAILED) { printMsg(logger, "Need to reset flash to default due to CRC"); } else if (result == INCOMPATIBLE_VERSION) { printMsg(logger, "Resetting but saving engine type [%d]", engineConfiguration->engineType); } else { printMsg(logger, "Got valid configuration from flash!"); } }
static void readFromFlash(void) { flashRead(FLASH_ADDR, (char *) &flashState, FLASH_USAGE); setDefaultNonPersistentConfiguration(engineConfiguration2); if (!isValidCrc(&flashState)) { scheduleMsg(&logger, "Need to reset flash to default"); resetConfigurationExt(defaultEngineType, engineConfiguration, engineConfiguration2, boardConfiguration); } else { scheduleMsg(&logger, "Got valid configuration from flash!"); applyNonPersistentConfiguration(engineConfiguration, engineConfiguration2, engineConfiguration->engineType); } // we can only change the state after the CRC check engineConfiguration->firmwareVersion = getRusEfiVersion(); }
void readFromFlash(void) { printMsg(&logger, "readFromFlash()"); flashRead(FLASH_ADDR, (char *) &persistentState, PERSISTENT_SIZE); //setDefaultNonPersistentConfiguration(engineConfiguration2); if (!isValidCrc(&persistentState) || persistentState.size != PERSISTENT_SIZE) { printMsg(&logger, "Need to reset flash to default"); resetConfigurationExt(&logger, defaultEngineType, engineConfiguration, engineConfiguration2, boardConfiguration); } else { printMsg(&logger, "Got valid configuration from flash!"); applyNonPersistentConfiguration(&logger, engineConfiguration, engineConfiguration2); } // we can only change the state after the CRC check engineConfiguration->firmwareVersion = getRusEfiVersion(); }
/** * this method could and should be executed before we have any * connectivity so no console output here */ persisted_configuration_state_e readConfiguration(Logging * logger) { efiAssert(getRemainingStack(chThdSelf()) > 256, "read f", PC_ERROR); flashRead(FLASH_ADDR, (char *) &persistentState, PERSISTENT_SIZE); persisted_configuration_state_e result; if (!isValidCrc(&persistentState)) { result = CRC_FAILED; warning(CUSTOM_ERR_FLASH_CRC_FAILED, "flash CRC failed"); resetConfigurationExt(logger, DEFAULT_ENGINE_TYPE PASS_ENGINE_PARAMETER); } else if (persistentState.version != FLASH_DATA_VERSION || persistentState.size != PERSISTENT_SIZE) { result = INCOMPATIBLE_VERSION; resetConfigurationExt(logger, engineConfiguration->engineType PASS_ENGINE_PARAMETER); } else { /** * At this point we know that CRC and version number is what we expect. Safe to assume it's a valid configuration. */ result = OK; applyNonPersistentConfiguration(logger PASS_ENGINE_PARAMETER); } // we can only change the state after the CRC check engineConfiguration->byFirmwareVersion = getRusEfiVersion(); return result; }