rusEFI
The most advanced open source ECU
limp_manager.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "shutdown_controller.h"
5 
6 #include <cstdint>
7 
8 // Keep this list in sync with fuelIgnCutCodeList in tunerstudio.template.ini!
9 enum class ClearReason : uint8_t {
10  None, // 0
11  Fatal, // 1
12  Settings, // 2
13  HardLimit, // 3
15  BoostCut, // 5
16  OilPressure, // 6
17  StopRequested, // 7
18  EtbProblem, // 8
19  LaunchCut, // 9
20  InjectorDutyCycle, // 10
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,
30 
31  // Keep this list in sync with fuelIgnCutCodeList in tunerstudio.template.ini!
32  // todo: add a code generator between ClearReason and fuelIgnCutCodeList in tunerstudio.template.ini
33 };
34 
35 enum class TpsState : uint8_t {
36  None, // 0
37  EngineStopped, // 1
38  TpsError, // 2
39  PpsError, // 3
40  IntermittentTps, // 4
41  PidJitter, // 5
42  Lua, // 6
43  Manual, // 7
44  NotConfigured, // 8
45  Redundancy, // 9
46  IntermittentPps, // 10
47  // keep this list in sync with etbCutCodeList in tunerstudio.template.ini!
48 };
49 
50 // Only allows clearing the value, but never resetting it.
51 class Clearable {
52 public:
53  Clearable() : m_value(true) {}
54  Clearable(bool value) : m_value(value) {
55  if (!m_value) {
57  }
58  }
59 
60  void clear(ClearReason p_clearReason) {
61  if (m_value) {
62  m_value = false;
63  clearReason = p_clearReason;
64  }
65  }
66 
67  operator bool() const {
68  return m_value;
69  }
70 
72 private:
73  bool m_value = true;
74 };
75 
76 struct LimpState {
77  const bool value;
79 
80  // Implicit conversion operator to bool, so you can do things like if (myResult) { ... }
81  constexpr explicit operator bool() const {
82  return value;
83  }
84 };
85 
86 class LimpManager : public EngineModule {
87 public:
89 
90  // This is called from periodicFastCallback to update internal state
91  void updateState(int rpm, efitick_t nowNt);
92 
93  void onFastCallback() override;
94  void onIgnitionStateChanged(bool ignitionOn) override;
95 
96  // Other subsystems call these APIs to determine their behavior
97  bool allowElectronicThrottle() const;
98 
99  LimpState allowInjection() const;
100  LimpState allowIgnition() const;
101 
102  float getTimeSinceAnyCut() const;
103 
104  bool allowTriggerInput() const;
105 
106  void updateRevLimit(int rpm);
108  float getLimitingFuelCorrection() const;
109 
110  // Other subsystems call these APIs to indicate a problem has occurred
111 // void reportEtbProblem();
112  void fatalError();
114 
115 private:
116  void setFaultRevLimit(int limit);
117 
121 
122  // Start with no fault rev limit
123  int32_t m_faultRevLimit = INT32_MAX;
124 
129 
132 
134 
135  // Ignition switch state
136  bool m_ignitionOn = false;
137 
139  float m_fuelCorrection = 1.0f;
140 
141  // todo: migrate to engineState->desiredRpmLimit to get this variable logged
142  float m_revLimit;
143  float resumeRpm;
144 
145  // Tracks how long since a cut (ignition or fuel) was active for any reason
147 
148  // Tracks how long injector duty has been over the sustained limit
150 
151  // Tracks how long oil pressure has been below threshold
153 };
154 
155 #if EFI_ENGINE_CONTROL
157 #endif // EFI_ENGINE_CONTROL
158 
159 
bool m_value
Definition: limp_manager.h:73
ClearReason clearReason
Definition: limp_manager.h:71
Clearable(bool value)
Definition: limp_manager.h:54
void clear(ClearReason p_clearReason)
Definition: limp_manager.h:60
Clearable m_transientAllowInjection
Definition: limp_manager.h:130
angle_t m_timingRetard
Definition: limp_manager.h:138
bool m_ignitionOn
Definition: limp_manager.h:136
Clearable m_allowInjection
Definition: limp_manager.h:126
void updateRevLimit(int rpm)
Hysteresis m_revLimitHysteresis
Definition: limp_manager.h:118
Timer m_lowOilPressureTimer
Definition: limp_manager.h:152
void updateState(int rpm, efitick_t nowNt)
Clearable m_allowIgnition
Definition: limp_manager.h:127
void setFaultRevLimit(int limit)
float getTimeSinceAnyCut() const
int32_t m_faultRevLimit
Definition: limp_manager.h:123
Clearable m_allowEtb
Definition: limp_manager.h:125
float m_revLimit
Definition: limp_manager.h:142
LimpState allowInjection() const
void fatalError()
bool m_hadOilPressureAfterStart
Definition: limp_manager.h:133
MaxLimitWithHysteresis m_boostCutHysteresis
Definition: limp_manager.h:119
Timer m_injectorDutySustainedTimer
Definition: limp_manager.h:149
Clearable m_allowTriggerInput
Definition: limp_manager.h:128
bool allowTriggerInput() const
LimpState allowIgnition() const
Clearable m_transientAllowIgnition
Definition: limp_manager.h:131
float getLimitingFuelCorrection() const
bool allowElectronicThrottle() const
void onFastCallback() override
angle_t getLimitingTimingRetard() const
void onIgnitionStateChanged(bool ignitionOn) override
float resumeRpm
Definition: limp_manager.h:143
Timer m_lastCutTime
Definition: limp_manager.h:146
float m_fuelCorrection
Definition: limp_manager.h:139
Hysteresis m_injectorDutyCutHysteresis
Definition: limp_manager.h:120
ShutdownController shutdownController
Definition: limp_manager.h:88
Timer externalGdiCanBusComms
Definition: limp_manager.h:113
TpsState
Definition: limp_manager.h:35
@ IntermittentPps
@ IntermittentTps
ClearReason
Definition: limp_manager.h:9
LimpManager * getLimpManager()
Definition: engine.cpp:617
float angle_t
Definition: rusefi_types.h:59
const bool value
Definition: limp_manager.h:77
const ClearReason reason
Definition: limp_manager.h:78