diff --git a/firmware/console/binary/tunerstudio.cpp b/firmware/console/binary/tunerstudio.cpp index f6627759af..c9b98e7be2 100644 --- a/firmware/console/binary/tunerstudio.cpp +++ b/firmware/console/binary/tunerstudio.cpp @@ -254,6 +254,8 @@ void handlePageSelectCommand(ts_channel_s *tsChannel, ts_response_format_e mode, } /** + * Copy specified amount of bytes from specified offset from communication layer working copy into real configuration + * * Some changes like changing VE table or timing table are applied right away, meaning * that the values are copied from communication copy into actual engine control copy right away. * We call these parameters 'soft parameters' @@ -263,7 +265,7 @@ void handlePageSelectCommand(ts_channel_s *tsChannel, ts_response_format_e mode, * On the contrary, 'hard parameters' are waiting for the Burn button to be clicked and configuration version * would be increased and much more complicated logic would be executed. */ -static void onlineTuneBytes(int currentPageId, uint32_t offset, int count) { +static void onlineApplyWorkingCopyBytes(int currentPageId, uint32_t offset, int count) { UNUSED(currentPageId); if (offset > sizeof(engine_configuration_s)) { int maxSize = sizeof(persistent_config_s) - offset; @@ -312,7 +314,7 @@ void handleWriteChunkCommand(ts_channel_s *tsChannel, ts_response_format_e mode, uint8_t * addr = (uint8_t *) (getWorkingPageAddr(currentPageId) + offset); memcpy(addr, content, count); - onlineTuneBytes(currentPageId, offset, count); + onlineApplyWorkingCopyBytes(currentPageId, offset, count); sendOkResponse(tsChannel, mode); } @@ -370,7 +372,7 @@ void handleWriteValueCommand(ts_channel_s *tsChannel, ts_response_format_e mode, getWorkingPageAddr(currentPageId)[offset] = value; - onlineTuneBytes(currentPageId, offset, 1); + onlineApplyWorkingCopyBytes(currentPageId, offset, 1); // scheduleMsg(logger, "va=%d", configWorkingCopy.boardConfiguration.idleValvePin); } @@ -589,6 +591,9 @@ static THD_FUNCTION(tsThreadEntryPoint, arg) { runBinaryProtocolLoop(&tsChannel); } +/** + * Copy real configuration into the communications layer working copy + */ void syncTunerStudioCopy(void) { #if !defined(EFI_NO_CONFIG_WORKING_COPY) || defined(__DOXYGEN__) memcpy(&configWorkingCopy, &persistentState.persistentConfiguration, sizeof(persistent_config_s)); diff --git a/firmware/console/console_io.h b/firmware/console/console_io.h index d70e93594c..fc613e36ac 100644 --- a/firmware/console/console_io.h +++ b/firmware/console/console_io.h @@ -25,8 +25,8 @@ typedef void (*CommandHandler)(char *); #include "datalogging.h" #ifdef CONFIG_RESET_SWITCH_PORT -// todo: make this pin configurable -#define SHOULD_INGORE_FLASH() (CONFIG_RESET_SWITCH_PORT != NULL && palReadPad(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN) == 0) +// todo: make this pin configurable? or maybe it should not be configurable? +#define SHOULD_INGORE_FLASH() (palReadPad(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN) == 0) #else #define SHOULD_INGORE_FLASH() (false) #endif diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index ddeb831975..ddaee41dd2 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -1357,7 +1357,7 @@ void resetConfigurationExt(Logging * logger, engine_type_e engineType DECLARE_EN #if EFI_TUNER_STUDIO syncTunerStudioCopy(); -#endif +#endif /* EFI_TUNER_STUDIO */ } void validateConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index f3e89f2c16..cc735891a9 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -441,6 +441,16 @@ static void getByte(int offset) { scheduleMsg(&logger, "byte%s%d is %d", CONSOLE_DATA_PROTOCOL_TAG, offset, value); } +static void onConfigurationChanged() { +#if EFI_TUNER_STUDIO + // on start-up rusEfi would read from working copy of TS while + // we have a lot of console commands which write into real copy of configuration directly + // we have a bit of a mess here + syncTunerStudioCopy(); +#endif /* EFI_TUNER_STUDIO */ + incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE); +} + static void setBit(const char *offsetStr, const char *bitStr, const char *valueStr) { int offset = atoi(offsetStr); if (absI(offset) == absI(ERROR_CODE)) { @@ -466,7 +476,7 @@ static void setBit(const char *offsetStr, const char *bitStr, const char *valueS * this response is part of dev console API */ scheduleMsg(&logger, "bit%s%d/%d is %d", CONSOLE_DATA_PROTOCOL_TAG, offset, bit, value); - incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE); + onConfigurationChanged(); } static void setShort(const int offset, const int value) { @@ -475,7 +485,7 @@ static void setShort(const int offset, const int value) { uint16_t *ptr = (uint16_t *) (&((char *) engineConfiguration)[offset]); *ptr = (uint16_t) value; getShort(offset); - incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE); + onConfigurationChanged(); } static void setByte(const int offset, const int value) { @@ -484,7 +494,7 @@ static void setByte(const int offset, const int value) { uint8_t *ptr = (uint8_t *) (&((char *) engineConfiguration)[offset]); *ptr = (uint8_t) value; getByte(offset); - incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE); + onConfigurationChanged(); } static void getBit(int offset, int bit) { @@ -515,7 +525,7 @@ static void setInt(const int offset, const int value) { int *ptr = (int *) (&((char *) engineConfiguration)[offset]); *ptr = value; getInt(offset); - incrementGlobalConfigurationVersion(PASS_ENGINE_PARAMETER_SIGNATURE); + onConfigurationChanged(); } static void getFloat(int offset) { @@ -545,6 +555,7 @@ static void setFloat(const char *offsetStr, const char *valueStr) { float *ptr = (float *) (&((char *) engineConfiguration)[offset]); *ptr = value; getFloat(offset); + onConfigurationChanged(); } #if EFI_ENABLE_MOCK_ADC || EFI_SIMULATOR diff --git a/firmware/controllers/flash_main.cpp b/firmware/controllers/flash_main.cpp index a49090393b..0a7f2c829b 100644 --- a/firmware/controllers/flash_main.cpp +++ b/firmware/controllers/flash_main.cpp @@ -171,6 +171,16 @@ static void rewriteConfig(void) { writeToFlashNow(); } +static void writeConfigCommand() { +#if EFI_TUNER_STUDIO + // on start-up rusEfi would read from working copy of TS while + // we have a lot of console commands which write into real copy of configuration directly + // we have a bit of a mess here + syncTunerStudioCopy(); +#endif /* EFI_TUNER_STUDIO */ + writeToFlashNow(); +} + void initFlash(Logging *sharedLogger) { logger = sharedLogger; @@ -178,7 +188,7 @@ void initFlash(Logging *sharedLogger) { /** * This would write NOW (you should not be doing this while connected to real engine) */ - addConsoleAction("writeconfig", writeToFlashNow); + addConsoleAction("writeconfig", writeConfigCommand); #if EFI_TUNER_STUDIO || defined(__DOXYGEN__) /** * This would schedule write to flash once the engine is stopped diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 2aeea4ff3f..188f6243cf 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -369,7 +369,9 @@ void initHardware(Logging *l) { #if EFI_INTERNAL_FLASH +#ifdef CONFIG_RESET_SWITCH_PORT palSetPadMode(CONFIG_RESET_SWITCH_PORT, CONFIG_RESET_SWITCH_PIN, PAL_MODE_INPUT_PULLUP); +#endif /* CONFIG_RESET_SWITCH_PORT */ initFlash(sharedLogger); /**