2020-12-26 14:30:46 -08:00
|
|
|
#pragma once
|
|
|
|
|
2022-09-28 19:42:08 -07:00
|
|
|
#include "shutdown_controller.h"
|
2024-08-23 08:16:45 -07:00
|
|
|
#include "max_limit_with_hysteresis.h"
|
2020-12-26 14:30:46 -08:00
|
|
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
2024-03-15 17:09:32 -07:00
|
|
|
// Keep this list in sync with fuelIgnCutCodeList in tunerstudio.template.ini!
|
2022-01-08 19:13:20 -08:00
|
|
|
enum class ClearReason : uint8_t {
|
|
|
|
None, // 0
|
2023-05-31 09:44:59 -07:00
|
|
|
Fatal, // 1
|
|
|
|
Settings, // 2
|
2022-01-08 19:52:28 -08:00
|
|
|
HardLimit, // 3
|
2022-01-08 19:13:20 -08:00
|
|
|
FaultRevLimit,
|
|
|
|
BoostCut, // 5
|
2023-05-31 09:44:59 -07:00
|
|
|
OilPressure, // 6
|
2022-01-08 20:10:25 -08:00
|
|
|
StopRequested, // 7
|
2022-03-11 06:27:42 -08:00
|
|
|
EtbProblem, // 8
|
|
|
|
LaunchCut, // 9
|
2022-03-24 05:58:55 -07:00
|
|
|
InjectorDutyCycle, // 10
|
|
|
|
FloodClear, // 11
|
2022-04-23 14:56:35 -07:00
|
|
|
EnginePhase, // 12
|
2022-09-19 19:01:03 -07:00
|
|
|
KickStart, // 13
|
2022-10-04 17:36:03 -07:00
|
|
|
IgnitionOff, // 14
|
2023-05-31 09:44:59 -07:00
|
|
|
Lua, // 15
|
2023-06-28 23:34:31 -07:00
|
|
|
ACR, // 16 - Harley Automatic Compression Release
|
|
|
|
LambdaProtection, // 17
|
2023-10-23 10:25:53 -07:00
|
|
|
GdiComms,
|
2023-11-26 22:01:19 -08:00
|
|
|
PleaseBrake,
|
2022-09-19 19:01:03 -07:00
|
|
|
|
2024-03-15 17:09:32 -07:00
|
|
|
// Keep this list in sync with fuelIgnCutCodeList in tunerstudio.template.ini!
|
|
|
|
// todo: add a code generator between ClearReason and fuelIgnCutCodeList in tunerstudio.template.ini
|
2022-01-08 19:13:20 -08:00
|
|
|
};
|
|
|
|
|
2022-11-29 19:00:28 -08:00
|
|
|
enum class TpsState : uint8_t {
|
|
|
|
None, // 0
|
2023-05-31 09:44:59 -07:00
|
|
|
EngineStopped, // 1
|
|
|
|
TpsError, // 2
|
2022-11-29 19:00:28 -08:00
|
|
|
PpsError, // 3
|
2023-05-31 09:44:59 -07:00
|
|
|
IntermittentTps, // 4
|
2024-11-08 11:35:58 -08:00
|
|
|
UnusedCode5, // 5
|
2022-11-29 19:39:55 -08:00
|
|
|
Lua, // 6
|
2023-05-31 09:44:59 -07:00
|
|
|
Manual, // 7
|
|
|
|
NotConfigured, // 8
|
2022-11-29 19:39:55 -08:00
|
|
|
Redundancy, // 9
|
2023-05-31 09:44:59 -07:00
|
|
|
IntermittentPps, // 10
|
2024-03-15 17:09:32 -07:00
|
|
|
// keep this list in sync with etbCutCodeList in tunerstudio.template.ini!
|
2022-11-29 19:00:28 -08:00
|
|
|
};
|
|
|
|
|
2020-12-26 14:30:46 -08:00
|
|
|
// Only allows clearing the value, but never resetting it.
|
|
|
|
class Clearable {
|
|
|
|
public:
|
2021-01-27 18:28:53 -08:00
|
|
|
Clearable() : m_value(true) {}
|
2022-01-08 19:13:20 -08:00
|
|
|
Clearable(bool value) : m_value(value) {
|
|
|
|
if (!m_value) {
|
|
|
|
clearReason = ClearReason::Settings;
|
|
|
|
}
|
|
|
|
}
|
2021-01-27 18:28:53 -08:00
|
|
|
|
2023-11-01 06:48:33 -07:00
|
|
|
void clear(ClearReason p_clearReason) {
|
2022-09-19 19:01:03 -07:00
|
|
|
if (m_value) {
|
|
|
|
m_value = false;
|
2023-11-01 06:48:33 -07:00
|
|
|
clearReason = p_clearReason;
|
2022-09-19 19:01:03 -07:00
|
|
|
}
|
2020-12-26 14:30:46 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
operator bool() const {
|
|
|
|
return m_value;
|
|
|
|
}
|
|
|
|
|
2022-01-08 19:13:20 -08:00
|
|
|
ClearReason clearReason = ClearReason::None;
|
2020-12-26 14:30:46 -08:00
|
|
|
private:
|
|
|
|
bool m_value = true;
|
|
|
|
};
|
|
|
|
|
2022-01-08 19:13:20 -08:00
|
|
|
struct LimpState {
|
|
|
|
const bool value;
|
|
|
|
const ClearReason reason;
|
|
|
|
|
|
|
|
// Implicit conversion operator to bool, so you can do things like if (myResult) { ... }
|
|
|
|
constexpr explicit operator bool() const {
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2022-10-04 17:36:03 -07:00
|
|
|
class LimpManager : public EngineModule {
|
2020-12-26 14:30:46 -08:00
|
|
|
public:
|
2022-09-28 19:42:08 -07:00
|
|
|
ShutdownController shutdownController;
|
|
|
|
|
2020-12-26 14:30:46 -08:00
|
|
|
// This is called from periodicFastCallback to update internal state
|
2024-09-24 23:40:49 -07:00
|
|
|
void updateState(float rpm, efitick_t nowNt);
|
2020-12-26 14:30:46 -08:00
|
|
|
|
2022-10-04 17:36:03 -07:00
|
|
|
void onFastCallback() override;
|
|
|
|
void onIgnitionStateChanged(bool ignitionOn) override;
|
|
|
|
|
2020-12-26 14:30:46 -08:00
|
|
|
// Other subsystems call these APIs to determine their behavior
|
|
|
|
bool allowElectronicThrottle() const;
|
|
|
|
|
2022-01-08 19:13:20 -08:00
|
|
|
LimpState allowInjection() const;
|
|
|
|
LimpState allowIgnition() const;
|
2020-12-26 14:30:46 -08:00
|
|
|
|
2023-03-02 11:42:12 -08:00
|
|
|
float getTimeSinceAnyCut() const;
|
|
|
|
|
2020-12-26 14:30:46 -08:00
|
|
|
bool allowTriggerInput() const;
|
|
|
|
|
2024-09-25 21:34:00 -07:00
|
|
|
void updateRevLimit(float rpm);
|
2023-04-10 14:18:51 -07:00
|
|
|
angle_t getLimitingTimingRetard() const;
|
|
|
|
float getLimitingFuelCorrection() const;
|
|
|
|
|
2022-11-26 20:44:48 -08:00
|
|
|
// Other subsystems call these APIs to indicate a problem has occurred
|
2024-09-17 18:33:32 -07:00
|
|
|
void reportEtbProblem();
|
2020-12-26 14:30:46 -08:00
|
|
|
void fatalError();
|
2024-08-31 17:12:27 -07:00
|
|
|
Timer externalGdiCanBusComms;
|
2020-12-26 14:30:46 -08:00
|
|
|
|
|
|
|
private:
|
|
|
|
void setFaultRevLimit(int limit);
|
|
|
|
|
2022-09-05 17:56:32 -07:00
|
|
|
Hysteresis m_revLimitHysteresis;
|
2024-08-23 08:16:45 -07:00
|
|
|
MaxLimitWithHysteresis m_boostCutHysteresis;
|
2022-09-05 17:56:32 -07:00
|
|
|
Hysteresis m_injectorDutyCutHysteresis;
|
|
|
|
|
2020-12-26 14:30:46 -08:00
|
|
|
// Start with no fault rev limit
|
|
|
|
int32_t m_faultRevLimit = INT32_MAX;
|
|
|
|
|
|
|
|
Clearable m_allowEtb;
|
|
|
|
Clearable m_allowInjection;
|
|
|
|
Clearable m_allowIgnition;
|
|
|
|
Clearable m_allowTriggerInput;
|
|
|
|
|
2022-01-08 19:52:28 -08:00
|
|
|
Clearable m_transientAllowInjection = true;
|
|
|
|
Clearable m_transientAllowIgnition = true;
|
2021-06-16 14:20:28 -07:00
|
|
|
|
|
|
|
bool m_hadOilPressureAfterStart = false;
|
2022-10-04 17:36:03 -07:00
|
|
|
|
|
|
|
// Ignition switch state
|
|
|
|
bool m_ignitionOn = false;
|
2023-04-10 14:18:51 -07:00
|
|
|
|
|
|
|
angle_t m_timingRetard = 0;
|
|
|
|
float m_fuelCorrection = 1.0f;
|
2023-04-15 09:03:47 -07:00
|
|
|
|
|
|
|
// todo: migrate to engineState->desiredRpmLimit to get this variable logged
|
|
|
|
float m_revLimit;
|
2023-04-29 08:07:08 -07:00
|
|
|
float resumeRpm;
|
2023-03-02 11:42:12 -08:00
|
|
|
|
|
|
|
// Tracks how long since a cut (ignition or fuel) was active for any reason
|
|
|
|
Timer m_lastCutTime;
|
2023-10-14 14:27:19 -07:00
|
|
|
|
|
|
|
// Tracks how long injector duty has been over the sustained limit
|
|
|
|
Timer m_injectorDutySustainedTimer;
|
2024-08-06 13:10:10 -07:00
|
|
|
|
|
|
|
// Tracks how long oil pressure has been below threshold
|
|
|
|
Timer m_lowOilPressureTimer;
|
2020-12-26 14:30:46 -08:00
|
|
|
};
|
2022-09-13 23:17:04 -07:00
|
|
|
|
2023-11-05 10:54:06 -08:00
|
|
|
#if EFI_ENGINE_CONTROL
|
2022-09-13 23:17:04 -07:00
|
|
|
LimpManager * getLimpManager();
|
2023-11-05 10:54:06 -08:00
|
|
|
#endif // EFI_ENGINE_CONTROL
|
2022-09-13 23:17:04 -07:00
|
|
|
|
|
|
|
|