rusEFI
An attempt to build an Engine Control Unit
|
#include <trigger_decoder.h>
Public Member Functions | |
TriggerState () | |
int | getCurrentIndex () const |
int | getTotalRevolutionCounter () const |
void | incrementTotalEventCounter () |
efitime_t | getTotalEventCounter () const |
void | decodeTriggerEvent (const char *msg, const TriggerWaveform &triggerShape, const TriggerStateCallback triggerCycleCallback, TriggerStateListener *triggerStateListener, const TriggerConfiguration &triggerConfiguration, const trigger_event_e signal, const efitime_t nowUs) |
Trigger decoding happens here VR falls are filtered out and some VR noise detection happens prior to invoking this method, for Hall this method is invoked every time we have a fall or rise on one of the trigger sensors. This method changes the state of trigger_state_s data structure according to the trigger event. More... | |
bool | validateEventCounters (const TriggerWaveform &triggerShape) const |
void | onShaftSynchronization (const TriggerStateCallback triggerCycleCallback, bool wasSynchronized, const efitick_t nowNt, const TriggerWaveform &triggerShape) |
bool | isValidIndex (const TriggerWaveform &triggerShape) const |
void | setTriggerErrorState () |
virtual void | resetTriggerState () |
void | setShaftSynchronized (bool value) |
bool | getShaftSynchronized () |
uint32_t | findTriggerZeroEventIndex (TriggerWaveform &shape, const TriggerConfiguration &triggerConfiguration, const trigger_config_s &triggerConfig) |
Data Fields | |
bool | shaft_is_synchronized |
efitick_t | mostRecentSyncTime |
Timer | previousEventTimer |
efitick_t | lastDecodingErrorTime |
bool | someSortOfTriggerError |
uint32_t | toothDurations [GAP_TRACKING_LENGTH+1] |
efitick_t | toothed_previous_time |
current_cycle_state_s | currentCycle |
const char * | name = nullptr |
int | expectedTotalTime [PWM_PHASE_MAX_WAVE_PER_PWM] |
uint32_t | totalTriggerErrorCounter |
uint32_t | orderingErrorCounter |
efitick_t | startOfCycleNt |
Data Fields inherited from trigger_state_s | |
uint32_t | totalRevolutionCounter = (uint32_t)0 |
scaled_channel< float, 1, 1 > | vvtSyncGapRatio = (float)0 |
scaled_channel< float, 1, 1 > | vvtCurrentPosition = (float)0 |
scaled_channel< float, 1, 1 > | triggerSyncGapRatio = (float)0 |
float | triggerActualSyncGapRatio = (float)0 |
uint8_t | triggerStateIndex = (uint8_t)0 |
uint8_t | vvtCounter = (uint8_t)0 |
uint8_t | vvtSyncCounter = (uint8_t)0 |
uint8_t | vvtStateIndex = (uint8_t)0 |
Private Member Functions | |
void | resetCurrentCycleState () |
bool | isSyncPoint (const TriggerWaveform &triggerShape, trigger_type_e triggerType) const |
Private Attributes | |
trigger_event_e | curSignal |
trigger_event_e | prevSignal |
int64_t | totalEventCountBase |
bool | isFirstEvent |
Definition at line 77 of file trigger_decoder.h.
TriggerState::TriggerState | ( | ) |
void TriggerState::decodeTriggerEvent | ( | const char * | msg, |
const TriggerWaveform & | triggerShape, | ||
const TriggerStateCallback | triggerCycleCallback, | ||
TriggerStateListener * | triggerStateListener, | ||
const TriggerConfiguration & | triggerConfiguration, | ||
const trigger_event_e | signal, | ||
const efitime_t | nowUs | ||
) |
Trigger decoding happens here VR falls are filtered out and some VR noise detection happens prior to invoking this method, for Hall this method is invoked every time we have a fall or rise on one of the trigger sensors. This method changes the state of trigger_state_s data structure according to the trigger event.
signal | type of event which just happened |
nowNt | current time |
We are here if there is a time gap between now and previous shaft event - that means the engine is not running. That means we have lost synchronization since the engine is not running :)
For performance reasons, we want to work with 32 bit values. If there has been more then 10 seconds since previous trigger event we do not really care.
For less important events we simply increment the index.
todo: technically we can afford detailed logging even with 60/2 as long as low RPM todo: figure out exact threshold as a function of RPM and tooth count? Open question what is 'triggerShape.getSize()' for 60/2 is it 58 or 58*2 or 58*4?
We are here in case of a wheel without synchronization - we just need to count events, synchronization point simply happens once we have the right number of events
in case of noise the counter could be above the expected number of events, that's why 'more or equals' and not just 'equals'
Definition at line 483 of file trigger_decoder.cpp.
Referenced by TriggerCentral::handleShaftSignal(), and hwHandleVvtCamSignal().
uint32_t TriggerState::findTriggerZeroEventIndex | ( | TriggerWaveform & | shape, |
const TriggerConfiguration & | triggerConfiguration, | ||
const trigger_config_s & | triggerConfig | ||
) |
Trigger shape is defined in a way which is convenient for trigger shape definition On the other hand, trigger decoder indexing begins from synchronization event.
This function finds the index of synchronization event within TriggerWaveform
Now that we have just located the synch point, we can simulate the whole cycle in order to calculate expected duty cycle
todo: add a comment why are we doing '2 * shape->getSize()' here?
Definition at line 776 of file trigger_decoder.cpp.
int TriggerState::getCurrentIndex | ( | ) | const |
current trigger processing index, between zero and size
Definition at line 382 of file trigger_decoder.cpp.
Referenced by TriggerCentral::handleShaftSignal().
bool TriggerState::getShaftSynchronized | ( | ) |
Definition at line 45 of file trigger_decoder.cpp.
Referenced by decodeTriggerEvent(), TriggerCentral::handleShaftSignal(), hwHandleVvtCamSignal(), TriggerNoiseFilter::noiseFilter(), TriggerStateWithRunningStatistics::setLastEventTimeForInstantRpm(), and SetNextCompositeEntry().
int64_t TriggerState::getTotalEventCounter | ( | ) | const |
Definition at line 212 of file trigger_decoder.cpp.
Referenced by updateDevConsoleState().
int TriggerState::getTotalRevolutionCounter | ( | ) | const |
Definition at line 216 of file trigger_decoder.cpp.
Referenced by extIonCallback(), findTriggerZeroEventIndex(), TriggerCentral::handleShaftSignal(), mainTriggerCallback(), TriggerStateWithRunningStatistics::syncEnginePhase(), triggerInfo(), and TriggerCentral::validateCamVvtCounters().
void TriggerState::incrementTotalEventCounter | ( | ) |
this is important for crank-based virtual trigger and VVT magic
Definition at line 420 of file trigger_decoder.cpp.
Referenced by onShaftSynchronization(), and TriggerStateWithRunningStatistics::syncEnginePhase().
|
private |
Definition at line 711 of file trigger_decoder.cpp.
Referenced by decodeTriggerEvent().
bool TriggerState::isValidIndex | ( | const TriggerWaveform & | triggerShape | ) | const |
Definition at line 346 of file trigger_decoder.cpp.
Referenced by decodeTriggerEvent(), and TriggerCentral::handleShaftSignal().
void TriggerState::onShaftSynchronization | ( | const TriggerStateCallback | triggerCycleCallback, |
bool | wasSynchronized, | ||
const efitick_t | nowNt, | ||
const TriggerWaveform & | triggerShape | ||
) |
Definition at line 443 of file trigger_decoder.cpp.
Referenced by decodeTriggerEvent().
|
private |
Definition at line 90 of file trigger_decoder.cpp.
Referenced by onShaftSynchronization(), and resetTriggerState().
|
virtual |
Reimplemented in TriggerStateWithRunningStatistics.
Definition at line 62 of file trigger_decoder.cpp.
Referenced by findTriggerZeroEventIndex(), Engine::OnTriggerSynchronizationLost(), TriggerStateWithRunningStatistics::resetTriggerState(), and TriggerState().
void TriggerState::setShaftSynchronized | ( | bool | value | ) |
Definition at line 49 of file trigger_decoder.cpp.
Referenced by decodeTriggerEvent(), and resetTriggerState().
void TriggerState::setTriggerErrorState | ( | ) |
Definition at line 85 of file trigger_decoder.cpp.
Referenced by Engine::OnTriggerInvalidIndex(), and Engine::OnTriggerStateDecodingError().
bool TriggerState::validateEventCounters | ( | const TriggerWaveform & | triggerShape | ) | const |
Definition at line 424 of file trigger_decoder.cpp.
Referenced by Engine::OnTriggerSyncronization().
current_cycle_state_s TriggerState::currentCycle |
Definition at line 131 of file trigger_decoder.h.
Referenced by decodeTriggerEvent(), getCurrentIndex(), getTotalEventCounter(), TriggerCentral::handleShaftSignal(), hwHandleVvtCamSignal(), isValidIndex(), TriggerNoiseFilter::noiseFilter(), onShaftSynchronization(), Engine::OnTriggerStateDecodingError(), Engine::OnTriggerSyncronization(), resetCurrentCycleState(), TriggerStateWithRunningStatistics::updateInstantRpm(), updateTunerStudioState(), and validateEventCounters().
|
private |
Definition at line 162 of file trigger_decoder.h.
Referenced by decodeTriggerEvent(), and resetTriggerState().
int TriggerState::expectedTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM] |
Definition at line 134 of file trigger_decoder.h.
Referenced by resetTriggerState().
|
private |
Definition at line 166 of file trigger_decoder.h.
Referenced by decodeTriggerEvent(), and resetTriggerState().
efitick_t TriggerState::lastDecodingErrorTime |
Definition at line 120 of file trigger_decoder.h.
Referenced by decodeTriggerEvent(), isTriggerErrorNow(), resetTriggerState(), and setTriggerErrorState().
efitick_t TriggerState::mostRecentSyncTime |
Definition at line 114 of file trigger_decoder.h.
Referenced by setShaftSynchronized().
const char* TriggerState::name = nullptr |
Definition at line 132 of file trigger_decoder.h.
Referenced by decodeTriggerEvent(), and Engine::updateTriggerWaveform().
uint32_t TriggerState::orderingErrorCounter |
Definition at line 140 of file trigger_decoder.h.
Referenced by decodeTriggerEvent(), resetTriggerState(), triggerInfo(), and updateTunerStudioState().
Timer TriggerState::previousEventTimer |
Definition at line 116 of file trigger_decoder.h.
Referenced by decodeTriggerEvent().
|
private |
Definition at line 163 of file trigger_decoder.h.
Referenced by decodeTriggerEvent(), and resetTriggerState().
bool TriggerState::shaft_is_synchronized |
TRUE if we know where we are
Definition at line 113 of file trigger_decoder.h.
Referenced by getShaftSynchronized(), and setShaftSynchronized().
bool TriggerState::someSortOfTriggerError |
Definition at line 122 of file trigger_decoder.h.
Referenced by decodeTriggerEvent(), Engine::OnTriggerStateDecodingError(), resetTriggerState(), and setTriggerErrorState().
efitick_t TriggerState::startOfCycleNt |
this is start of real trigger cycle for virtual double trigger see timeAtVirtualZeroNt
Definition at line 150 of file trigger_decoder.h.
Referenced by onShaftSynchronization(), and resetTriggerState().
uint32_t TriggerState::toothDurations[GAP_TRACKING_LENGTH+1] |
current duration at index zero and previous durations are following
Definition at line 127 of file trigger_decoder.h.
Referenced by decodeTriggerEvent(), isSyncPoint(), and resetTriggerState().
efitick_t TriggerState::toothed_previous_time |
Definition at line 129 of file trigger_decoder.h.
Referenced by decodeTriggerEvent(), and resetTriggerState().
|
private |
Definition at line 164 of file trigger_decoder.h.
Referenced by getTotalEventCounter(), onShaftSynchronization(), and resetTriggerState().
uint32_t TriggerState::totalTriggerErrorCounter |
how many times since ECU reboot we had unexpected number of teeth in trigger cycle
Definition at line 139 of file trigger_decoder.h.
Referenced by canDashboardHaltech(), Engine::OnTriggerStateDecodingError(), resetTriggerState(), triggerInfo(), and updateTunerStudioState().