rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
limp_manager.h
Go to the documentation of this file.
1#pragma once
2
5
6#include <cstdint>
7
8// Keep this list in sync with fuelIgnCutCodeList in tunerstudio.template.ini!
9enum class ClearReason : uint8_t {
10 None, // 0
11 Fatal, // 1
12 Settings, // 2
13 HardLimit, // 3
14 EtbFaultRevLimit, // 4 means 1500 RPM limit in case of ETB fault
15 BoostCut, // 5
16 OilPressure, // 6
17 StopRequested, // 7
18 EtbProblem, // 8
19 LaunchCut, // 9
21 FloodClear, // 11
22 EnginePhase, // 12
23 KickStart, // 13
24 IgnitionOff, // 14
25 Lua, // 15
26 ACR, // 16 - Harley Automatic Compression Release
27 LambdaProtection, // 17
28 GdiComms, // 18
29 PleaseBrake, // 19
31 GdiLimits, // 21
32 GdiPumpLimit, // 22
33
34 // Keep this list in sync with fuelIgnCutCodeList in tunerstudio.template.ini!
35 // todo: add a code generator between ClearReason and fuelIgnCutCodeList in tunerstudio.template.ini
36};
37
38enum class EtbStatus : uint8_t {
39 None, // 0
40 EngineStopped, // 1
41 TpsError, // 2
42 PpsError, // 3
43 IntermittentTps, // 4
44 AutoTune, // 5
45 Lua, // 6
46 AutoCalibrate, // 7
47 NotConfigured, // 8
48 Redundancy, // 9
49 IntermittentPps, // 10
50 JamDetected, // 11
51 // keep this list in sync with etbCutCodeList in tunerstudio.template.ini!
52};
53
54// Only allows clearing the value, but never resetting it.
55class Clearable {
56public:
57 Clearable() : m_value(true) {}
58 Clearable(bool value) : m_value(value) {
59 if (!m_value) {
61 }
62 }
63
64 void clear(ClearReason p_clearReason) {
65 if (m_value) {
66 m_value = false;
67 clearReason = p_clearReason;
68 }
69 }
70
71 operator bool() const {
72 return m_value;
73 }
74
76private:
77 bool m_value = true;
78};
79
80struct LimpState {
81 const bool value;
83
84 // Implicit conversion operator to bool, so you can do things like if (myResult) { ... }
85 constexpr explicit operator bool() const {
86 return value;
87 }
88};
89
90class LimpManager : public EngineModule {
91public:
93 // Mockable<> interface
95
96 // This is called from periodicFastCallback to update internal state
97 void updateState(float rpm, efitick_t nowNt);
98
99 void onFastCallback() override;
100 void onIgnitionStateChanged(bool ignitionOn) override;
101
102 // Other subsystems call these APIs to determine their behavior
103 bool allowElectronicThrottle() const;
104
106 LimpState allowIgnition() const;
107
108 float getTimeSinceAnyCut() const;
109
110 bool allowTriggerInput() const;
111
112 void updateRevLimit(float rpm);
114 float getLimitingFuelCorrection() const;
115
116 // Other subsystems call these APIs to indicate a problem has occurred
117 void reportEtbProblem();
118 void fatalError();
120
121private:
122 void setFaultRevLimit(int limit, ClearReason rpmLimitReason);
123
127
128 // Start with no fault rev limit
129 int32_t m_faultRevLimit = INT32_MAX;
130
135
138
140
141 // Ignition switch state
142 bool m_ignitionOn = false;
143
145 float m_fuelCorrection = 1.0f;
146
147 // todo: migrate to engineState->desiredRpmLimit to get this variable logged
151
152 // Tracks how long since a cut (ignition or fuel) was active for any reason
154
155 // Tracks how long injector duty has been over the sustained limit
157
158 // Tracks how long oil pressure has been out of thresholds
161};
162
163#if EFI_ENGINE_CONTROL
165#endif // EFI_ENGINE_CONTROL
166
167
ClearReason clearReason
Clearable(bool value)
void clear(ClearReason p_clearReason)
Clearable m_transientAllowInjection
angle_t m_timingRetard
Clearable m_allowInjection
Hysteresis m_revLimitHysteresis
Timer m_lowOilPressureTimer
Clearable m_allowIgnition
float getTimeSinceAnyCut() const
int32_t m_faultRevLimit
Clearable m_allowEtb
Timer m_highOilPressureTimer
LimpState allowInjection() const
bool m_hadOilPressureAfterStart
MaxLimitWithHysteresis m_boostCutHysteresis
ClearReason m_rpmLimitReason
Timer m_injectorDutySustainedTimer
Clearable m_allowTriggerInput
bool allowTriggerInput() const
void updateState(float rpm, efitick_t nowNt)
LimpState allowIgnition() const
Clearable m_transientAllowIgnition
void reportEtbProblem()
float getLimitingFuelCorrection() const
void updateRevLimit(float rpm)
bool allowElectronicThrottle() const
void onFastCallback() override
void setFaultRevLimit(int limit, ClearReason rpmLimitReason)
angle_t getLimitingTimingRetard() const
void onIgnitionStateChanged(bool ignitionOn) override
Timer m_lastCutTime
float m_fuelCorrection
Hysteresis m_injectorDutyCutHysteresis
ShutdownController shutdownController
Timer externalGdiCanBusComms
ClearReason
Definition limp_manager.h:9
LimpManager * getLimpManager()
Definition engine.cpp:594
EtbStatus
const bool value
const ClearReason reason