rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
trigger_decoder.h
Go to the documentation of this file.
1/**
2 * @file trigger_decoder.h
3 *
4 * @date Dec 24, 2013
5 * @author Andrey Belomutskiy, (c) 2012-2020
6 */
7
8#pragma once
9
10#include "trigger_structure.h"
13#include <rusefi/timer.h>
14
15const char *getTrigger_event_e(trigger_event_e value);
16const char *getTrigger_value_e(TriggerValue value);
17
19#if EFI_SHAFT_POSITION_INPUT
20 virtual void OnTriggerStateProperState(efitick_t nowNt, size_t triggerStateIndex) = 0;
21 virtual void OnTriggerSynchronization(bool wasSynchronized, bool isDecodingError) = 0;
22 virtual void OnTriggerSynchronizationLost() = 0;
23 // todo: replace this dirty hack with proper collection (linked list?) of listeners
25#endif // EFI_SHAFT_POSITION_INPUT
26};
27
29public:
30 explicit TriggerConfiguration(const char* printPrefix) : PrintPrefix(printPrefix) {}
31 void update();
32
33 const char* const PrintPrefix;
36
37protected:
38 virtual bool isVerboseTriggerSynchDetails() const = 0;
39public:
40 virtual trigger_config_s getType() const = 0;
41};
42
44public:
46
47protected:
48 bool isVerboseTriggerSynchDetails() const override;
49 trigger_config_s getType() const override;
50};
51
53public:
54 const int index;
55
58
59protected:
60 bool isVerboseTriggerSynchDetails() const override;
61 trigger_config_s getType() const override;
62};
63
64typedef struct {
65 /**
66 * index within trigger revolution, from 0 to trigger event count
67 */
68 uint32_t current_index;
69 /**
70 * Number of actual events of each channel within current trigger cycle, these
71 * values are used to detect trigger signal errors.
72 * see TriggerWaveform
73 */
74 size_t eventCount[PWM_PHASE_MAX_WAVE_PER_PWM];
75
77
79 uint32_t CurrentIndex;
80};
81
82/**
83 * @see TriggerWaveform for trigger wheel shape definition
84 */
86public:
87 TriggerDecoderBase(const char* name);
88
89 void printGaps(const char * prefix,
90 const TriggerConfiguration& triggerConfiguration,
91 const TriggerWaveform& triggerShape);
92
93 /**
94 * current trigger processing index, between zero and #size
95 */
96 int getCurrentIndex() const;
97 int getSynchronizationCounter() const;
98 /**
99 * this is important for crank-based virtual trigger and VVT magic
100 */
102
103#if EFI_UNIT_TEST
104 /**
105 * used only for trigger export
106 */
107 float gapRatio[PWM_PHASE_MAX_COUNT * 6];
108#endif // EFI_UNIT_TEST
109
110 int64_t getTotalEventCounter() const;
111
112 expected<TriggerDecodeResult> decodeTriggerEvent(
113 const char *msg,
114 const TriggerWaveform& triggerShape,
115 TriggerStateListener* triggerStateListener,
116 const TriggerConfiguration& triggerConfiguration,
117 const trigger_event_e signal,
118 const efitick_t nowNt);
119
121 bool wasSynchronized,
122 const efitick_t nowNt,
123 const TriggerWaveform& triggerShape);
124
125 bool isValidIndex(const TriggerWaveform& triggerShape) const;
126
127 /**
128 * TRUE if we know where we are
129 */
132
134
135 /**
136 * current duration at index zero and previous durations are following
137 */
138 uint32_t toothDurations[GAP_TRACKING_LENGTH + 1];
139
141
143 const char* const name;
144
145 /**
146 * how many times since ECU reboot we had unexpected number of teeth in trigger cycle
147 */
150
151 virtual void resetState();
152 void setShaftSynchronized(bool value);
153 bool getShaftSynchronized() const;
154
155 /**
156 * this is start of real trigger cycle
157 * for virtual double trigger see timeAtVirtualZeroNt
158 */
159 efitick_t startOfCycleNt;
160
162 TriggerWaveform& shape,
163 const TriggerConfiguration& triggerConfiguration
164 );
165
167 return !m_timeSinceDecodeError.hasElapsedSec(0.3);
168 }
169
170protected:
171 // Called when some problem is detected with trigger decoding.
172 // That means either:
173 // - Too many events without a sync point
174 // - Saw a sync point but the wrong number of events in the cycle
175 virtual void onTriggerError() { }
176
177 virtual void onNotEnoughTeeth(int, int) { }
178 virtual void onTooManyTeeth(int, int) { }
179
180private:
181 void setTriggerErrorState(int errorIncrement = 1);
183 bool isSyncPoint(const TriggerWaveform& triggerShape, trigger_type_e triggerType) const;
184
185 int getEventCountersError(const TriggerWaveform& triggerShape) const;
186
189
191
193};
194
195/**
196 * the reason for sub-class is simply to save RAM but not having statistics in the trigger initialization instance
197 */
199public:
200 PrimaryTriggerDecoder(const char* name);
201 void resetState() override;
202
204 // If this trigger doesn't need disambiguation, we already have phase sync
206 }
207
208 /**
209 * returns zero if we were lucky to have correct engine phase, otherwise angle of engine phase correction which was applied.
210 */
211 angle_t syncEnginePhase(int divider, int remainder, angle_t engineCycle);
212
213 // Returns true if syncEnginePhase has been called,
214 // i.e. if we have enough VVT information to have full sync on
215 // an indeterminate crank pattern
216 bool hasSynchronizedPhase() const {
218 }
219
220 void setNeedsDisambiguation(bool needsDisambiguation) {
221 m_needsDisambiguation = needsDisambiguation;
222
224 }
225
226 void onTriggerError() override;
227
228 void onNotEnoughTeeth(int actual, int expected) override;
229 void onTooManyTeeth(int actual, int expected) override;
230
231private:
232
234};
235
237public:
238 VvtTriggerDecoder(const char* p_name) : TriggerDecoderBase(p_name) { }
239
240 void onNotEnoughTeeth(int actual, int expected) override;
241 void onTooManyTeeth(int actual, int expected) override;
242};
243
trigger_config_s getType() const override
Definition engine2.cpp:293
bool isVerboseTriggerSynchDetails() const override
Definition engine2.cpp:297
void setNeedsDisambiguation(bool needsDisambiguation)
void onTooManyTeeth(int actual, int expected) override
void onTriggerError() override
void onNotEnoughTeeth(int actual, int expected) override
angle_t syncEnginePhase(int divider, int remainder, angle_t engineCycle)
bool hasSynchronizedPhase() const
virtual bool isVerboseTriggerSynchDetails() const =0
TriggerConfiguration(const char *printPrefix)
const char *const PrintPrefix
trigger_config_s TriggerType
virtual trigger_config_s getType() const =0
virtual void resetState()
void printGaps(const char *prefix, const TriggerConfiguration &triggerConfiguration, const TriggerWaveform &triggerShape)
void incrementShaftSynchronizationCounter()
virtual void onTriggerError()
float gapRatio[PWM_PHASE_MAX_COUNT *6]
void onShaftSynchronization(bool wasSynchronized, const efitick_t nowNt, const TriggerWaveform &triggerShape)
const char *const name
uint32_t findTriggerZeroEventIndex(TriggerWaveform &shape, const TriggerConfiguration &triggerConfiguration)
virtual void onNotEnoughTeeth(int, int)
virtual void onTooManyTeeth(int, int)
efitick_t toothed_previous_time
int getSynchronizationCounter() const
int getEventCountersError(const TriggerWaveform &triggerShape) const
void setShaftSynchronized(bool value)
int64_t getTotalEventCounter() const
trigger_event_e prevSignal
expected< TriggerDecodeResult > decodeTriggerEvent(const char *msg, const TriggerWaveform &triggerShape, TriggerStateListener *triggerStateListener, const TriggerConfiguration &triggerConfiguration, const trigger_event_e signal, const efitick_t nowNt)
Trigger decoding happens here VR falls are filtered out and some VR noise detection happens prior to ...
bool isValidIndex(const TriggerWaveform &triggerShape) const
current_cycle_state_s currentCycle
bool someSortOfTriggerError() const
void setTriggerErrorState(int errorIncrement=1)
uint32_t toothDurations[GAP_TRACKING_LENGTH+1]
uint32_t totalTriggerErrorCounter
bool isSyncPoint(const TriggerWaveform &triggerShape, trigger_type_e triggerType) const
bool getShaftSynchronized() const
Trigger shape has all the fields needed to describe and decode trigger signal.
trigger_config_s getType() const override
Definition engine2.cpp:301
bool isVerboseTriggerSynchDetails() const override
Definition engine2.cpp:306
VvtTriggerConfiguration(const char *prefix, const int p_index)
void onTooManyTeeth(int actual, int expected) override
void onNotEnoughTeeth(int actual, int expected) override
VvtTriggerDecoder(const char *p_name)
trigger_type_e
operation_mode_e
float angle_t
triggerStateIndex("triggerStateIndex", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1584, 1.0, -1.0, -1.0, "")
trigger_event_e
TriggerValue
virtual void OnTriggerStateProperState(efitick_t nowNt, size_t triggerStateIndex)=0
virtual void OnTriggerSynchronization(bool wasSynchronized, bool isDecodingError)=0
virtual void OnTriggerSynchronizationLost()=0
virtual TriggerStateListener * nextListener()=0
const char * getTrigger_value_e(TriggerValue value)
angle_t getEngineCycle(operation_mode_e operationMode)
const char * getTrigger_event_e(trigger_event_e value)
triggerType