diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index be9a2795fc..9cda7b908e 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -309,7 +309,7 @@ void StartupFuelPumping::setPumpsCounter( } void StartupFuelPumping::update(DECLARE_ENGINE_PARAMETER_F) { - if (engine->rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F) == 0) { + if (engine->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F) == 0) { bool isTpsAbove50 = getTPS(PASS_ENGINE_PARAMETER_F) >= 50; if (this->isTpsAbove50 != isTpsAbove50) { diff --git a/firmware/controllers/algo/fuel_math.cpp b/firmware/controllers/algo/fuel_math.cpp index dd28c2bd03..ba3701af51 100644 --- a/firmware/controllers/algo/fuel_math.cpp +++ b/firmware/controllers/algo/fuel_math.cpp @@ -193,7 +193,7 @@ floatms_t getBaseTableFuel(engine_configuration_s *engineConfiguration, int rpm, float getBaroCorrection(DECLARE_ENGINE_PARAMETER_F) { if (hasBaroSensor(PASS_ENGINE_PARAMETER_F)) { - return baroCorrMap.getValue(getBaroPressure(PASS_ENGINE_PARAMETER_F), getRpm()); + return baroCorrMap.getValue(getBaroPressure(PASS_ENGINE_PARAMETER_F), getRpmE(engine)); } else { return 1; } diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index 6bcfa901a7..2f49f7ffe0 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -75,7 +75,7 @@ float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action) { case LE_METHOD_INTAKE_AIR: return getIntakeAirTemperature(PASS_ENGINE_PARAMETER_F); case LE_METHOD_RPM: - return engine->rpmCalculator.rpm(); + return engine->rpmCalculator.getRpm(); case LE_METHOD_TIME_SINCE_BOOT: return getTimeNowSeconds(); case LE_METHOD_FAN_OFF_SETTING: diff --git a/firmware/controllers/core/table_helper.h b/firmware/controllers/core/table_helper.h index 466915e66f..30f09cd83e 100644 --- a/firmware/controllers/core/table_helper.h +++ b/firmware/controllers/core/table_helper.h @@ -12,9 +12,9 @@ #include "interpolation.h" #include "efilib.h" -// 'random' value to be sure we are not treating any non-zero trash as TRUE -#define MAGIC_TRUE_VALUE 153351512 - +/** + * this helper class brings together 3D table with two 2D axis curves + */ template class Map3D { public: @@ -26,7 +26,7 @@ private: float *pointers[LOAD_BIN_SIZE]; float *loadBins; float *rpmBins; - int initialized; + bool initialized; const char *name; }; @@ -73,14 +73,14 @@ void Map3D::init(float table[RPM_BIN_SIZE][LOAD_BIN for (int k = 0; k < LOAD_BIN_SIZE; k++) { pointers[k] = table[k]; } - initialized = MAGIC_TRUE_VALUE; + initialized = true; this->loadBins = loadBins; this->rpmBins = rpmBins; } template float Map3D::getValue(float x, float rpm) { - efiAssert(initialized == MAGIC_TRUE_VALUE, "map not initialized", NAN); + efiAssert(initialized, "map not initialized", NAN); if (cisnan(x)) { warning(OBD_PCM_Processor_Fault, "%s: x is NaN", name); return NAN; @@ -99,7 +99,7 @@ Map3D::Map3D(const char *name) { template void Map3D::setAll(float value) { - efiAssertVoid(initialized == MAGIC_TRUE_VALUE, "map not initialized"); + efiAssertVoid(initialized, "map not initialized"); for (int l = 0; l < LOAD_BIN_SIZE; l++) { for (int r = 0; r < RPM_BIN_SIZE; r++) { pointers[l][r] = value; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index d02d58fe99..f510a15afc 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -117,7 +117,7 @@ static msg_t csThread(void) { chRegSetThreadName("status"); #if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__) while (true) { - int rpm = getRpm(); + int rpm = getRpmE(engine); int is_cranking = isCrankingR(rpm); int is_running = rpm > 0 && !is_cranking; if (is_running) { diff --git a/firmware/controllers/idle_thread.cpp b/firmware/controllers/idle_thread.cpp index d87f9f0e35..96c4fed4a9 100644 --- a/firmware/controllers/idle_thread.cpp +++ b/firmware/controllers/idle_thread.cpp @@ -194,7 +194,7 @@ static msg_t ivThread(int param) { efitimems_t now = currentTimeMillis(); - percent_t newValue = idlePositionController.getIdle(getRpm(), now PASS_ENGINE_PARAMETER); + percent_t newValue = idlePositionController.getIdle(getRpmE(engine), now PASS_ENGINE_PARAMETER); if (currentIdleValve != newValue) { currentIdleValve = newValue; diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index b4060d93c1..45294cf048 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -485,7 +485,7 @@ void MainTriggerCallback::init(Engine *engine) { static void showMainInfo(Engine *engine) { #if EFI_PROD_CODE || defined(__DOXYGEN__) - int rpm = engine->rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F); + int rpm = engine->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F); float el = getEngineLoadT(PASS_ENGINE_PARAMETER_F); scheduleMsg(logger, "rpm %d engine_load %f", rpm, el); scheduleMsg(logger, "fuel %fms timing %f", getFuelMs(rpm PASS_ENGINE_PARAMETER), engine->engineState.timingAdvance); diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index 69f5b3997f..c65b2d564d 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -116,7 +116,7 @@ float RpmCalculator::getRpmAcceleration() { */ // 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::rpm(DECLARE_ENGINE_PARAMETER_F) { +int RpmCalculator::getRpm(DECLARE_ENGINE_PARAMETER_F) { #if !EFI_PROD_CODE if (mockRpm != MOCK_UNDEFINED) return mockRpm; @@ -221,7 +221,7 @@ static char rpmBuffer[10]; * digital sniffer. */ static void onTdcCallback(void) { - itoa10(rpmBuffer, getRpm()); + itoa10(rpmBuffer, getRpmE(engine)); addWaveChartEvent(TOP_DEAD_CENTER_MESSAGE, (char* ) rpmBuffer); } @@ -235,7 +235,7 @@ static void tdcMarkCallback(trigger_event_e ckpSignalType, if (isTriggerSynchronizationPoint && engineConfiguration->isEngineChartEnabled) { int revIndex2 = engine->rpmCalculator.getRevolutionCounter() % 2; - int rpm = getRpm(); + int rpm = getRpmE(engine); // todo: use event-based scheduling, not just time-based scheduling if (isValidRpm(rpm)) { scheduleByAngle(rpm, &tdcScheduler[revIndex2], tdcPosition(), @@ -263,7 +263,7 @@ float getCrankshaftAngleNt(efitime_t timeNt DECLARE_ENGINE_PARAMETER_S) { * compiler is not smart enough to figure out that "A / ( B / C)" could be optimized into * "A * C / B" in order to replace a slower division with a faster multiplication. */ - int rpm = engine->rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F); + int rpm = engine->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F); return rpm == 0 ? NAN : timeSinceZeroAngleNt / getOneDegreeTimeNt(rpm); } diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index 15aa369ece..c7dae7d613 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -41,7 +41,7 @@ public: * Please note that this is a relatively heavy method due to getTimeNowNt() usage */ bool isRunning(DECLARE_ENGINE_PARAMETER_F); - int rpm(DECLARE_ENGINE_PARAMETER_F); + int getRpm(DECLARE_ENGINE_PARAMETER_F); /** * This method is invoked once per engine cycle right after we calculate new RPM value */ @@ -73,12 +73,10 @@ private: volatile uint32_t revolutionCounterSinceStart; }; -#define getRpm() getRpmE(engine) - /** * @brief Current RPM */ -#define getRpmE(engine) (engine)->rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F) +#define getRpmE(engine) (engine)->rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F) bool isCrankingE(Engine *engine); void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_S); diff --git a/firmware/development/wave_analyzer.cpp b/firmware/development/wave_analyzer.cpp index ffc5c3e727..975d14b9cd 100644 --- a/firmware/development/wave_analyzer.cpp +++ b/firmware/development/wave_analyzer.cpp @@ -227,7 +227,7 @@ static void reportWave(Logging *logging, int index) { appendPrintf(logging, "%s", DELIMETER); uint32_t offsetUs = getWaveOffset(index); - int rpm = getRpm(); + int rpm = getRpmE(engine); float oneDegreeUs = rpm == 0 ? NAN : getOneDegreeTimeUs(rpm); appendPrintf(logging, "advance%d%s", index, DELIMETER); diff --git a/firmware/hw_layer/can_hw.cpp b/firmware/hw_layer/can_hw.cpp index dabc236ad0..7005861ce2 100644 --- a/firmware/hw_layer/can_hw.cpp +++ b/firmware/hw_layer/can_hw.cpp @@ -214,7 +214,7 @@ static void canRead(void) { } static void writeStateToCan(void) { - engine_rpm = getRpm(); + engine_rpm = getRpmE(engine); engine_clt = 123; //getCoolantTemperature(engine); canInfoNBCBroadcast(engineConfiguration->canNbcType); diff --git a/unit_tests/test_speed_density.cpp b/unit_tests/test_speed_density.cpp index bccc22ffd0..fb54f93f6b 100644 --- a/unit_tests/test_speed_density.cpp +++ b/unit_tests/test_speed_density.cpp @@ -19,7 +19,7 @@ void testSpeedDensity(void) { eth.initTriggerShapeAndRpmCalculator(); eth.fireTriggerEvents(); - assertEqualsM("RPM", 1500, eth.engine.rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F)); + assertEqualsM("RPM", 1500, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F)); // 427 cubic inches, that's a LOT of engine eth.ec->specs.displacement = 6.99728; diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index 22b8a28f6d..cc610e1d10 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -300,10 +300,10 @@ static void testRpmCalculator(void) { engine->updateSlowSensors(PASS_ENGINE_PARAMETER_F); timeNow = 0; - assertEquals(0, eth.engine.rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F)); + assertEquals(0, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F)); eth.fireTriggerEvents(); - assertEqualsM("RPM", 1500, eth.engine.rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F)); + assertEqualsM("RPM", 1500, eth.engine.rpmCalculator.getRpm(PASS_ENGINE_PARAMETER_F)); assertEqualsM("index #1", 15, eth.engine.triggerCentral.triggerState.getCurrentIndex()); static MainTriggerCallback triggerCallbackInstance;