From ae0164950e2139bb8e674a76ceb55e4d9c24ed9a Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Thu, 2 May 2024 02:10:01 -0500 Subject: [PATCH 1/3] fix knock retard table init column and row definition were swapped w/re: value lookup fixes #246, #417 --- firmware/controllers/engine_cycle/knock_controller.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/controllers/engine_cycle/knock_controller.cpp b/firmware/controllers/engine_cycle/knock_controller.cpp index 8d5308b8c0..b75d35c998 100644 --- a/firmware/controllers/engine_cycle/knock_controller.cpp +++ b/firmware/controllers/engine_cycle/knock_controller.cpp @@ -11,7 +11,7 @@ void KnockController::onConfigurationChange(engine_configuration_s const * previousConfig) { KnockControllerBase::onConfigurationChange(previousConfig); - m_maxRetardTable.init(config->maxKnockRetardTable, config->maxKnockRetardRpmBins, config->maxKnockRetardLoadBins); + m_maxRetardTable.init(config->maxKnockRetardTable, config->maxKnockRetardLoadBins, config->maxKnockRetardRpmBins); } int getCylinderKnockBank(uint8_t cylinderNumber) { From dbe240bafbf8ff59268c3605c831df2befc4c180 Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Fri, 3 May 2024 19:16:12 -0500 Subject: [PATCH 2/3] initialize knock controller / max retard table on reset --- firmware/controllers/engine_controller.cpp | 2 ++ firmware/controllers/engine_cycle/knock_controller.cpp | 10 +++++++++- firmware/controllers/engine_cycle/knock_logic.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index ca427aa2eb..bbd54fcc6d 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -490,6 +490,8 @@ void commonInitEngineController() { initTachometer(); initSpeedometer(); + + initKnockCtrl(); } // Returns false if there's an obvious problem with the loaded configuration diff --git a/firmware/controllers/engine_cycle/knock_controller.cpp b/firmware/controllers/engine_cycle/knock_controller.cpp index b75d35c998..d15d55d3f5 100644 --- a/firmware/controllers/engine_cycle/knock_controller.cpp +++ b/firmware/controllers/engine_cycle/knock_controller.cpp @@ -8,10 +8,14 @@ #include "pch.h" #include "knock_logic.h" +void KnockController::init(engine_configuration_s const * const previousConfig) { + m_maxRetardTable.init(config->maxKnockRetardTable, config->maxKnockRetardLoadBins, config->maxKnockRetardRpmBins); +} + void KnockController::onConfigurationChange(engine_configuration_s const * previousConfig) { KnockControllerBase::onConfigurationChange(previousConfig); - m_maxRetardTable.init(config->maxKnockRetardTable, config->maxKnockRetardLoadBins, config->maxKnockRetardRpmBins); + init(previousConfig); } int getCylinderKnockBank(uint8_t cylinderNumber) { @@ -161,3 +165,7 @@ void Engine::onSparkFireKnockSense(uint8_t cylinderNumber, efitick_t nowNt) { UNUSED(nowNt); #endif } + +void initKnockCtrl() { + engine->module().unmock().init(engineConfiguration); +} diff --git a/firmware/controllers/engine_cycle/knock_logic.h b/firmware/controllers/engine_cycle/knock_logic.h index e460aac912..cadb3d9c35 100644 --- a/firmware/controllers/engine_cycle/knock_logic.h +++ b/firmware/controllers/engine_cycle/knock_logic.h @@ -41,6 +41,7 @@ class KnockController : public KnockControllerBase { KnockController() { } + void init(engine_configuration_s const * const previousConfig); void onConfigurationChange(engine_configuration_s const * /*previousConfig*/) override; @@ -50,3 +51,5 @@ class KnockController : public KnockControllerBase { private: Map3D<6, 6, uint8_t, uint8_t, uint8_t> m_maxRetardTable; }; + +void initKnockCtrl(); From 365e32203737ee1c2aa52eb0b596f48c5e160668 Mon Sep 17 00:00:00 2001 From: Nathan Schulte Date: Fri, 3 May 2024 21:55:52 -0500 Subject: [PATCH 3/3] fix KnockController init no need for previousConfig (or any config ref); use the current config --- firmware/controllers/engine_cycle/knock_controller.cpp | 6 +++--- firmware/controllers/engine_cycle/knock_logic.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/firmware/controllers/engine_cycle/knock_controller.cpp b/firmware/controllers/engine_cycle/knock_controller.cpp index d15d55d3f5..a914c60919 100644 --- a/firmware/controllers/engine_cycle/knock_controller.cpp +++ b/firmware/controllers/engine_cycle/knock_controller.cpp @@ -8,14 +8,14 @@ #include "pch.h" #include "knock_logic.h" -void KnockController::init(engine_configuration_s const * const previousConfig) { +void KnockController::init() { m_maxRetardTable.init(config->maxKnockRetardTable, config->maxKnockRetardLoadBins, config->maxKnockRetardRpmBins); } void KnockController::onConfigurationChange(engine_configuration_s const * previousConfig) { KnockControllerBase::onConfigurationChange(previousConfig); - init(previousConfig); + init(); } int getCylinderKnockBank(uint8_t cylinderNumber) { @@ -167,5 +167,5 @@ void Engine::onSparkFireKnockSense(uint8_t cylinderNumber, efitick_t nowNt) { } void initKnockCtrl() { - engine->module().unmock().init(engineConfiguration); + engine->module().unmock().init(); } diff --git a/firmware/controllers/engine_cycle/knock_logic.h b/firmware/controllers/engine_cycle/knock_logic.h index cadb3d9c35..6a33e74f58 100644 --- a/firmware/controllers/engine_cycle/knock_logic.h +++ b/firmware/controllers/engine_cycle/knock_logic.h @@ -41,7 +41,7 @@ class KnockController : public KnockControllerBase { KnockController() { } - void init(engine_configuration_s const * const previousConfig); + void init(); void onConfigurationChange(engine_configuration_s const * /*previousConfig*/) override;