diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 53ebd41247..98c1848038 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -15,6 +15,7 @@ #include "efiGpio.h" #include "trigger_central.h" #include "fuel_math.h" +#include "engine_math.h" #if EFI_PROD_CODE #include "injector_central.h" @@ -158,6 +159,13 @@ void Engine::watchdog() { #endif } +void Engine::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { + int rpm = rpmCalculator.rpmValue; + + engineState.sparkDwell = getSparkDwellMsT(rpm PASS_ENGINE_PARAMETER); + dwellAngle = engineState.sparkDwell / getOneDegreeTimeMs(rpm); +} + StartupFuelPumping::StartupFuelPumping() { isTpsAbove50 = false; pumpsCounter = 0; diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 034446e334..43302d4fbd 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -86,6 +86,15 @@ public: angle_t mapAveragingStart; angle_t mapAveragingDuration; + + // spark-related + float sparkDwell; + float timingAdvance; + + // fuel-related; + float iatFuelCorrection; + float cltFuelCorrection; + float injectorLag; }; class RpmCalculator; @@ -163,6 +172,8 @@ public: angle_t dwellAngle; angle_t advance; + void periodicFastCallback(DECLARE_ENGINE_PARAMETER_F); + bool_t clutchUpState; bool_t clutchDownState; diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 57956ff65e..aa1269b539 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -219,8 +219,6 @@ static void periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { if (isValidRpm(rpm)) { MAP_sensor_config_s * c = &engineConfiguration->map; - - engine->engineState.mapAveragingStart = interpolate2d(rpm, c->samplingAngleBins, c->samplingAngle, MAP_ANGLE_SIZE); engine->engineState.mapAveragingDuration = interpolate2d(rpm, c->samplingWindowBins, c->samplingWindow, MAP_WINDOW_SIZE); } else { @@ -228,6 +226,8 @@ static void periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { engine->engineState.mapAveragingDuration = NAN; } + engine->engineState.sparkDwell = getSparkDwellMsT(rpm PASS_ENGINE_PARAMETER); + chVTSetAny(&periodicFastTimer, 20 * TICKS_IN_MS, (vtfunc_t) &periodicFastCallback, engine); } diff --git a/firmware/controllers/trigger/main_trigger_callback.cpp b/firmware/controllers/trigger/main_trigger_callback.cpp index 2cc4f89110..a41b2db596 100644 --- a/firmware/controllers/trigger/main_trigger_callback.cpp +++ b/firmware/controllers/trigger/main_trigger_callback.cpp @@ -177,7 +177,7 @@ static ALWAYS_INLINE void handleFuel(uint32_t eventIndex, int rpm DECLARE_ENGINE static ALWAYS_INLINE void handleSparkEvent(uint32_t eventIndex, IgnitionEvent *iEvent, int rpm DECLARE_ENGINE_PARAMETER_S) { - float dwellMs = getSparkDwellMsT(rpm PASS_ENGINE_PARAMETER); + float dwellMs = engine->engineState.sparkDwell; if (cisnan(dwellMs) || dwellMs < 0) { firmwareError("invalid dwell: %f at %d", dwellMs, rpm); return; @@ -256,7 +256,7 @@ static ALWAYS_INLINE void handleSpark(uint32_t eventIndex, int rpm, scheduling_s * sDown = ¤t->signalTimerDown; - float timeTillIgnitionUs = engine->rpmCalculator.oneDegreeUs * current->sparkPosition.angleOffset; + float timeTillIgnitionUs = ENGINE(rpmCalculator.oneDegreeUs) * current->sparkPosition.angleOffset; scheduleTask("spark 2down", sDown, (int) timeTillIgnitionUs, (schfunc_t) &turnPinLow, current->output); } } diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 350b2c415d..868d089ca5 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -290,5 +290,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20150427; + return 20150428; } diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index ab14e4edcd..bb12f1cbc8 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -405,9 +405,12 @@ static void testRpmCalculator(void) { debugSignalExecutor = true; timeNow += 5000; // 5ms + + eth.engine.periodicFastCallback(PASS_ENGINE_PARAMETER_F); + eth.triggerCentral.handleShaftSignal(SHAFT_PRIMARY_UP PASS_ENGINE_PARAMETER); - assertEquals(4.5, eth.engine.dwellAngle); + assertEqualsM("dwell", 4.5, eth.engine.dwellAngle); assertEqualsM("fuel", 3.03, eth.engine.fuelMs); assertEqualsM("one degree", 111.1111, eth.engine.rpmCalculator.oneDegreeUs); assertEqualsM("size", 6, ilist->size);