Limp shutdown rebase (#3879)

* limp manager handles engine stop

* use timer

* dead relevant fsio

* this stuff needs its own ticket

* if we can comment out 'business logic' and tests do not fail it's not a great sign :(

Co-authored-by: Matthew Kennedy <matthewkennedy@outlook.com>
Co-authored-by: rusefillc <sdfsdfqsf2334234234>
This commit is contained in:
rusefillc 2022-02-01 20:47:17 -05:00 committed by GitHub
parent 5805b0c855
commit 3be2fcaa80
8 changed files with 34 additions and 27 deletions

View File

@ -354,15 +354,6 @@ Engine::Engine() {
reset(); 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 { int Engine::getGlobalConfigurationVersion(void) const {
return globalConfigurationVersion; 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) // 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 const efitick_t engineStopWaitTimeoutUs = 500000LL; // 0.5 sec
// in shutdown mode, we need a small cooldown time between the ignition off and on // 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 (stopEngineRequestTimeNt == 0 || (getTimeNowNt() - stopEngineRequestTimeNt) > US2NT(engineStopWaitTimeoutUs)) {
// if the ignition key is turned on again, // if the ignition key is turned on again,
// we cancel the shutdown mode, but only if all shutdown procedures are complete // 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 */ #endif /* EFI_MAIN_RELAY_CONTROL */
} }
@ -563,7 +556,8 @@ bool Engine::isInMainRelayBench() {
} }
bool Engine::isInShutdownMode() const { 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 we are in "ignition_on" mode and not in shutdown mode
if (stopEngineRequestTimeNt == 0 && ignitionOnTimeNt > 0) { if (stopEngineRequestTimeNt == 0 && ignitionOnTimeNt > 0) {
const float vBattThresholdOff = 5.0f; const float vBattThresholdOff = 5.0f;
@ -661,7 +655,7 @@ void Engine::periodicFastCallback() {
void doScheduleStopEngine() { void doScheduleStopEngine() {
efiPrintf("Starting doScheduleStopEngine"); efiPrintf("Starting doScheduleStopEngine");
engine->stopEngineRequestTimeNt = getTimeNowNt(); engine->limpManager.stopEngine();
engine->ignitionOnTimeNt = 0; engine->ignitionOnTimeNt = 0;
// todo: initiate stepper motor parking // todo: initiate stepper motor parking
// make sure we have stored all the info // make sure we have stored all the info

View File

@ -274,7 +274,6 @@ public:
scheduling_s tdcScheduler[2]; scheduling_s tdcScheduler[2];
#endif /* EFI_ENGINE_CONTROL */ #endif /* EFI_ENGINE_CONTROL */
bool needToStopEngine(efitick_t nowNt) const;
bool etbAutoTune = false; bool etbAutoTune = false;
/** /**
* this is based on isEngineChartEnabled and engineSnifferRpmThreshold settings * this is based on isEngineChartEnabled and engineSnifferRpmThreshold settings
@ -298,12 +297,6 @@ public:
RpmCalculator rpmCalculator; RpmCalculator rpmCalculator;
/**
* this is about 'stopengine' command
*/
efitick_t stopEngineRequestTimeNt = 0;
bool startStopState = false; bool startStopState = false;
int startStopStateToggleCounter = 0; int startStopStateToggleCounter = 0;

View File

@ -47,7 +47,6 @@ typedef enum {
LE_METHOD_EXHAUST_VVT = 118, LE_METHOD_EXHAUST_VVT = 118,
LE_METHOD_IS_COOLANT_BROKEN = 119, LE_METHOD_IS_COOLANT_BROKEN = 119,
LE_METHOD_CRANKING_RPM = 120, LE_METHOD_CRANKING_RPM = 120,
LE_METHOD_IN_SHUTDOWN = 122,
LE_METHOD_FSIO_DIGITAL_INPUT = 123, LE_METHOD_FSIO_DIGITAL_INPUT = 123,
LE_METHOD_FSIO_SETTING = 124, LE_METHOD_FSIO_SETTING = 124,
LE_METHOD_PPS = 125, LE_METHOD_PPS = 125,

View File

@ -61,7 +61,6 @@ static LENameOrdinalPair leFsioDigitalInput(LE_METHOD_FSIO_DIGITAL_INPUT, FSIO_M
static LENameOrdinalPair leIntakeVVT(LE_METHOD_INTAKE_VVT, "ivvt"); static LENameOrdinalPair leIntakeVVT(LE_METHOD_INTAKE_VVT, "ivvt");
static LENameOrdinalPair leExhaustVVT(LE_METHOD_EXHAUST_VVT, "evvt"); static LENameOrdinalPair leExhaustVVT(LE_METHOD_EXHAUST_VVT, "evvt");
static LENameOrdinalPair leCrankingRpm(LE_METHOD_CRANKING_RPM, "cranking_rpm"); 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"); static LENameOrdinalPair leFuelRate(LE_METHOD_FUEL_FLOW_RATE, "fuel_flow");
#define SYS_ELEMENT_POOL_SIZE 24 #define SYS_ELEMENT_POOL_SIZE 24
@ -100,8 +99,6 @@ FsioResult getEngineValue(le_action_e action) {
#endif #endif
case LE_METHOD_CRANKING_RPM: case LE_METHOD_CRANKING_RPM:
return engineConfiguration->cranking.rpm; return engineConfiguration->cranking.rpm;
case LE_METHOD_IN_SHUTDOWN:
return engine->isInShutdownMode();
case LE_METHOD_VBATT: case LE_METHOD_VBATT:
return Sensor::getOrZero(SensorType::BatteryVoltage); return Sensor::getOrZero(SensorType::BatteryVoltage);
case LE_METHOD_TPS: case LE_METHOD_TPS:
@ -132,8 +129,6 @@ static const char * action2String(le_action_e action) {
return "CLT"; return "CLT";
case LE_METHOD_FAN: case LE_METHOD_FAN:
return "fan"; return "fan";
case LE_METHOD_IN_SHUTDOWN:
return leInShutdown.name;
default: { default: {
// this is here to make compiler happy // this is here to make compiler happy

View File

@ -88,6 +88,10 @@ bool RpmCalculator::isRunning() const {
* @return true if engine is spinning (cranking or running) * @return true if engine is spinning (cranking or running)
*/ */
bool RpmCalculator::checkIfSpinning(efitick_t nowNt) const { bool RpmCalculator::checkIfSpinning(efitick_t nowNt) const {
if (engine->limpManager.isEngineStop(nowNt)) {
return false;
}
// Anything below 60 rpm is not running // Anything below 60 rpm is not running
bool noRpmEventsForTooLong = lastTdcTimer.getElapsedSeconds(nowNt) > NO_RPM_EVENTS_TIMEOUT_SECS; bool noRpmEventsForTooLong = lastTdcTimer.getElapsedSeconds(nowNt) > NO_RPM_EVENTS_TIMEOUT_SECS;

View File

@ -60,7 +60,8 @@ void LimpManager::updateState(int rpm, efitick_t nowNt) {
m_hadOilPressureAfterStart = false; 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! * 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_transientAllowInjection = allowFuel;
m_transientAllowIgnition = allowSpark; m_transientAllowIgnition = allowSpark;
} }
@ -93,6 +95,21 @@ void LimpManager::fatalError() {
setFaultRevLimit(0); 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) { void LimpManager::setFaultRevLimit(int limit) {
// Only allow decreasing the limit // Only allow decreasing the limit
// aka uses the limit of the worst fault to yet occur // aka uses the limit of the worst fault to yet occur

View File

@ -66,6 +66,10 @@ public:
// Other subsystems call these APIs to indicate a problem has occured // Other subsystems call these APIs to indicate a problem has occured
void etbProblem(); void etbProblem();
void fatalError(); void fatalError();
void stopEngine();
bool isEngineStop(efitick_t nowNt) const;
float getTimeSinceEngineStop(efitick_t nowNt) const;
private: private:
void setFaultRevLimit(int limit); void setFaultRevLimit(int limit);
@ -82,4 +86,6 @@ private:
Clearable m_transientAllowIgnition = true; Clearable m_transientAllowIgnition = true;
bool m_hadOilPressureAfterStart = false; bool m_hadOilPressureAfterStart = false;
Timer m_engineStopTimer;
}; };

View File

@ -839,8 +839,7 @@ static void disableSpi(int index) {
} }
/** /**
* See 'Engine::needToStopEngine' for code which actually stops engine * See 'LimpManager::isEngineStop' 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?
*/ */
void scheduleStopEngine(void) { void scheduleStopEngine(void) {
doScheduleStopEngine(); doScheduleStopEngine();