rusefi/firmware/controllers/limp_manager.cpp

146 lines
3.8 KiB
C++
Raw Normal View History

#include "pch.h"
#include "limp_manager.h"
void LimpManager::updateState(int rpm, efitick_t nowNt) {
Clearable allowFuel = engineConfiguration->isInjectionEnabled;
Clearable allowSpark = engineConfiguration->isIgnitionEnabled;
// User-configured hard RPM limit
if (rpm > engineConfiguration->rpmHardLimit) {
2022-01-08 20:38:40 -08:00
warning(CUSTOM_OBD_NAN_INJECTION, "Hit hard limit %d", engineConfiguration->rpmHardLimit);
if (engineConfiguration->cutFuelOnHardLimit) {
2022-01-08 19:13:20 -08:00
allowFuel.clear(ClearReason::HardLimit);
}
if (engineConfiguration->cutSparkOnHardLimit) {
2022-01-08 19:13:20 -08:00
allowSpark.clear(ClearReason::HardLimit);
}
}
// Force fuel limiting on the fault rev limit
if (rpm > m_faultRevLimit) {
2022-01-08 19:13:20 -08:00
allowFuel.clear(ClearReason::FaultRevLimit);
}
// Limit fuel only on boost pressure (limiting spark bends valves)
if (engineConfiguration->boostCutPressure != 0) {
if (Sensor::getOrZero(SensorType::Map) > engineConfiguration->boostCutPressure) {
2022-01-08 19:13:20 -08:00
allowFuel.clear(ClearReason::BoostCut);
}
}
if (engine->rpmCalculator.isRunning()) {
uint16_t minOilPressure = engineConfiguration->minOilPressureAfterStart;
// Only check if the setting is enabled
if (minOilPressure > 0) {
// Has it been long enough we should have pressure?
bool isTimedOut = engine->rpmCalculator.getTimeSinceEngineStart(nowNt) > 5.0f;
// Only check before timed out
if (!isTimedOut) {
auto oilp = Sensor::get(SensorType::OilPressure);
if (oilp) {
// We had oil pressure! Set the flag.
if (oilp.Value > minOilPressure) {
m_hadOilPressureAfterStart = true;
}
}
}
// If time is up, the sensor works, and no pressure, kill the engine.
if (isTimedOut && !m_hadOilPressureAfterStart) {
2022-01-08 19:13:20 -08:00
allowFuel.clear(ClearReason::OilPressure);
}
}
} else {
// reset state in case of stalled engine
m_hadOilPressureAfterStart = false;
}
// If we're in engine stop mode, inhibit fuel
if (isEngineStop(nowNt)) {
2021-10-07 06:31:34 -07:00
/**
* todo: we need explicit clarification on why do we cut fuel but do not cut spark here!
*/
2022-01-08 19:13:20 -08:00
allowFuel.clear(ClearReason::StopRequested);
}
2021-12-04 09:18:52 -08:00
if (!engine->isMainRelayEnabled()) {
/*
todo AndreiKA this change breaks 22 unit tests?
2021-10-08 02:03:19 -07:00
allowFuel.clear();
allowSpark.clear();
*/
2021-10-08 02:03:19 -07:00
}
m_transientAllowInjection = allowFuel;
m_transientAllowIgnition = allowSpark;
}
void LimpManager::etbProblem() {
2022-01-08 19:13:20 -08:00
m_allowEtb.clear(ClearReason::EtbProblem);
setFaultRevLimit(1500);
}
void LimpManager::fatalError() {
2022-01-08 19:13:20 -08:00
m_allowEtb.clear(ClearReason::Fatal);
m_allowIgnition.clear(ClearReason::Fatal);
m_allowInjection.clear(ClearReason::Fatal);
m_allowTriggerInput.clear(ClearReason::Fatal);
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
m_faultRevLimit = minI(m_faultRevLimit, limit);
}
bool LimpManager::allowElectronicThrottle() const {
return m_allowEtb;
}
bool LimpManager::allowTriggerInput() const {
return m_allowTriggerInput;
}
2022-01-08 19:13:20 -08:00
LimpState LimpManager::allowInjection() const {
if (!m_allowInjection) {
return {false, m_allowInjection.clearReason};
}
if (!m_transientAllowInjection) {
2022-01-08 19:52:28 -08:00
return {false, m_transientAllowInjection.clearReason};
2022-01-08 19:13:20 -08:00
}
return {true, ClearReason::None};
}
2022-01-08 19:13:20 -08:00
LimpState LimpManager::allowIgnition() const {
if (!m_allowIgnition) {
return {false, m_allowIgnition.clearReason};
}
if (!m_transientAllowIgnition) {
2022-01-08 19:52:28 -08:00
return {false, m_transientAllowIgnition.clearReason};
2022-01-08 19:13:20 -08:00
}
return {true, ClearReason::None};
}