diff --git a/firmware/config/engines/honda_accord.cpp b/firmware/config/engines/honda_accord.cpp index a7daa7d86b..4d6bf2e630 100644 --- a/firmware/config/engines/honda_accord.cpp +++ b/firmware/config/engines/honda_accord.cpp @@ -187,7 +187,7 @@ void setHondaAccordConfigurationThreeWires(DECLARE_ENGINE_PARAMETER_F) { void setHondaAccordConfigurationDip(DECLARE_ENGINE_PARAMETER_F) { engineConfiguration->engineType = HONDA_ACCORD_CD_DIP; - engineConfiguration->trigger.type = TT_HONDA_ACCORD_CD_DIP; + engineConfiguration->trigger.type = TT_HONDA_1_4_24; setHondaAccordConfigurationCommon(PASS_ENGINE_PARAMETER_F); } diff --git a/firmware/controllers/algo/auto_generated_enums.cpp b/firmware/controllers/algo/auto_generated_enums.cpp index e8992600f8..d81c60770a 100644 --- a/firmware/controllers/algo/auto_generated_enums.cpp +++ b/firmware/controllers/algo/auto_generated_enums.cpp @@ -167,8 +167,8 @@ case TT_DODGE_STRATUS: return "TT_DODGE_STRATUS"; case TT_36_2_2_2: return "TT_36_2_2_2"; -case TT_HONDA_ACCORD_CD_DIP: - return "TT_HONDA_ACCORD_CD_DIP"; +case TT_HONDA_1_4_24: + return "TT_HONDA_1_4_24"; case TT_HONDA_4_24: return "TT_HONDA_4_24"; case TT_MAZDA_MIATA_NA: diff --git a/firmware/controllers/algo/rusefi_enums.h b/firmware/controllers/algo/rusefi_enums.h index 24b45846fc..fa8f5809ba 100644 --- a/firmware/controllers/algo/rusefi_enums.h +++ b/firmware/controllers/algo/rusefi_enums.h @@ -167,7 +167,7 @@ typedef enum { // this makes sense because mechanical spark distribution does not require synchronization TT_HONDA_4_24 = 12, - TT_HONDA_ACCORD_CD_DIP = 13, + TT_HONDA_1_4_24 = 13, // cam-based TT_DODGE_NEON_2003_CAM = 14, diff --git a/firmware/controllers/flash_main.cpp b/firmware/controllers/flash_main.cpp index b362c8a0d7..7c7d86a6b8 100644 --- a/firmware/controllers/flash_main.cpp +++ b/firmware/controllers/flash_main.cpp @@ -40,6 +40,14 @@ extern engine_configuration_s *engineConfiguration; #define PERSISTENT_SIZE sizeof(persistent_config_container_s) +/** + * https://sourceforge.net/p/rusefi/tickets/335/ + * + * Address of second cofig copy, rounded to 4K. 4K is the page size is it? + * + */ +#define FLASH_ADDR_SECOND_COPY (FLASH_ADDR + ((PERSISTENT_SIZE + 4095) & 0xFFFFF000)) + crc_t flashStateCrc(persistent_config_container_s *state) { return calc_crc((const crc_t*) &state->persistentConfiguration, sizeof(persistent_config_s)); } @@ -77,6 +85,7 @@ void writeToFlashNow(void) { scheduleMsg(logger, "Flashing with CRC=%d", crcResult); efitimems_t nowMs = currentTimeMillis(); int result = flashWrite(FLASH_ADDR, (const char *) &persistentState, PERSISTENT_SIZE); + flashWrite(FLASH_ADDR_SECOND_COPY, (const char *) &persistentState, PERSISTENT_SIZE); scheduleMsg(logger, "Flash programmed in %dms", currentTimeMillis() - nowMs); bool isSuccess = result == FLASH_RETURN_SUCCESS; if (isSuccess) { @@ -99,27 +108,41 @@ static void doResetConfiguration(void) { persisted_configuration_state_e flashState; +static persisted_configuration_state_e doReadConfiguration(flashaddr_t address, Logging * logger) { + printMsg(logger, "readFromFlash %x", address); + flashRead(address, (char *) &persistentState, PERSISTENT_SIZE); + + if (!isValidCrc(&persistentState)) { + return CRC_FAILED; + } else if (persistentState.version != FLASH_DATA_VERSION || persistentState.size != PERSISTENT_SIZE) { + return INCOMPATIBLE_VERSION; + } else { + return PC_OK; + } +} + /** * 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; + persisted_configuration_state_e result = doReadConfiguration(FLASH_ADDR, logger); + if (result != PC_OK) { + printMsg(logger, "Reading second configuration copy"); + result = doReadConfiguration(FLASH_ADDR_SECOND_COPY, logger); + } + + if (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; + } else if (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 @@ -128,7 +151,6 @@ persisted_configuration_state_e readConfiguration(Logging * logger) { } void readFromFlash(void) { - printMsg(logger, "readFromFlash()"); persisted_configuration_state_e result = readConfiguration(logger); if (result == CRC_FAILED) { diff --git a/firmware/controllers/flash_main.h b/firmware/controllers/flash_main.h index 5423d2356e..37599ad65b 100644 --- a/firmware/controllers/flash_main.h +++ b/firmware/controllers/flash_main.h @@ -14,7 +14,7 @@ #define FLASH_DATA_VERSION 10000 typedef enum { - OK = 0, + PC_OK = 0, CRC_FAILED = 1, INCOMPATIBLE_VERSION = 2, RESET_REQUESTED = 3, diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 4748a685e5..ab00d2173c 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -538,7 +538,7 @@ void TriggerShape::initializeTriggerShape(Logging *logger DECLARE_ENGINE_PARAMET configureHondaAccordShifted(triggerShape PASS_ENGINE_PARAMETER); break; - case TT_HONDA_ACCORD_CD_DIP: + case TT_HONDA_1_4_24: configureHondaAccordCDDip(triggerShape PASS_ENGINE_PARAMETER); break; diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 932a50727b..e20267e37a 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -249,5 +249,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20170213; + return 20170214; }