diff --git a/firmware/controllers/algo/aux_pid.cpp b/firmware/controllers/algo/aux_pid.cpp index 7cd579fda2..99351f63f2 100644 --- a/firmware/controllers/algo/aux_pid.cpp +++ b/firmware/controllers/algo/aux_pid.cpp @@ -64,7 +64,7 @@ static msg_t auxPidThread(int param) { while (true) { auxPid.sleep(); - if (parametersVersion.isOld(getGlobalConfigurationVersion())) { + if (parametersVersion.isOld(engine->getGlobalConfigurationVersion())) { pidReset(); } diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index f8009e4b48..e0a639ae18 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -35,6 +35,9 @@ static TriggerState initState CCM_OPTIONAL; LoggingWithStorage engineLogger("engine"); +extern int globalConfigurationVersion; + + EXTERN_ENGINE ; @@ -166,6 +169,10 @@ bool Engine::needToStopEngine(efitick_t nowNt) { nowNt - stopEngineRequestTimeNt < 3 * US2NT(US_PER_SECOND_LL); } +int Engine::getGlobalConfigurationVersion(void) const { + return globalConfigurationVersion; +} + void Engine::reset() { withError = isEngineChartEnabled = false; etbAutoTune = false; diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 08d6e84f0e..284fa7e105 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -343,6 +343,8 @@ public: InjectionSignalPair fuelActuators[INJECTION_PIN_COUNT]; IgnitionEventList ignitionEvents; + int getGlobalConfigurationVersion(void) const; + // a pointer with interface type would make this code nicer but would carry extra runtime // cost to resolve pointer, we use instances as a micro optimization #if EFI_SIGNAL_EXECUTOR_ONE_TIMER diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index c0e7f07e39..d822bbd22d 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -136,7 +136,11 @@ static fuel_table_t alphaNfuel = { {/*15 engineLoad=100.00*/ /*0 800.0*/xxxxx, /*1 1213.0*/xxxxx, /*2 1626.0*/xxxxx, /*3 2040.0*/xxxxx, /*4 2453.0*/xxxxx, /*5 2866.0*/xxxxx, /*6 3280.0*/xxxxx, /*7 3693.0*/xxxxx, /*8 4106.0*/xxxxx, /*9 4520.0*/xxxxx, /*10 4933.0*/xxxxx, /*11 5346.0*/xxxxx, /*12 5760.0*/xxxxx, /*13 6173.0*/xxxxx, /*14 6586.0*/xxxxx, /*15 7000.0*/xxxxx} }; -static volatile int globalConfigurationVersion = 0; +/** + * This counter is incremented every time user adjusts ECU parameters online (either via dev console or other + * tuning software) + */ +volatile int globalConfigurationVersion = 0; /** * Current engine configuration. On firmware start we assign empty configuration, then @@ -153,13 +157,6 @@ void rememberCurrentConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { memcpy(&activeConfiguration, engineConfiguration, sizeof(engine_configuration_s)); } -/** - * This counter is incremented every time user adjusts ECU parameters online (either via dev console or other - * tuning software) - */ -int getGlobalConfigurationVersion(void) { - return globalConfigurationVersion; -} extern LoggingWithStorage sharedLogger; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index e51e04c39b..5f26f62e1c 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -308,7 +308,7 @@ static void periodicSlowCallback(Engine *engine) { updatePrimeInjectionPulseState(PASS_ENGINE_PARAMETER_SIGNATURE); } - if (versionForConfigurationListeners.isOld(getGlobalConfigurationVersion())) { + if (versionForConfigurationListeners.isOld(engine->getGlobalConfigurationVersion())) { updateAccelParameters(); engine->engineState.warmupAfrPid.reset(); } diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index a8610344b5..bf23f7ceac 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -206,7 +206,7 @@ void printConfiguration(const engine_configuration_s *engineConfiguration) { getEngine_load_mode_e(engineConfiguration->fuelAlgorithm), engineConfiguration->fuelAlgorithm); - scheduleMsg(&logger, "configurationVersion=%d", getGlobalConfigurationVersion()); + scheduleMsg(&logger, "configurationVersion=%d", engine->getGlobalConfigurationVersion()); for (int k = 0; k < FUEL_LOAD_COUNT; k++) { // print("line %d (%.2f): ", k, engineConfiguration->fuelKeyBins[k]); diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 7c7199b904..8b88e2e38c 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -692,7 +692,7 @@ void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfig * @returns true if configuration just changed, and if that change has affected trigger */ bool checkIfTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - bool result = triggerVersion.isOld(getGlobalConfigurationVersion()) && isTriggerConfigChanged; + bool result = triggerVersion.isOld(engine->getGlobalConfigurationVersion()) && isTriggerConfigChanged; isTriggerConfigChanged = false; // whoever has called the method is supposed to react to changes return result; } diff --git a/firmware/controllers/trigger/trigger_emulator_algo.cpp b/firmware/controllers/trigger/trigger_emulator_algo.cpp index 3338e60196..5790b4fc1f 100644 --- a/firmware/controllers/trigger/trigger_emulator_algo.cpp +++ b/firmware/controllers/trigger/trigger_emulator_algo.cpp @@ -118,7 +118,7 @@ static void updateTriggerShapeIfNeeded(PwmConfig *state) { if (atTriggerVersion < engine->triggerCentral.triggerShape.version) { atTriggerVersion = engine->triggerCentral.triggerShape.version; scheduleMsg(logger, "Stimulator: updating trigger shape: %d/%d %d", atTriggerVersion, - getGlobalConfigurationVersion(), currentTimeMillis()); + engine->getGlobalConfigurationVersion(), currentTimeMillis()); TriggerShape *s = &engine->triggerCentral.triggerShape; diff --git a/firmware/util/LocalVersionHolder.cpp b/firmware/util/LocalVersionHolder.cpp index bdee308cfd..be2d5ce3f3 100644 --- a/firmware/util/LocalVersionHolder.cpp +++ b/firmware/util/LocalVersionHolder.cpp @@ -18,9 +18,9 @@ int LocalVersionHolder::getVersion() { return localVersion; } -bool LocalVersionHolder::isOld(int global) { - if (global > localVersion) { - localVersion = global; +bool LocalVersionHolder::isOld(int globalVersion) { + if (globalVersion > localVersion) { + localVersion = globalVersion; return true; } return false; diff --git a/firmware/util/LocalVersionHolder.h b/firmware/util/LocalVersionHolder.h index 6ab97fe653..55e22eaeac 100644 --- a/firmware/util/LocalVersionHolder.h +++ b/firmware/util/LocalVersionHolder.h @@ -21,9 +21,9 @@ public: * Calling this method changes the internal state of the class - each consumer interested in tracking * changes should have it's own instance of this class * - * @return true if getGlobalConfigurationVersion() has changed since last time we've invoked this method + * @return true if 'globalVersion' has changed since last time we've invoked this method */ - bool isOld(int currentVersion); + bool isOld(int globalVersion); int getVersion(); private: