diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index a6679ec10f..2aa78a399a 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -838,7 +838,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ { float instantRpm = engine->triggerCentral.triggerState.instantRpm; tsOutputChannels->debugFloatField1 = instantRpm; - tsOutputChannels->debugFloatField2 = instantRpm / GET_RPM(); + tsOutputChannels->debugFloatField2 = instantRpm / GET_RPM_VALUE; } break; case DBG_ION: diff --git a/firmware/controllers/algo/aux_pid.cpp b/firmware/controllers/algo/aux_pid.cpp index 99351f63f2..1d3cbc5c63 100644 --- a/firmware/controllers/algo/aux_pid.cpp +++ b/firmware/controllers/algo/aux_pid.cpp @@ -68,7 +68,7 @@ static msg_t auxPidThread(int param) { pidReset(); } - float rpm = GET_RPM(); + float rpm = GET_RPM_VALUE; // todo: make this configurable? bool enabledAtCurrentRpm = rpm > engineConfiguration->cranking.rpm; diff --git a/firmware/controllers/alternatorController.cpp b/firmware/controllers/alternatorController.cpp index 388c74fc53..5b576fb645 100644 --- a/firmware/controllers/alternatorController.cpp +++ b/firmware/controllers/alternatorController.cpp @@ -65,7 +65,7 @@ static msg_t AltCtrlThread(int param) { } // todo: migrate this to FSIO - bool alternatorShouldBeEnabledAtCurrentRpm = GET_RPM() > engineConfiguration->cranking.rpm; + bool alternatorShouldBeEnabledAtCurrentRpm = GET_RPM_VALUE > 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 fee0f89ac9..9cee4f1da2 100644 --- a/firmware/controllers/idle_thread.cpp +++ b/firmware/controllers/idle_thread.cpp @@ -451,7 +451,7 @@ static void applyIdleSolenoidPinState(PwmConfig *state, int stateIndex) { OutputPin *output = state->outputPins[0]; int value = state->multiWave.getChannelState(/*channelIndex*/0, stateIndex); if (!value /* always allow turning solenoid off */ || - (GET_RPM() != 0 || timeToStopIdleTest != 0) /* do not run solenoid unless engine is spinning or bench testing in progress */ + (GET_RPM_VALUE != 0 || timeToStopIdleTest != 0) /* do not run solenoid unless engine is spinning or bench testing in progress */ ) { output->setValue(value); } diff --git a/firmware/controllers/map_averaging.cpp b/firmware/controllers/map_averaging.cpp index ce189d2a30..074a9c839d 100644 --- a/firmware/controllers/map_averaging.cpp +++ b/firmware/controllers/map_averaging.cpp @@ -224,7 +224,7 @@ void postMapState(TunerStudioOutputChannels *tsOutputChannels) { } void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - int rpm = GET_RPM(); + int rpm = GET_RPM_VALUE; if (isValidRpm(rpm)) { MAP_sensor_config_s * c = &engineConfiguration->map; angle_t start = interpolate2d("mapa", rpm, c->samplingAngleBins, c->samplingAngle, MAP_ANGLE_SIZE); @@ -261,7 +261,7 @@ static void mapAveragingTriggerCallback(trigger_event_e ckpEventType, return; engine->m.beforeMapAveragingCb = GET_TIMESTAMP(); - int rpm = GET_RPM(); + int rpm = GET_RPM_VALUE; if (!isValidRpm(rpm)) { return; } @@ -322,7 +322,7 @@ float getMap(void) { } #if EFI_ANALOG_SENSORS || defined(__DOXYGEN__) - if (!isValidRpm(GET_RPM()) || currentPressure == NO_VALUE_YET) + if (!isValidRpm(GET_RPM_VALUE) || currentPressure == NO_VALUE_YET) return validateMap(getRawMap()); // maybe return NaN in case of stopped engine? return validateMap(currentPressure); #else diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index cc35733cfa..1a99159fd1 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -238,7 +238,7 @@ static floatms_t getCrankingSparkDwell(DECLARE_ENGINE_PARAMETER_SIGNATURE) { } else { // technically this could be implemented via interpolate2d float angle = engineConfiguration->crankingChargeAngle; - return getOneDegreeTimeMs(GET_RPM()) * angle; + return getOneDegreeTimeMs(GET_RPM_VALUE) * angle; } } diff --git a/firmware/controllers/trigger/aux_valves.cpp b/firmware/controllers/trigger/aux_valves.cpp index f626bdfbef..eabf77797e 100644 --- a/firmware/controllers/trigger/aux_valves.cpp +++ b/firmware/controllers/trigger/aux_valves.cpp @@ -40,7 +40,7 @@ static void auxValveTriggerCallback(trigger_event_e ckpSignalType, if (index != SCHEDULING_TRIGGER_INDEX) { return; } - int rpm = GET_RPM(); + int rpm = GET_RPM_VALUE; if (!isValidRpm(rpm)) { return; } diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 4994e05293..3334ce8917 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -315,7 +315,7 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE InjectorOutputPin *output = event->outputs[0]; #if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__) printf("fuelout %s duration %d total=%d\t\n", output->name, (int)durationUs, - (int)MS2US(getCrankshaftRevolutionTimeMs(GET_RPM()))); + (int)MS2US(getCrankshaftRevolutionTimeMs(GET_RPM_VALUE))); #endif /*EFI_PRINTF_FUEL_DETAILS */ @@ -350,7 +350,7 @@ static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionE static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) { #if ! EFI_UNIT_TEST - if (GET_RPM() < CONFIG(fuelClosedLoopRpmThreshold) || + if (GET_RPM_VALUE < CONFIG(fuelClosedLoopRpmThreshold) || ENGINE(sensors.clt) < CONFIG(fuelClosedLoopCltThreshold) || getTPS(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(fuelClosedLoopTpsThreshold) || ENGINE(sensors.currentAfr) < CONFIGB(fuelClosedLoopAfrLowThreshold) || @@ -456,7 +456,7 @@ void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex D return; } - int rpm = GET_RPM(); + int rpm = GET_RPM_VALUE; if (rpm == 0) { // this happens while we just start cranking // todo: check for 'trigger->is_synchnonized?' diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index fbc62ea5be..4ecafb17a7 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -207,13 +207,10 @@ void RpmCalculator::setSpinningUp(efitime_t nowNt DECLARE_ENGINE_PARAMETER_SUFFI } /** - * WARNING: this is a heavy method because 'getRpm()' is relatively heavy - * * @return -1 in case of isNoisySignal(), current RPM otherwise */ // todo: migrate to float return result or add a float version? this would have with calculations -// todo: add a version which does not check time & saves time? need to profile -int RpmCalculator::getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE) { +int RpmCalculator::getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE) const { #if !EFI_PROD_CODE if (mockRpm != MOCK_UNDEFINED) { return mockRpm; diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index 8c2f20e89a..6255200299 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -53,8 +53,6 @@ typedef enum { RUNNING, } spinning_state_e; -#define GET_RPM() ( ENGINE(rpmCalculator.rpmValue) ) - class RpmCalculator { public: #if !EFI_PROD_CODE @@ -94,7 +92,11 @@ public: */ void setStopSpinning(DECLARE_ENGINE_PARAMETER_SIGNATURE); - int getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE); + /** + * Just a getter for rpmValue + * Also hangles mockRpm if not EFI_PROD_CODE + */ + int getRpm(DECLARE_ENGINE_PARAMETER_SIGNATURE) const; /** * This method is invoked once per engine cycle right after we calculate new RPM value */ @@ -157,6 +159,10 @@ private: */ #define getRpmE(engine) (engine)->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_SIGNATURE) +#define GET_RPM_VALUE ( ENGINE(rpmCalculator.rpmValue) ) + +#define isValidRpm(rpm) ((rpm) > 0 && (rpm) < UNREALISTIC_RPM) + void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX); /** * @brief Initialize RPM calculator @@ -167,8 +173,6 @@ float getCrankshaftAngleNt(efitime_t timeNt DECLARE_ENGINE_PARAMETER_SUFFIX); int getRevolutionCounter(void); -#define isValidRpm(rpm) ((rpm) > 0 && (rpm) < UNREALISTIC_RPM) - #if EFI_ENGINE_SNIFFER #define addEngineSnifferEvent(name, msg) if (ENGINE(isEngineChartEnabled)) { waveChart.addEvent3((name), (msg)); } #else diff --git a/firmware/controllers/trigger/spark_logic.cpp b/firmware/controllers/trigger/spark_logic.cpp index 75577eb242..aa706a4646 100644 --- a/firmware/controllers/trigger/spark_logic.cpp +++ b/firmware/controllers/trigger/spark_logic.cpp @@ -131,7 +131,7 @@ void turnSparkPinLow(IgnitionEvent *event) { static void turnSparkPinHigh2(IgnitionEvent *event, IgnitionOutputPin *output) { #if ! EFI_UNIT_TEST || defined(__DOXYGEN__) - if (GET_RPM() > 2 * engineConfiguration->cranking.rpm) { + if (GET_RPM_VALUE > 2 * engineConfiguration->cranking.rpm) { const char *outputName = output->name; if (prevSparkName == outputName && getCurrentIgnitionMode(PASS_ENGINE_PARAMETER_SIGNATURE) != IM_ONE_COIL) { warning(CUSTOM_OBD_SKIPPED_SPARK, "looks like skipped spark event %d %s", getRevolutionCounter(), outputName); diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 8919db61de..6bd7a19ba5 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -566,7 +566,7 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no } if (!isValidIndex(PASS_ENGINE_PARAMETER_SIGNATURE) && !engine->isInitializingTrigger) { // let's not show a warning if we are just starting to spin - if (GET_RPM() != 0) { + if (GET_RPM_VALUE != 0) { warning(CUSTOM_SYNC_ERROR, "sync error: index #%d above total size %d", currentCycle.current_index, getTriggerSize()); lastDecodingErrorTime = getTimeNowNt(); someSortOfTriggerError = true; diff --git a/firmware/hw_layer/HIP9011.cpp b/firmware/hw_layer/HIP9011.cpp index e45d798e25..7d592f2200 100644 --- a/firmware/hw_layer/HIP9011.cpp +++ b/firmware/hw_layer/HIP9011.cpp @@ -241,7 +241,7 @@ static void intHoldCallback(trigger_event_e ckpEventType, uint32_t index DECLARE return; engine->m.beforeHipCb = GET_TIMESTAMP(); - int rpm = GET_RPM(); + int rpm = GET_RPM_VALUE; if (!isValidRpm(rpm)) return; @@ -299,7 +299,7 @@ void hipAdcCallback(adcsample_t adcValue) { hipValueMax = maxF(engine->knockVolts, hipValueMax); engine->knockLogic(engine->knockVolts); - instance.handleValue(GET_RPM() DEFINE_PARAM_SUFFIX(PASS_HIP_PARAMS)); + instance.handleValue(GET_RPM_VALUE DEFINE_PARAM_SUFFIX(PASS_HIP_PARAMS)); } } diff --git a/unit_tests/tests/test_fasterEngineSpinningUp.cpp b/unit_tests/tests/test_fasterEngineSpinningUp.cpp index d5278873e7..753e544c2e 100644 --- a/unit_tests/tests/test_fasterEngineSpinningUp.cpp +++ b/unit_tests/tests/test_fasterEngineSpinningUp.cpp @@ -104,5 +104,5 @@ TEST(cranking, testFasterEngineSpinningUp60_2) { setupSimpleTestEngineWithMaf(ð, IM_SEQUENTIAL, TT_TOOTHED_WHEEL_60_2); - + eth.fireTriggerEvents2(30 /* count */, 1 /*ms*/); }