From 4002c92dcc14a3d33400d33a61e453a9f1298880 Mon Sep 17 00:00:00 2001 From: Andrey Date: Mon, 15 Nov 2021 18:57:12 -0500 Subject: [PATCH] refactoring launch --- firmware/controllers/algo/engine.h | 2 ++ firmware/controllers/algo/engine2.cpp | 2 +- firmware/controllers/algo/launch_control.cpp | 8 +------ firmware/controllers/algo/launch_control.h | 2 -- .../engine_cycle/main_trigger_callback.cpp | 4 +--- unit_tests/tests/test_launch.cpp | 22 +++++++++---------- 6 files changed, 16 insertions(+), 24 deletions(-) diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index e79d368be6..df5916d0f8 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -23,6 +23,7 @@ #include "ac_control.h" #include "knock_logic.h" #include "idle_state_generated.h" +#include "launch_control.h" #if EFI_SIGNAL_EXECUTOR_ONE_TIMER // PROD real firmware uses this implementation @@ -109,6 +110,7 @@ public: cyclic_buffer triggerErrorDetection; GearControllerBase *gearController; + LaunchControlBase launchController; efitick_t mostRecentSparkEvent; efitick_t mostRecentTimeBetweenSparkEvents; diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 8302d54396..58b682fe70 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -169,7 +169,7 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { multispark.count = getMultiSparkCount(rpm PASS_ENGINE_PARAMETER_SUFFIX); #if EFI_LAUNCH_CONTROL - updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE); + engine->launchController.update(); #endif //EFI_LAUNCH_CONTROL engine->limpManager.updateState(rpm, nowNt); diff --git a/firmware/controllers/algo/launch_control.cpp b/firmware/controllers/algo/launch_control.cpp index 1b63ce09ea..862deb6ba9 100644 --- a/firmware/controllers/algo/launch_control.cpp +++ b/firmware/controllers/algo/launch_control.cpp @@ -17,8 +17,6 @@ static bool isInit = false; -LaunchControlBase launchInstance; - /** * We can have active condition from switch or from clutch. * In case we are dependent on VSS we just return true. @@ -98,10 +96,6 @@ bool LaunchControlBase::isLaunchConditionMet(int rpm) const { return speedCondition && activateSwitchCondition && rpmCondition && tpsCondition; } -void updateLaunchConditions(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - launchInstance.update(); -} - void LaunchControlBase::update() { if (!CONFIG(launchControlEnabled)) { @@ -180,7 +174,7 @@ void LaunchControlBase::applyLaunchControlLimiting(bool *limitedSpark, bool *lim } void initLaunchControl(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - launchInstance.inject(PASS_ENGINE_PARAMETER_SIGNATURE); + engine->launchController.inject(PASS_ENGINE_PARAMETER_SIGNATURE); isInit = true; } diff --git a/firmware/controllers/algo/launch_control.h b/firmware/controllers/algo/launch_control.h index da2a1f2066..e245ce07b0 100644 --- a/firmware/controllers/algo/launch_control.h +++ b/firmware/controllers/algo/launch_control.h @@ -13,8 +13,6 @@ void initLaunchControl(DECLARE_ENGINE_PARAMETER_SIGNATURE); void setDefaultLaunchParameters(DECLARE_CONFIG_PARAMETER_SIGNATURE); -void updateLaunchConditions(DECLARE_ENGINE_PARAMETER_SIGNATURE); - class LaunchControlBase : public EnginePtr { public: // Update the state of the launch control system diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index f028eacfe6..07d290a74c 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -49,8 +49,6 @@ #include "backup_ram.h" -extern LaunchControlBase launchInstance; - // todo: figure out if this even helps? //#if defined __GNUC__ //#define RAM_METHOD_PREFIX __attribute__((section(".ram"))) @@ -418,7 +416,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 */ - launchInstance.applyLaunchControlLimiting(&limitedSpark, &limitedFuel PASS_ENGINE_PARAMETER_SUFFIX); + engine->launchController.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 ddf6510abd..fc3d68b522 100644 --- a/unit_tests/tests/test_launch.cpp +++ b/unit_tests/tests/test_launch.cpp @@ -130,7 +130,6 @@ TEST(LaunchControl, CompleteRun) { bool spark, fuel; WITH_ENGINE_TEST_HELPER(TEST_ENGINE); - extern LaunchControlBase launchInstance; initLaunchControl(PASS_ENGINE_PARAMETER_SIGNATURE); //load default config @@ -149,46 +148,47 @@ TEST(LaunchControl, CompleteRun) { Sensor::setMockValue(SensorType::VehicleSpeed, 10.0); engine->rpmCalculator.mockRpm = 1200; - //update condition check - updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE); + engine->launchController.update(); + //check if we have some sort of cut? we should not have at this point spark = false; fuel = false; - launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); + engine->launchController.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); EXPECT_FALSE(spark); EXPECT_FALSE(fuel); engine->rpmCalculator.mockRpm = 3510; //update condition check - updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE); + engine->launchController.update(); //we have a 3 seconds delay to actually enable it! eth.moveTimeForwardAndInvokeEventsSec(1); - updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE); + engine->launchController.update(); + spark = false; fuel = false; - launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); + engine->launchController.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); EXPECT_FALSE(spark); EXPECT_FALSE(fuel); eth.moveTimeForwardAndInvokeEventsSec(3); - updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE); + engine->launchController.update(); spark = false; fuel = false; - launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); + engine->launchController.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); EXPECT_TRUE(spark); EXPECT_FALSE(fuel); Sensor::setMockValue(SensorType::VehicleSpeed, 40.0); - updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE); + engine->launchController.update(); spark = false; fuel = false; - launchInstance.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); + engine->launchController.applyLaunchControlLimiting(&spark, &fuel PASS_ENGINE_PARAMETER_SUFFIX); EXPECT_FALSE(spark); EXPECT_FALSE(fuel);