From 77ebc71f9a061c8a88089dd4a9a517a8cec95b7f Mon Sep 17 00:00:00 2001 From: rusefillc <48498823+rusefillc@users.noreply.github.com> Date: Sat, 2 Oct 2021 01:17:53 -0400 Subject: [PATCH] overdwell protection #3071 (#3294) --- firmware/controllers/engine_cycle/spark_logic.cpp | 13 ++++++++++++- .../ignition_injection/test_ignition_scheduling.cpp | 3 +++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index e751d2e19a..5bb494d327 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -139,6 +139,13 @@ static void fireTrailingSpark(IgnitionOutputPin* pin) { pin->setLow(); } +static void overFireSparkAndPrepareNextSchedule(IgnitionEvent *event) { +#if SPARK_EXTREME_LOGGING + efiPrintf("overFireSparkAndPrepareNextSchedule %s", event->outputs[0]->name); +#endif /* SPARK_EXTREME_LOGGING */ + fireSparkAndPrepareNextSchedule(event); +} + void fireSparkAndPrepareNextSchedule(IgnitionEvent *event) { for (int i = 0; i< MAX_OUTPUTS_FOR_IGNITION;i++) { IgnitionOutputPin *output = event->outputs[i]; @@ -202,6 +209,9 @@ if (engineConfiguration->debugMode == DBG_DWELL_METRIC) { efitick_t nextDwellStart = nowNt + engine->engineState.multispark.delay; efitick_t nextFiring = nextDwellStart + engine->engineState.multispark.dwell; +#if SPARK_EXTREME_LOGGING + efiPrintf("schedule multispark"); +#endif /* SPARK_EXTREME_LOGGING */ // We can schedule both of these right away, since we're going for "asap" not "particular angle" engine->executor.scheduleByTimestampNt("dwell", &event->dwellStartTimer, nextDwellStart, { &turnSparkPinHigh, event }); @@ -424,7 +434,8 @@ static void handleSparkEvent(bool limitedSpark, uint32_t trgEventIndex, Ignition if (!limitedSpark && engine->enableOverdwellProtection) { // auto fire spark at 1.5x nominal dwell efitick_t fireTime = chargeTime + MSF2NT(1.5f * dwellMs); - engine->executor.scheduleByTimestampNt("overdwell", &event->sparkEvent.scheduling, fireTime, { fireSparkAndPrepareNextSchedule, event }); + engine->executor.scheduleByTimestampNt("overdwell", &event->sparkEvent.scheduling, fireTime, { overFireSparkAndPrepareNextSchedule, event }); + } } } diff --git a/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp b/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp index f8147640eb..c5168202d5 100644 --- a/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp +++ b/unit_tests/tests/ignition_injection/test_ignition_scheduling.cpp @@ -40,7 +40,10 @@ TEST(ignition, twoCoils) { TEST(ignition, trailingSpark) { WITH_ENGINE_TEST_HELPER(TEST_ENGINE); + /** // TODO #3220: this feature makes this test sad, eventually remove this line (and the ability to disable it altogether) + * I am pretty sure that it's about usage of improper method clearQueue() below see it's comment + */ engine->enableOverdwellProtection = false; EXPECT_CALL(eth.mockAirmass, getAirmass(_))