diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index b3853d3ccd..73f3c8a454 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -354,15 +354,6 @@ Engine::Engine() { reset(); } -/** - * @see scheduleStopEngine() - * @return true if there is a reason to stop engine - */ -bool Engine::needToStopEngine(efitick_t nowNt) const { - return stopEngineRequestTimeNt != 0 && - nowNt - stopEngineRequestTimeNt < 3 * NT_PER_SECOND; -} - int Engine::getGlobalConfigurationVersion(void) const { return globalConfigurationVersion; } @@ -537,6 +528,7 @@ void Engine::checkShutdown() { // here we are in the shutdown (the ignition is off) or initial mode (after the firmware fresh start) const efitick_t engineStopWaitTimeoutUs = 500000LL; // 0.5 sec // in shutdown mode, we need a small cooldown time between the ignition off and on +/* this needs work or tests if (stopEngineRequestTimeNt == 0 || (getTimeNowNt() - stopEngineRequestTimeNt) > US2NT(engineStopWaitTimeoutUs)) { // if the ignition key is turned on again, // we cancel the shutdown mode, but only if all shutdown procedures are complete @@ -552,6 +544,7 @@ void Engine::checkShutdown() { } } } +*/ #endif /* EFI_MAIN_RELAY_CONTROL */ } @@ -563,7 +556,8 @@ bool Engine::isInMainRelayBench() { } bool Engine::isInShutdownMode() const { -#if EFI_MAIN_RELAY_CONTROL && EFI_PROD_CODE + // TODO: this logic is currently broken +#if 0 && EFI_MAIN_RELAY_CONTROL && EFI_PROD_CODE // if we are in "ignition_on" mode and not in shutdown mode if (stopEngineRequestTimeNt == 0 && ignitionOnTimeNt > 0) { const float vBattThresholdOff = 5.0f; @@ -661,7 +655,7 @@ void Engine::periodicFastCallback() { void doScheduleStopEngine() { efiPrintf("Starting doScheduleStopEngine"); - engine->stopEngineRequestTimeNt = getTimeNowNt(); + engine->limpManager.stopEngine(); engine->ignitionOnTimeNt = 0; // todo: initiate stepper motor parking // make sure we have stored all the info diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index c3ce0ed5fa..196ba585b6 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -274,7 +274,6 @@ public: scheduling_s tdcScheduler[2]; #endif /* EFI_ENGINE_CONTROL */ - bool needToStopEngine(efitick_t nowNt) const; bool etbAutoTune = false; /** * this is based on isEngineChartEnabled and engineSnifferRpmThreshold settings @@ -298,12 +297,6 @@ public: RpmCalculator rpmCalculator; - /** - * this is about 'stopengine' command - */ - efitick_t stopEngineRequestTimeNt = 0; - - bool startStopState = false; int startStopStateToggleCounter = 0; diff --git a/firmware/controllers/core/fsio_core.h b/firmware/controllers/core/fsio_core.h index 24b112c451..25702aca6e 100644 --- a/firmware/controllers/core/fsio_core.h +++ b/firmware/controllers/core/fsio_core.h @@ -47,7 +47,6 @@ typedef enum { LE_METHOD_EXHAUST_VVT = 118, LE_METHOD_IS_COOLANT_BROKEN = 119, LE_METHOD_CRANKING_RPM = 120, - LE_METHOD_IN_SHUTDOWN = 122, LE_METHOD_FSIO_DIGITAL_INPUT = 123, LE_METHOD_FSIO_SETTING = 124, LE_METHOD_PPS = 125, diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index f11e3975e6..aee13876d7 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -61,7 +61,6 @@ static LENameOrdinalPair leFsioDigitalInput(LE_METHOD_FSIO_DIGITAL_INPUT, FSIO_M static LENameOrdinalPair leIntakeVVT(LE_METHOD_INTAKE_VVT, "ivvt"); static LENameOrdinalPair leExhaustVVT(LE_METHOD_EXHAUST_VVT, "evvt"); static LENameOrdinalPair leCrankingRpm(LE_METHOD_CRANKING_RPM, "cranking_rpm"); -static LENameOrdinalPair leInShutdown(LE_METHOD_IN_SHUTDOWN, "in_shutdown"); static LENameOrdinalPair leFuelRate(LE_METHOD_FUEL_FLOW_RATE, "fuel_flow"); #define SYS_ELEMENT_POOL_SIZE 24 @@ -100,8 +99,6 @@ FsioResult getEngineValue(le_action_e action) { #endif case LE_METHOD_CRANKING_RPM: return engineConfiguration->cranking.rpm; - case LE_METHOD_IN_SHUTDOWN: - return engine->isInShutdownMode(); case LE_METHOD_VBATT: return Sensor::getOrZero(SensorType::BatteryVoltage); case LE_METHOD_TPS: @@ -132,8 +129,6 @@ static const char * action2String(le_action_e action) { return "CLT"; case LE_METHOD_FAN: return "fan"; - case LE_METHOD_IN_SHUTDOWN: - return leInShutdown.name; default: { // this is here to make compiler happy diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 8bae4b4195..34ebee6d06 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -88,6 +88,10 @@ bool RpmCalculator::isRunning() const { * @return true if engine is spinning (cranking or running) */ bool RpmCalculator::checkIfSpinning(efitick_t nowNt) const { + if (engine->limpManager.isEngineStop(nowNt)) { + return false; + } + // Anything below 60 rpm is not running bool noRpmEventsForTooLong = lastTdcTimer.getElapsedSeconds(nowNt) > NO_RPM_EVENTS_TIMEOUT_SECS; diff --git a/firmware/controllers/limp_manager.cpp b/firmware/controllers/limp_manager.cpp index ffe8ec4fbc..dea129e074 100644 --- a/firmware/controllers/limp_manager.cpp +++ b/firmware/controllers/limp_manager.cpp @@ -60,7 +60,8 @@ void LimpManager::updateState(int rpm, efitick_t nowNt) { m_hadOilPressureAfterStart = false; } - if (engine->needToStopEngine(nowNt)) { + // If we're in engine stop mode, inhibit fuel + if (isEngineStop(nowNt)) { /** * todo: we need explicit clarification on why do we cut fuel but do not cut spark here! */ @@ -75,6 +76,7 @@ todo AndreiKA this change breaks 22 unit tests? */ } + m_transientAllowInjection = allowFuel; m_transientAllowIgnition = allowSpark; } @@ -93,6 +95,21 @@ void LimpManager::fatalError() { setFaultRevLimit(0); } +void LimpManager::stopEngine() { + m_engineStopTimer.reset(); +} + +bool LimpManager::isEngineStop(efitick_t nowNt) const { + float timeSinceStop = getTimeSinceEngineStop(nowNt); + + // If there was stop requested in the past 5 seconds, we're in stop mode + return timeSinceStop < 5; +} + +float LimpManager::getTimeSinceEngineStop(efitick_t nowNt) const { + return m_engineStopTimer.getElapsedSeconds(nowNt); +} + void LimpManager::setFaultRevLimit(int limit) { // Only allow decreasing the limit // aka uses the limit of the worst fault to yet occur diff --git a/firmware/controllers/limp_manager.h b/firmware/controllers/limp_manager.h index 83be5917b1..e1c360057e 100644 --- a/firmware/controllers/limp_manager.h +++ b/firmware/controllers/limp_manager.h @@ -66,6 +66,10 @@ public: // Other subsystems call these APIs to indicate a problem has occured void etbProblem(); void fatalError(); + void stopEngine(); + + bool isEngineStop(efitick_t nowNt) const; + float getTimeSinceEngineStop(efitick_t nowNt) const; private: void setFaultRevLimit(int limit); @@ -82,4 +86,6 @@ private: Clearable m_transientAllowIgnition = true; bool m_hadOilPressureAfterStart = false; + + Timer m_engineStopTimer; }; diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 986d6b3f5c..5568e7fafb 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -839,8 +839,7 @@ static void disableSpi(int index) { } /** - * See 'Engine::needToStopEngine' for code which actually stops engine - * weird: we stop pins from here? we probably should stop engine from the code which is actually stopping engine? + * See 'LimpManager::isEngineStop' for code which actually stops engine */ void scheduleStopEngine(void) { doScheduleStopEngine();