From 5c96277fbfa63c8e16ecc44ddbc3a2b28ce0b525 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Wed, 3 Dec 2014 16:03:09 -0600 Subject: [PATCH] auto-sync --- firmware/controllers/algo/engine.cpp | 2 +- firmware/controllers/map_averaging.cpp | 4 +--- .../trigger/main_trigger_callback.cpp | 2 +- firmware/controllers/trigger/rpm_calculator.cpp | 16 ++++++++-------- firmware/controllers/trigger/rpm_calculator.h | 8 ++++---- firmware/global.h | 3 ++- unit_tests/test_speed_density.cpp | 4 +++- unit_tests/test_trigger_decoder.cpp | 4 ++-- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 66e947c3d3..5ab169b140 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -123,7 +123,7 @@ void StartupFuelPumping::setPumpsCounter(engine_configuration_s *engineConfigura } void StartupFuelPumping::update(DECLARE_ENGINE_PARAMETER_F) { - if (engine->rpmCalculator.rpm() == 0) { + if (engine->rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F) == 0) { bool isTpsAbove50 = getTPS(PASS_ENGINE_PARAMETER_F) >= 50; if (this->isTpsAbove50 != isTpsAbove50) { diff --git a/firmware/controllers/map_averaging.cpp b/firmware/controllers/map_averaging.cpp index 49769adfce..3e8175970a 100644 --- a/firmware/controllers/map_averaging.cpp +++ b/firmware/controllers/map_averaging.cpp @@ -66,8 +66,6 @@ static float v_averagedMapValue; EXTERN_ENGINE; -extern engine_configuration_s *engineConfiguration; - static scheduling_s startTimer[2]; static scheduling_s endTimer[2]; @@ -100,7 +98,7 @@ void mapAveragingCallback(adcsample_t value) { #if EFI_ANALOG_CHART if (engineConfiguration->analogChartMode == AC_MAP) if (perRevolutionCounter % FAST_MAP_CHART_SKIP_FACTOR == 0) - acAddData(getCrankshaftAngleNt(engine, getTimeNowNt()), currentPressure); + acAddData(getCrankshaftAngleNt(getTimeNowNt() PASS_ENGINE_PARAMETER), currentPressure); #endif /* EFI_ANALOG_CHART */ chSysLockFromIsr() diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index dcfdaada6d..8cc048a32d 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -406,8 +406,8 @@ void MainTriggerCallback::init(Engine *engine, engine_configuration2_s *engineCo } static void showMainInfo(Engine *engine) { - int rpm = engine->rpmCalculator.rpm(); #if EFI_PROD_CODE + int rpm = engine->rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F); float el = getEngineLoadT(PASS_ENGINE_PARAMETER); scheduleMsg(&logger, "rpm %d engine_load %f", rpm, el); scheduleMsg(&logger, "fuel %fms timing %f", getFuelMs(rpm PASS_ENGINE_PARAMETER), diff --git a/firmware/controllers/trigger/rpm_calculator.cpp b/firmware/controllers/trigger/rpm_calculator.cpp index f4a3d0df17..65b21af92c 100644 --- a/firmware/controllers/trigger/rpm_calculator.cpp +++ b/firmware/controllers/trigger/rpm_calculator.cpp @@ -62,7 +62,7 @@ RpmCalculator::RpmCalculator() { /** * @return true if there was a full shaft revolution within the last second */ -bool RpmCalculator::isRunning(void) { +bool RpmCalculator::isRunning(DECLARE_ENGINE_PARAMETER_F) { uint64_t nowNt = getTimeNowNt(); return nowNt - lastRpmEventTimeNt < US2NT(US_PER_SECOND); } @@ -96,12 +96,12 @@ uint32_t RpmCalculator::getRevolutionCounterSinceStart(void) { */ // todo: migrate to float return result or add a float verion? this would have with calculations // todo: add a version which does not check time & saves time? need to profile -int RpmCalculator::rpm(void) { +int RpmCalculator::rpm(DECLARE_ENGINE_PARAMETER_F) { #if !EFI_PROD_CODE if (mockRpm != MOCK_UNDEFINED) return mockRpm; #endif - if (!isRunning()) { + if (!isRunning(PASS_ENGINE_PARAMETER_F)) { revolutionCounterSinceStart = 0; return 0; } @@ -141,12 +141,12 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index DECL if (index != 0) { #if EFI_ANALOG_CHART || defined(__DOXYGEN__) if (engineConfiguration->analogChartMode == AC_TRIGGER) - acAddData(getCrankshaftAngleNt(engine, nowNt), 1000 * ckpSignalType + index); + acAddData(getCrankshaftAngleNt(nowNt PASS_ENGINE_PARAMETER), 1000 * ckpSignalType + index); #endif return; } - bool hadRpmRecently = rpmState->isRunning(); + bool hadRpmRecently = rpmState->isRunning(PASS_ENGINE_PARAMETER_F); if (hadRpmRecently) { uint64_t diffNt = nowNt - rpmState->lastRpmEventTimeNt; @@ -169,7 +169,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index DECL rpmState->lastRpmEventTimeNt = nowNt; #if EFI_ANALOG_CHART || defined(__DOXYGEN__) if (engineConfiguration->analogChartMode == AC_TRIGGER) - acAddData(getCrankshaftAngleNt(engine, nowNt), index); + acAddData(getCrankshaftAngleNt(nowNt PASS_ENGINE_PARAMETER), index); #endif } @@ -212,7 +212,7 @@ int getRevolutionCounter() { /** * @return Current crankshaft angle, 0 to 720 for four-stroke */ -float getCrankshaftAngleNt(Engine *engine, uint64_t timeNt) { +float getCrankshaftAngleNt(uint64_t timeNt DECLARE_ENGINE_PARAMETER_S) { uint64_t timeSinceZeroAngleNt = timeNt - engine->rpmCalculator.lastRpmEventTimeNt; /** @@ -220,7 +220,7 @@ float getCrankshaftAngleNt(Engine *engine, uint64_t timeNt) { * 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. */ - return timeSinceZeroAngleNt / getOneDegreeTimeNt(engine->rpmCalculator.rpm()); + return timeSinceZeroAngleNt / getOneDegreeTimeNt(engine->rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F)); } void initRpmCalculator(Engine *engine) { diff --git a/firmware/controllers/trigger/rpm_calculator.h b/firmware/controllers/trigger/rpm_calculator.h index a5caa2e90d..6f231e4e4f 100644 --- a/firmware/controllers/trigger/rpm_calculator.h +++ b/firmware/controllers/trigger/rpm_calculator.h @@ -31,8 +31,8 @@ public: int mockRpm; #endif RpmCalculator(); - bool isRunning(void); - int rpm(void); + bool isRunning(DECLARE_ENGINE_PARAMETER_F); + int rpm(DECLARE_ENGINE_PARAMETER_F); void onNewEngineCycle(); uint32_t getRevolutionCounter(void); void setRpmValue(int value); @@ -60,7 +60,7 @@ private: /** * @brief Current RPM */ -#define getRpmE(engine) (engine)->rpmCalculator.rpm() +#define getRpmE(engine) (engine)->rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F) bool isCrankingE(Engine *engine); void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_S); @@ -69,7 +69,7 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index DECL */ void initRpmCalculator(Engine *engine); -float getCrankshaftAngleNt(Engine *engine, uint64_t timeNt); +float getCrankshaftAngleNt(uint64_t timeNt DECLARE_ENGINE_PARAMETER_S); #endif #ifdef __cplusplus diff --git a/firmware/global.h b/firmware/global.h index ed78cd67b5..69609d9ed8 100644 --- a/firmware/global.h +++ b/firmware/global.h @@ -73,7 +73,8 @@ typedef Thread thread_t; extern engine_configuration_s *engineConfiguration; \ extern board_configuration_s *boardConfiguration; \ extern persistent_config_container_s persistentState; \ - extern Engine _engine + extern Engine _engine; \ + extern engine_configuration2_s * engineConfiguration2 #define DECLARE_ENGINE_PARAMETER_F void #define DECLARE_ENGINE_PARAMETER_S diff --git a/unit_tests/test_speed_density.cpp b/unit_tests/test_speed_density.cpp index bde7d2cc06..f0703c4b47 100644 --- a/unit_tests/test_speed_density.cpp +++ b/unit_tests/test_speed_density.cpp @@ -13,12 +13,14 @@ void testSpeedDensity(void) { printf("*************************************************** testSpeedDensity\r\n"); EngineTestHelper eth(FORD_INLINE_6_1995); + Engine *engine = ð.engine; + engine_configuration_s *engineConfiguration = engine->engineConfiguration; eth.ec->triggerConfig.customTotalToothCount = 8; eth.initTriggerShapeAndRpmCalculator(); eth.fireTriggerEvents(); - assertEqualsM("RPM", 1500, eth.engine.rpmCalculator.rpm()); + assertEqualsM("RPM", 1500, eth.engine.rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F)); // 427 cubic inches, that's a LOT of engine eth.ec->displacement = 6.99728; diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index 6267ca6d39..9120758de6 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -401,10 +401,10 @@ static void testRpmCalculator(void) { eth.engine.engineConfiguration->injectorLag = 0.0; timeNow = 0; - assertEquals(0, eth.engine.rpmCalculator.rpm()); + assertEquals(0, eth.engine.rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F)); eth.fireTriggerEvents(); - assertEqualsM("RPM", 1500, eth.engine.rpmCalculator.rpm()); + assertEqualsM("RPM", 1500, eth.engine.rpmCalculator.rpm(PASS_ENGINE_PARAMETER_F)); assertEqualsM("index #1", 15, eth.triggerCentral.triggerState.getCurrentIndex()); static MainTriggerCallback triggerCallbackInstance;