diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index aa1005f823..613dcf0e31 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -308,6 +308,17 @@ injection_mode_e Engine::getCurrentInjectionMode(DECLARE_ENGINE_PARAMETER_SIGNAT return rpmCalculator.isCranking(PASS_ENGINE_PARAMETER_SIGNATURE) ? CONFIG(crankingInjectionMode) : CONFIG(injectionMode); } +// see also in TunerStudio project '[doesTriggerImplyOperationMode] tag +static bool doesTriggerImplyOperationMode(trigger_type_e type) { + return type != TT_TOOTHED_WHEEL && type != TT_TOOTHED_WHEEL_60_2 && type != TT_TOOTHED_WHEEL_36_1; +} + +operation_mode_e Engine::getOperationMode(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + //return doesTriggerImplyOperationMode(engineConfiguration->trigger.type) ? triggerCentral.triggerShape.getOperationMode() : engineConfiguration->ambiguousOperationMode; + return engineConfiguration->operationMode; +} + + /** * The idea of this method is to execute all heavy calculations in a lower-priority thread, * so that trigger event handler/IO scheduler tasks are faster. diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index bd446fbe19..04689cba8e 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -77,6 +77,8 @@ public: IgnitionEventList ignitionEvents; LocalVersionHolder versionForConfigurationListeners; LocalVersionHolder auxParametersVersion; + operation_mode_e getOperationMode(DECLARE_ENGINE_PARAMETER_SIGNATURE); + int globalSparkIdCoutner = 0; diff --git a/firmware/controllers/map_averaging.cpp b/firmware/controllers/map_averaging.cpp index a8409f04ec..89e19a1646 100644 --- a/firmware/controllers/map_averaging.cpp +++ b/firmware/controllers/map_averaging.cpp @@ -235,7 +235,7 @@ void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { efiAssertVoid(CUSTOM_ERR_MAP_AVG_OFFSET, !cisnan(offsetAngle), "offsetAngle"); for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { - angle_t cylinderOffset = getEngineCycle(engineConfiguration->operationMode) * i / engineConfiguration->specs.cylindersCount; + angle_t cylinderOffset = getEngineCycle(engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)) * i / engineConfiguration->specs.cylindersCount; efiAssertVoid(CUSTOM_ERR_6692, !cisnan(cylinderOffset), "cylinderOffset"); float cylinderStart = start + cylinderOffset - offsetAngle + tdcPosition(); fixAngle(cylinderStart, "cylinderStart", CUSTOM_ERR_6562); diff --git a/firmware/controllers/math/config_engine_specs.h b/firmware/controllers/math/config_engine_specs.h index fdd573a731..82628654d0 100644 --- a/firmware/controllers/math/config_engine_specs.h +++ b/firmware/controllers/math/config_engine_specs.h @@ -34,7 +34,6 @@ #define CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(x) persistentState.persistentConfiguration.engineConfiguration.x #endif /* EFI_UNIT_TEST */ -#define get_operationMode CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(operationMode) #define get_specs_displacement CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(specs.displacement) #define get_specs_cylindersCount CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(specs.cylindersCount) #define get_injector_flow CONFIG_ACCESS_FOR_CONFIG_HEADER_ONLY(injector.flow) diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 527d3ec540..ec892a5489 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -33,8 +33,8 @@ EXTERN_ENGINE ; -floatms_t getEngineCycleDuration(int rpm DECLARE_GLOBAL_SUFFIX) { - return getCrankshaftRevolutionTimeMs(rpm) * (get_operationMode == TWO_STROKE ? 1 : 2); +floatms_t getEngineCycleDuration(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { + return getCrankshaftRevolutionTimeMs(rpm) * (engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE) == TWO_STROKE ? 1 : 2); } /** @@ -472,7 +472,7 @@ ignition_mode_e getCurrentIgnitionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE) { * This heavy method is only invoked in case of a configuration change or initialization. */ void prepareOutputSignals(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - ENGINE(engineCycle) = getEngineCycle(CONFIG(operationMode)); + ENGINE(engineCycle) = getEngineCycle(engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)); angle_t maxTimingCorrMap = -720.0f; angle_t maxTimingMap = -720.0f; diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index a3996e899c..e8d5c6f0eb 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -236,7 +236,7 @@ void printConfiguration(const engine_configuration_s *engineConfiguration) { // printFloatArray("vBatt bins: ", engineConfiguration->injector.battLagCorrBins, VBAT_INJECTOR_CURVE_SIZE); scheduleMsg(&logger, "rpmHardLimit: %d/operationMode=%d", engineConfiguration->rpmHardLimit, - engineConfiguration->operationMode); + engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)); scheduleMsg(&logger, "globalTriggerAngleOffset=%.2f", engineConfiguration->globalTriggerAngleOffset); diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index db18383745..db1c00f86d 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -253,7 +253,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, if (diffNt == 0) { rpmState->setRpmValue(NOISY_RPM PASS_ENGINE_PARAMETER_SUFFIX); } else { - int mult = (int)getEngineCycle(engineConfiguration->operationMode) / 360; + int mult = (int)getEngineCycle(engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE)) / 360; int rpm = (int) (60 * US2NT(US_PER_SECOND_LL) * mult / diffNt); rpmState->setRpmValue(rpm > UNREALISTIC_RPM ? NOISY_RPM : rpm PASS_ENGINE_PARAMETER_SUFFIX); } diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index 4788e42264..24e6b4d08c 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -348,10 +348,11 @@ static ALWAYS_INLINE void prepareIgnitionSchedule(DECLARE_ENGINE_PARAMETER_SIGNA * but we are already re-purposing the output signals, but everything works because we * are not affecting that space in memory. todo: use two instances of 'ignitionSignals' */ - float maxAllowedDwellAngle = (int) (getEngineCycle(engineConfiguration->operationMode) / 2); // the cast is about making Coverity happy + operation_mode_e operationMode = engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE); + float maxAllowedDwellAngle = (int) (getEngineCycle(operationMode) / 2); // the cast is about making Coverity happy if (getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) == IM_ONE_COIL) { - maxAllowedDwellAngle = getEngineCycle(engineConfiguration->operationMode) / engineConfiguration->specs.cylindersCount / 1.1; + maxAllowedDwellAngle = getEngineCycle(operationMode) / engineConfiguration->specs.cylindersCount / 1.1; } if (engine->engineState.dwellAngle == 0) { @@ -450,6 +451,6 @@ int getNumberOfSparks(ignition_mode_e mode DECLARE_ENGINE_PARAMETER_SUFFIX) { */ percent_t getCoilDutyCycle(int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) { floatms_t totalPerCycle = 1/**getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX)*/ * getNumberOfSparks(getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) PASS_ENGINE_PARAMETER_SUFFIX); - floatms_t engineCycleDuration = getCrankshaftRevolutionTimeMs(rpm) * (engineConfiguration->operationMode == TWO_STROKE ? 1 : 2); + floatms_t engineCycleDuration = getCrankshaftRevolutionTimeMs(rpm) * (engine->getOperationMode(PASS_ENGINE_PARAMETER_SIGNATURE) == TWO_STROKE ? 1 : 2); return 100 * totalPerCycle / engineCycleDuration; } diff --git a/firmware/svnversion.h b/firmware/svnversion.h index 1f9ce52a72..a3b93ad744 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,12 +1,12 @@ // This file was generated by Version2Header -// Tue Aug 06 22:52:28 EDT 2019 +// Wed Aug 07 22:44:31 EDT 2019 #ifndef GIT_HASH -#define GIT_HASH "2579897d060ece1d5416fa9a117b81f274a1f3ba" +#define GIT_HASH "1f8bfa4ee0f861b8087f350381e2c462be2b9bd8" #endif #ifndef VCS_VERSION -#define VCS_VERSION "19666" +#define VCS_VERSION "19676" #endif