From 6e747b91c8a811acaef6921c6272e12a479b4dcd Mon Sep 17 00:00:00 2001 From: rusEfi Date: Thu, 19 Feb 2015 08:04:18 -0600 Subject: [PATCH] auto-sync --- firmware/console/tunerstudio/tunerstudio.cpp | 12 +++++++---- firmware/console/tunerstudio/tunerstudio.h | 1 + firmware/controllers/flash_main.cpp | 21 ++++++++++++++++---- firmware/controllers/flash_main.h | 2 +- firmware/controllers/settings.cpp | 2 +- firmware/hw_layer/hardware.cpp | 2 +- firmware/rusefi.cpp | 2 +- firmware/svnversion.h | 4 ++-- 8 files changed, 32 insertions(+), 14 deletions(-) diff --git a/firmware/console/tunerstudio/tunerstudio.cpp b/firmware/console/tunerstudio/tunerstudio.cpp index 8d5c82699a..e1e30480eb 100644 --- a/firmware/console/tunerstudio/tunerstudio.cpp +++ b/firmware/console/tunerstudio/tunerstudio.cpp @@ -308,6 +308,13 @@ void handlePageReadCommand(ts_response_format_e mode, uint16_t pageId, uint16_t #endif } +void requestBurn(void) { +#if EFI_INTERNAL_FLASH + setNeedToWriteConfiguration(); +#endif + incrementGlobalConfigurationVersion(); +} + /** * 'Burn' command is a command to commit the changes */ @@ -327,10 +334,7 @@ void handleBurnCommand(ts_response_format_e mode, uint16_t page) { // todo: how about some multi-threading? memcpy(&persistentState.persistentConfiguration, &configWorkingCopy, sizeof(persistent_config_s)); -#if EFI_INTERNAL_FLASH - setNeedToWriteConfiguration(); -#endif - incrementGlobalConfigurationVersion(); + requestBurn(); tunerStudioWriteCrcPacket(TS_RESPONSE_BURN_OK, NULL, 0); scheduleMsg(tsLogger, "burned in (ms): %d", currentTimeMillis() - nowMs); } diff --git a/firmware/console/tunerstudio/tunerstudio.h b/firmware/console/tunerstudio/tunerstudio.h index 1455f02f24..a717920327 100644 --- a/firmware/console/tunerstudio/tunerstudio.h +++ b/firmware/console/tunerstudio/tunerstudio.h @@ -16,6 +16,7 @@ void updateTunerStudioState(Engine *engine, TunerStudioOutputChannels *tsOutputChannels); void printTsStats(void); +void requestBurn(void); void startTunerStudioConnectivity(Logging *sharedLogger); void syncTunerStudioCopy(void); diff --git a/firmware/controllers/flash_main.cpp b/firmware/controllers/flash_main.cpp index db3c48a40a..e2c08df85d 100644 --- a/firmware/controllers/flash_main.cpp +++ b/firmware/controllers/flash_main.cpp @@ -14,6 +14,10 @@ #include "flash.h" #include "rusefi.h" +#if EFI_TUNER_STUDIO || defined(__DOXYGEN__) +#include "tunerstudio.h" +#endif + #if EFI_INTERNAL_FLASH #include "engine_controller.h" @@ -56,12 +60,12 @@ void writeToFlashIfPending() { // todo: technically we need a lock here, realistically we should be fine. needToWriteConfiguration = false; scheduleMsg(logger, "Writing pending configuration"); - writeToFlash(); + writeToFlashNow(); } extern uint32_t maxLockTime; -void writeToFlash(void) { +void writeToFlashNow(void) { scheduleMsg(logger, " !!!!!!!!!!!!!!!!!!!! BE SURE NOT WRITE WITH IGNITION ON !!!!!!!!!!!!!!!!!!!!"); persistentState.size = PERSISTENT_SIZE; persistentState.version = FLASH_DATA_VERSION; @@ -119,14 +123,23 @@ void readFromFlash(void) { static void rewriteConfig(Engine *engine) { doResetConfiguration(); - writeToFlash(); + writeToFlashNow(); } void initFlash(Logging *sharedLogger, Engine *engine) { logger = sharedLogger; addConsoleAction("readconfig", readFromFlash); - addConsoleAction("writeconfig", writeToFlash); + /** + * This would write NOW (you should not be doing this while connected to real engine) + */ + addConsoleAction("writeconfig", writeToFlashNow); +#if EFI_TUNER_STUDIO || defined(__DOXYGEN__) + /** + * This would schedule write to flash once the engine is stopped + */ + addConsoleAction("burnconfig", requestBurn); +#endif addConsoleAction("resetconfig", doResetConfiguration); addConsoleActionP("rewriteconfig", (VoidPtr)rewriteConfig, engine); } diff --git a/firmware/controllers/flash_main.h b/firmware/controllers/flash_main.h index a79656f440..711ac0dc12 100644 --- a/firmware/controllers/flash_main.h +++ b/firmware/controllers/flash_main.h @@ -23,7 +23,7 @@ void initFlash(Logging *sharedLogger, Engine *engine); * 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. */ -void writeToFlash(void); +void writeToFlashNow(void); void setNeedToWriteConfiguration(void); /** * @return true if an flash write is pending diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 9db0cba04d..a44e9700f9 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -283,7 +283,7 @@ void setEngineType(int value) { engineConfiguration->engineType = (engine_type_e) value; resetConfigurationExt(&logger, (engine_type_e) value, engine); #if EFI_INTERNAL_FLASH - writeToFlash(); + writeToFlashNow(); // scheduleReset(); #endif /* EFI_PROD_CODE */ incrementGlobalConfigurationVersion(); diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 27883ea216..33ac22312c 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -230,7 +230,7 @@ void initHardware(Logging *l, Engine *engine) { if (SHOULD_INGORE_FLASH()) { engineConfiguration->engineType = DEFAULT_ENGINE_TYPE; resetConfigurationExt(sharedLogger, engineConfiguration->engineType, engine); - writeToFlash(); + writeToFlashNow(); } else { readFromFlash(); } diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index b18c494383..499d7467d9 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -278,5 +278,5 @@ int getRusEfiVersion(void) { return 1; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE == 0) return 1; // this is here to make the compiler happy about the unused array - return 20150218; + return 20150219; } diff --git a/firmware/svnversion.h b/firmware/svnversion.h index a15aaa738d..a9ba7c628b 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,5 +1,5 @@ // This file was generated by Version2Header -// Wed Feb 18 22:08:55 EST 2015 +// Thu Feb 19 07:53:56 EST 2015 #ifndef VCS_VERSION -#define VCS_VERSION "6947" +#define VCS_VERSION "6949" #endif