From 93b034b8e968da4df35636f11a2784a978f009bc Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Wed, 27 Jan 2021 18:28:53 -0800 Subject: [PATCH] Limp handles inj/ign disable (#2245) * status loop just asks limp mgr * put logic in limp manager * don't need that function any more * bye * TIL these bits already exist in the configuration --- firmware/console/status_loop.cpp | 4 +-- .../engine_cycle/main_trigger_callback.cpp | 4 +-- .../controllers/engine_cycle/spark_logic.cpp | 5 ---- .../controllers/engine_cycle/spark_logic.h | 1 - firmware/controllers/limp_manager.cpp | 29 ++++++++++++------- firmware/controllers/limp_manager.h | 7 +++-- 6 files changed, 26 insertions(+), 24 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index b370f48255..35b2dcac5c 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -681,8 +681,8 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ tsOutputChannels->isFuelPumpOn = enginePins.fuelPumpRelay.getLogicValue(); tsOutputChannels->isFanOn = enginePins.fanRelay.getLogicValue(); tsOutputChannels->isO2HeaterOn = enginePins.o2heater.getLogicValue(); - tsOutputChannels->isIgnitionEnabledIndicator = engineConfiguration->isIgnitionEnabled && ENGINE(limpManager).allowIgnition(); - tsOutputChannels->isInjectionEnabledIndicator = engineConfiguration->isInjectionEnabled && ENGINE(limpManager).allowInjection(); + tsOutputChannels->isIgnitionEnabledIndicator = ENGINE(limpManager).allowIgnition(); + tsOutputChannels->isInjectionEnabledIndicator = ENGINE(limpManager).allowInjection(); tsOutputChannels->isCylinderCleanupEnabled = engineConfiguration->isCylinderCleanupEnabled; tsOutputChannels->isCylinderCleanupActivated = engine->isCylinderCleanupMode; diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index ed6cd8c861..91c0f1d5f6 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -320,7 +320,7 @@ static void handleFuel(const bool limitedFuel, uint32_t trgEventIndex, int rpm, efiAssertVoid(CUSTOM_STACK_6627, getCurrentRemainingStack() > 128, "lowstck#3"); efiAssertVoid(CUSTOM_ERR_6628, trgEventIndex < engine->engineCycleEventCount, "handleFuel/event index"); - if (!isInjectionEnabled(PASS_ENGINE_PARAMETER_SIGNATURE) || limitedFuel) { + if (limitedFuel) { return; } if (ENGINE(isCylinderCleanupMode)) { @@ -554,8 +554,6 @@ void initMainEventListener(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX addConsoleActionP("maininfo", (VoidPtr) showMainInfo, engine); printMsg(logger, "initMainLoop: %d", currentTimeMillis()); - if (!isInjectionEnabled(PASS_ENGINE_PARAMETER_SIGNATURE)) - printMsg(logger, "!!!!!!!!!!!!!!!!!!! injection disabled"); #endif diff --git a/firmware/controllers/engine_cycle/spark_logic.cpp b/firmware/controllers/engine_cycle/spark_logic.cpp index 792c7df6aa..ad4d592ada 100644 --- a/firmware/controllers/engine_cycle/spark_logic.cpp +++ b/firmware/controllers/engine_cycle/spark_logic.cpp @@ -35,11 +35,6 @@ static Logging *logger; static const char *prevSparkName = nullptr; -int isInjectionEnabled(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - // todo: is this worth a method? should this be inlined? - return CONFIG(isInjectionEnabled); -} - int isIgnitionTimingError(void) { return ignitionErrorDetection.sum(6) > 4; } diff --git a/firmware/controllers/engine_cycle/spark_logic.h b/firmware/controllers/engine_cycle/spark_logic.h index ef7bfcb238..c70eee7abf 100644 --- a/firmware/controllers/engine_cycle/spark_logic.h +++ b/firmware/controllers/engine_cycle/spark_logic.h @@ -9,7 +9,6 @@ #include "engine.h" -int isInjectionEnabled(DECLARE_ENGINE_PARAMETER_SIGNATURE); void onTriggerEventSparkLogic(bool limitedSpark, uint32_t trgEventIndex, int rpm, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX); void initSparkLogic(Logging *sharedLogger); void turnSparkPinHigh(IgnitionEvent *event); diff --git a/firmware/controllers/limp_manager.cpp b/firmware/controllers/limp_manager.cpp index 069e6592ea..ae87ca9d57 100644 --- a/firmware/controllers/limp_manager.cpp +++ b/firmware/controllers/limp_manager.cpp @@ -5,27 +5,34 @@ EXTERN_ENGINE; void LimpManager::updateState(int rpm) { - // User-configured hard RPM limit - bool isRevLimited = rpm > engine->getRpmHardLimit(PASS_ENGINE_PARAMETER_SIGNATURE); + Clearable allowFuel = CONFIG(isInjectionEnabled); + Clearable allowSpark = CONFIG(isIgnitionEnabled); - // TODO: user configurable what gets limited - bool limitFuel = isRevLimited; - bool limitSpark = isRevLimited; + // User-configured hard RPM limit + if (rpm > engine->getRpmHardLimit(PASS_ENGINE_PARAMETER_SIGNATURE)) { + if (CONFIG(cutFuelOnHardLimit)) { + allowFuel.clear(); + } + + if (CONFIG(cutSparkOnHardLimit)) { + allowSpark.clear(); + } + } // Force fuel limiting on the fault rev limit if (rpm > m_faultRevLimit) { - limitFuel = true; + allowFuel.clear(); } // Limit fuel only on boost pressure (limiting spark bends valves) if (CONFIG(boostCutPressure) != 0) { if (Sensor::get(SensorType::Map).value_or(0) > CONFIG(boostCutPressure)) { - limitFuel = true; + allowFuel.clear(); } } - m_transientLimitInjection = limitFuel; - m_transientLimitIgnition = limitSpark; + m_transientAllowInjection = allowFuel; + m_transientAllowIgnition = allowSpark; } void LimpManager::etbProblem() { @@ -57,9 +64,9 @@ bool LimpManager::allowTriggerInput() const { } bool LimpManager::allowInjection() const { - return !m_transientLimitInjection && m_allowInjection; + return m_transientAllowInjection && m_allowInjection; } bool LimpManager::allowIgnition() const { - return !m_transientLimitIgnition && m_allowIgnition; + return m_transientAllowIgnition && m_allowIgnition; } diff --git a/firmware/controllers/limp_manager.h b/firmware/controllers/limp_manager.h index 183524b77d..5a8db594ea 100644 --- a/firmware/controllers/limp_manager.h +++ b/firmware/controllers/limp_manager.h @@ -7,6 +7,9 @@ // Only allows clearing the value, but never resetting it. class Clearable { public: + Clearable() : m_value(true) {} + Clearable(bool value) : m_value(value) {} + void clear() { m_value = false; } @@ -49,6 +52,6 @@ private: Clearable m_allowIgnition; Clearable m_allowTriggerInput; - bool m_transientLimitInjection = false; - bool m_transientLimitIgnition = false; + bool m_transientAllowInjection = true; + bool m_transientAllowIgnition = true; };