From 34015eceee568d2b44f954ba01b1cac3977b5d2a Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 15 Nov 2021 14:40:35 -0500 Subject: [PATCH] refactoring launch --- firmware/controllers/algo/launch_control.cpp | 6 ++---- firmware/controllers/algo/launch_control.h | 4 +++- .../controllers/engine_cycle/main_trigger_callback.cpp | 4 +++- unit_tests/tests/test_launch.cpp | 9 +++++---- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/firmware/controllers/algo/launch_control.cpp b/firmware/controllers/algo/launch_control.cpp index e163294536..1b63ce09ea 100644 --- a/firmware/controllers/algo/launch_control.cpp +++ b/firmware/controllers/algo/launch_control.cpp @@ -17,9 +17,7 @@ static bool isInit = false; -static LaunchControlBase launchInstance; - -static int retardThresholdRpm; +LaunchControlBase launchInstance; /** * We can have active condition from switch or from clutch. @@ -174,7 +172,7 @@ void setDefaultLaunchParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE) { } -void applyLaunchControlLimiting(bool *limitedSpark, bool *limitedFuel DECLARE_ENGINE_PARAMETER_SUFFIX) { +void LaunchControlBase::applyLaunchControlLimiting(bool *limitedSpark, bool *limitedFuel DECLARE_ENGINE_PARAMETER_SUFFIX) { if (( engine->isLaunchCondition ) && ( retardThresholdRpm < GET_RPM() )) { *limitedSpark = engineConfiguration->launchSparkCutEnable; *limitedFuel = engineConfiguration->launchFuelCutEnable; diff --git a/firmware/controllers/algo/launch_control.h b/firmware/controllers/algo/launch_control.h index 0916b808b5..da2a1f2066 100644 --- a/firmware/controllers/algo/launch_control.h +++ b/firmware/controllers/algo/launch_control.h @@ -12,7 +12,7 @@ void initLaunchControl(DECLARE_ENGINE_PARAMETER_SIGNATURE); void setDefaultLaunchParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE); -void applyLaunchControlLimiting(bool *limitedSpark, bool *limitedFuel DECLARE_ENGINE_PARAMETER_SUFFIX); + void updateLaunchConditions(DECLARE_ENGINE_PARAMETER_SIGNATURE); class LaunchControlBase : public EnginePtr { @@ -25,6 +25,8 @@ public: bool isInsideSwitchCondition() const; bool isInsideRPMCondition(int rpm) const; bool isLaunchConditionMet(int rpm) const; + int retardThresholdRpm; + void applyLaunchControlLimiting(bool *limitedSpark, bool *limitedFuel DECLARE_ENGINE_PARAMETER_SUFFIX); private: Timer m_launchTimer; diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 464980daa2..f028eacfe6 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -49,6 +49,8 @@ #include "backup_ram.h" +extern LaunchControlBase launchInstance; + // todo: figure out if this even helps? //#if defined __GNUC__ //#define RAM_METHOD_PREFIX __attribute__((section(".ram"))) @@ -416,7 +418,7 @@ void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp DECLARE #if EFI_LAUNCH_CONTROL if (engine->isLaunchCondition && !limitedSpark && !limitedFuel) { /* in case we are not already on a limited conditions, check launch as well */ - applyLaunchControlLimiting(&limitedSpark, &limitedFuel PASS_ENGINE_PARAMETER_SUFFIX); + launchInstance.applyLaunchControlLimiting(&limitedSpark, &limitedFuel PASS_ENGINE_PARAMETER_SUFFIX); } #endif if (trgEventIndex == 0) { diff --git a/unit_tests/tests/test_launch.cpp b/unit_tests/tests/test_launch.cpp index 00898bda3c..ddf6510abd 100644 --- a/unit_tests/tests/test_launch.cpp +++ b/unit_tests/tests/test_launch.cpp @@ -130,6 +130,7 @@ TEST(LaunchControl, CompleteRun) { bool spark, fuel; WITH_ENGINE_TEST_HELPER(TEST_ENGINE); + extern LaunchControlBase launchInstance; initLaunchControl(PASS_ENGINE_PARAMETER_SIGNATURE); //load default config @@ -154,7 +155,7 @@ TEST(LaunchControl, CompleteRun) { //check if we have some sort of cut? we should not have at this point spark = false; fuel = false; - applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); + launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); EXPECT_FALSE(spark); EXPECT_FALSE(fuel); @@ -169,7 +170,7 @@ TEST(LaunchControl, CompleteRun) { updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE); spark = false; fuel = false; - applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); + launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); EXPECT_FALSE(spark); EXPECT_FALSE(fuel); @@ -178,7 +179,7 @@ TEST(LaunchControl, CompleteRun) { updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE); spark = false; fuel = false; - applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); + launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); EXPECT_TRUE(spark); EXPECT_FALSE(fuel); @@ -187,7 +188,7 @@ TEST(LaunchControl, CompleteRun) { updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE); spark = false; fuel = false; - applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); + launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); EXPECT_FALSE(spark); EXPECT_FALSE(fuel);