From a3b10a0a04c2718900187aaa8fc9318b2ae787f6 Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 8 Jul 2017 07:19:26 -0400 Subject: [PATCH] RPM refactoring done --- firmware/controllers/algo/aux_pid.cpp | 2 +- firmware/controllers/algo/engine.cpp | 2 +- firmware/controllers/alternatorController.cpp | 2 +- firmware/controllers/idle_thread.cpp | 2 +- firmware/controllers/math/engine_math.cpp | 2 +- firmware/controllers/trigger/main_trigger_callback.cpp | 4 ++-- firmware/controllers/trigger/rpm_calculator.h | 2 ++ firmware/controllers/trigger/spark_logic.cpp | 2 +- 8 files changed, 10 insertions(+), 8 deletions(-) diff --git a/firmware/controllers/algo/aux_pid.cpp b/firmware/controllers/algo/aux_pid.cpp index bcfd6bb7b3..9cda46f36a 100644 --- a/firmware/controllers/algo/aux_pid.cpp +++ b/firmware/controllers/algo/aux_pid.cpp @@ -66,7 +66,7 @@ static msg_t auxPidThread(int param) { pidReset(); } - float rpm = engine->rpmCalculator.rpmValue; + float rpm = GET_RPM(); // todo: make this configurable? bool enabledAtCurrentRpm = rpm > engineConfiguration->cranking.rpm; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 85311c0d9a..0e97a8abf4 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -186,7 +186,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { timeSinceCranking = nowNt - crankingTime; } - int rpm = ENGINE(rpmCalculator.rpmValue); + int rpm = GET_RPM(); sparkDwell = getSparkDwell(rpm PASS_ENGINE_PARAMETER_SUFFIX); dwellAngle = sparkDwell / getOneDegreeTimeMs(rpm); engine->sensors.currentAfr = getAfr(PASS_ENGINE_PARAMETER_SIGNATURE); diff --git a/firmware/controllers/alternatorController.cpp b/firmware/controllers/alternatorController.cpp index 99d7a06719..d30fb39f8e 100644 --- a/firmware/controllers/alternatorController.cpp +++ b/firmware/controllers/alternatorController.cpp @@ -68,7 +68,7 @@ static msg_t AltCtrlThread(int param) { // todo: migrate this to FSIO - bool alternatorShouldBeEnabledAtCurrentRpm = engine->rpmCalculator.rpmValue > engineConfiguration->cranking.rpm; + bool alternatorShouldBeEnabledAtCurrentRpm = GET_RPM() > engineConfiguration->cranking.rpm; engine->isAlternatorControlEnabled = CONFIG(isAlternatorControlEnabled) && alternatorShouldBeEnabledAtCurrentRpm; if (!engine->isAlternatorControlEnabled) { diff --git a/firmware/controllers/idle_thread.cpp b/firmware/controllers/idle_thread.cpp index d7a91df34f..64c72de13a 100644 --- a/firmware/controllers/idle_thread.cpp +++ b/firmware/controllers/idle_thread.cpp @@ -307,7 +307,7 @@ static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) { OutputPin *output = state->outputPins[0]; int value = state->multiWave.waves[0].pinStates[stateIndex]; if (!value /* always allow turning solenoid off */ || - (engine->rpmCalculator.rpmValue != 0 || timeToStopIdleTest != 0) /* do not run solenoid unless engine is spinning or bench testing in progress */ + (GET_RPM() != 0 || timeToStopIdleTest != 0) /* do not run solenoid unless engine is spinning or bench testing in progress */ ) { output->setValue(value); } diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 9bb49ec8ab..0ef3368714 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -227,7 +227,7 @@ static floatms_t getCrankingSparkDwell(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } else { // technically this could be implemented via interpolate2d float angle = engineConfiguration->crankingChargeAngle; - return getOneDegreeTimeMs(engine->rpmCalculator.rpmValue) * angle; + return getOneDegreeTimeMs(GET_RPM()) * angle; } } diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 548c63dc36..07fcc0aacc 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -328,7 +328,7 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #if ! EFI_UNIT_TEST - if (ENGINE(rpmCalculator.rpmValue) < CONFIG(fuelClosedLoopRpmThreshold) || + if (GET_RPM() < CONFIG(fuelClosedLoopRpmThreshold) || ENGINE(sensors.clt) < CONFIG(fuelClosedLoopCltThreshold) || getTPS(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(fuelClosedLoopTpsThreshold) || ENGINE(sensors.currentAfr) < boardConfiguration->fuelClosedLoopAfrLowThreshold || @@ -432,7 +432,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D return; } - int rpm = ENGINE(rpmCalculator.rpmValue); + int rpm = GET_RPM(); if (rpm == 0) { // this happens while we just start cranking // todo: check for 'trigger->is_synchnonized?' diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index 45f7573484..0707b515d0 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -48,6 +48,8 @@ typedef enum { class Engine; +#define GET_RPM() ( ENGINE(rpmCalculator.rpmValue) ) + class RpmCalculator { public: #if !EFI_PROD_CODE diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index b657404060..2c994c8fa8 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -79,7 +79,7 @@ void turnSparkPinLow(IgnitionEvent *event) { static void turnSparkPinHigh2(IgnitionEvent *event, IgnitionOutputPin *output) { #if ! EFI_UNIT_TEST || defined(__DOXYGEN__) - if (engine->rpmCalculator.rpmValue > 2 * engineConfiguration->cranking.rpm) { + if (GET_RPM() > 2 * engineConfiguration->cranking.rpm) { const char *outputName = output->name; if (prevSparkName == outputName && engineConfiguration->ignitionMode != IM_ONE_COIL) { warning(CUSTOM_OBD_SKIPPED_SPARK, "looks like skipped spark event %d %s", getRevolutionCounter(), outputName);