From b3de217c1bc2cc4803e7da47bdda49e423311e0a Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Fri, 31 Dec 2021 00:21:21 -0600 Subject: [PATCH] adjustment to #3722 (#3723) * s * behold, another bug a test caught * test * test generates usable trigger pattern so it works correctly * comment * don't need that --- firmware/config/engines/test_engine.cpp | 2 ++ .../controllers/engine_cycle/main_trigger_callback.cpp | 4 ++-- firmware/controllers/trigger/trigger_decoder.cpp | 6 ++++++ firmware/controllers/trigger/trigger_decoder.h | 9 +++++++++ unit_tests/tests/trigger/test_map_cam.cpp | 8 ++++++-- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/firmware/config/engines/test_engine.cpp b/firmware/config/engines/test_engine.cpp index 32106ed404..5da7e67a63 100644 --- a/firmware/config/engines/test_engine.cpp +++ b/firmware/config/engines/test_engine.cpp @@ -54,6 +54,8 @@ void setTestCamEngineConfiguration() { void setTestCrankEngineConfiguration() { setTestCamEngineConfiguration(); + engineConfiguration->trigger.type = TT_ONE; + setOperationMode(engineConfiguration, FOUR_STROKE_CRANK_SENSOR); } diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 8514ba0ca0..8847bd154d 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -335,7 +335,7 @@ static bool noFiringUntilVvtSync(vvt_mode_e vvtMode) { // V-Twin MAP phase sense needs to always wait for sync if (vvtMode == VVT_MAP_V_TWIN_ANOTHER) { - return false; + return true; } // Symmetrical crank modes require cam sync before firing @@ -352,7 +352,7 @@ void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp) { ScopePerf perf(PE::MainTriggerCallback); if (noFiringUntilVvtSync(engineConfiguration->vvtMode[0]) - && !engine->triggerCentral.vvtState[0][0].getShaftSynchronized()) { + && !engine->triggerCentral.triggerState.hasSynchronizedSymmetrical()) { // Any engine that requires cam-assistance for a full crank sync (symmetrical crank) can't schedule until we have cam sync // examples: // NB2, Nissan VQ/MR: symmetrical crank wheel and we need to make sure no spark happens out of sync diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 922cd62f08..30ec390cdc 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -80,6 +80,8 @@ void TriggerState::resetTriggerState() { totalEventCountBase = 0; isFirstEvent = true; + + m_hasSynchronizedSymmetrical = false; } void TriggerState::setTriggerErrorState() { @@ -404,6 +406,10 @@ angle_t TriggerState::syncSymmetricalCrank(int divider, int remainder, angle_t e incrementTotalEventCounter(); totalShift += engineCycle / divider; } + + // Allow injection/ignition to happen, we've now fully sync'd the crank based on new cam information + m_hasSynchronizedSymmetrical = true; + return totalShift; } diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 33c12d1a93..35a8ce7396 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -155,6 +155,13 @@ public: const trigger_config_s& triggerConfig ); + // Returns true if syncSymmetricalCrank has been called, + // ie if we have enough VVT information to have full sync on + // an indeterminite crank pattern + bool hasSynchronizedSymmetrical() const { + return m_hasSynchronizedSymmetrical; + } + private: void resetCurrentCycleState(); bool isSyncPoint(const TriggerWaveform& triggerShape, trigger_type_e triggerType) const; @@ -164,6 +171,8 @@ private: int64_t totalEventCountBase; bool isFirstEvent; + + bool m_hasSynchronizedSymmetrical = false; }; // we only need 90 degrees of events so /4 or maybe even /8 should work? diff --git a/unit_tests/tests/trigger/test_map_cam.cpp b/unit_tests/tests/trigger/test_map_cam.cpp index 1497a1ec9b..59a5177ac3 100644 --- a/unit_tests/tests/trigger/test_map_cam.cpp +++ b/unit_tests/tests/trigger/test_map_cam.cpp @@ -15,17 +15,21 @@ TEST(trigger, map_cam_by_magic_point) { engineConfiguration->mapCamDetectionAnglePosition = 90; eth.smartFireTriggerEvents2(/*count*/10, /*delayMs*/200); - ASSERT_EQ( 75, GET_RPM()) << "RPM"; + ASSERT_EQ(150, GET_RPM()) << "RPM"; ASSERT_EQ(1, engine->outputChannels.TEMPLOG_map_peak); ASSERT_EQ(0, engine->outputChannels.vvtSyncCounter); + // Nothing should have been scheduled yet + ASSERT_EQ(0, engine->executor.size()); engine->outputChannels.instantMAPValue = 120; eth.smartFireTriggerEvents2(/*count*/4, /*delayMs*/200); ASSERT_EQ(2, engine->outputChannels.TEMPLOG_map_peak); ASSERT_EQ(1, engine->outputChannels.vvtSyncCounter); - ASSERT_EQ(6, engine->outputChannels.TEMPLOG_MAP_AT_CYCLE_COUNT); + ASSERT_EQ(10, engine->outputChannels.TEMPLOG_MAP_AT_CYCLE_COUNT); + // We have "VVT" sync, things should be scheduled! + ASSERT_NE(0, engine->executor.size()); }