2015-07-10 06:01:56 -07:00
|
|
|
/*
|
|
|
|
* @file trigger_central.h
|
|
|
|
*
|
|
|
|
* @date Feb 23, 2014
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2019-12-23 18:56:16 -08:00
|
|
|
#pragma once
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#include "rusefi_enums.h"
|
|
|
|
#include "listener_array.h"
|
|
|
|
#include "trigger_decoder.h"
|
2019-09-03 16:30:51 -07:00
|
|
|
#include "trigger_central_generated.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2020-02-14 10:02:27 -08:00
|
|
|
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
class Engine;
|
2020-01-09 12:45:13 -08:00
|
|
|
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-07-12 11:24:45 -07:00
|
|
|
#define HAVE_CAM_INPUT() engineConfiguration->camInputs[0] != GPIO_UNASSIGNED
|
2019-05-10 18:56:33 -07:00
|
|
|
|
2020-01-27 21:16:33 -08:00
|
|
|
class TriggerNoiseFilter {
|
|
|
|
public:
|
|
|
|
void resetAccumSignalData();
|
|
|
|
bool noiseFilter(efitick_t nowNt,
|
|
|
|
TriggerState * triggerState,
|
|
|
|
trigger_event_e signal DECLARE_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
|
|
|
|
efitick_t lastSignalTimes[HW_EVENT_TYPES];
|
|
|
|
efitick_t accumSignalPeriods[HW_EVENT_TYPES];
|
|
|
|
efitick_t accumSignalPrevPeriods[HW_EVENT_TYPES];
|
|
|
|
};
|
|
|
|
|
2017-05-18 13:16:55 -07:00
|
|
|
/**
|
|
|
|
* Maybe merge TriggerCentral and TriggerState classes into one class?
|
|
|
|
* Probably not: we have an instance of TriggerState which is used for trigger initialization,
|
|
|
|
* also composition probably better than inheritance here
|
|
|
|
*/
|
2019-06-30 06:38:51 -07:00
|
|
|
class TriggerCentral : public trigger_central_s {
|
2015-07-10 06:01:56 -07:00
|
|
|
public:
|
|
|
|
TriggerCentral();
|
|
|
|
void addEventListener(ShaftPositionListener handler, const char *name, Engine *engine);
|
2020-01-09 10:19:11 -08:00
|
|
|
void handleShaftSignal(trigger_event_e signal, efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
2019-06-08 06:51:36 -07:00
|
|
|
int getHwEventCounter(int index) const;
|
2015-07-10 06:01:56 -07:00
|
|
|
void resetCounters();
|
2019-09-02 11:47:05 -07:00
|
|
|
void validateCamVvtCounters();
|
2017-05-18 13:16:55 -07:00
|
|
|
TriggerStateWithRunningStatistics triggerState;
|
2020-01-09 10:19:11 -08:00
|
|
|
|
2020-01-27 21:16:33 -08:00
|
|
|
TriggerNoiseFilter noiseFilter;
|
|
|
|
|
2020-01-30 22:49:10 -08:00
|
|
|
angle_t getVVTPosition();
|
|
|
|
|
2019-01-22 16:07:36 -08:00
|
|
|
angle_t vvtPosition = 0;
|
2016-08-22 20:04:55 -07:00
|
|
|
/**
|
|
|
|
* this is similar to TriggerState#startOfCycleNt but with the crank-only sensor magic
|
|
|
|
*/
|
2019-01-22 16:07:36 -08:00
|
|
|
efitick_t timeAtVirtualZeroNt = 0;
|
2016-08-20 20:02:09 -07:00
|
|
|
|
2019-12-07 22:09:39 -08:00
|
|
|
TriggerWaveform triggerShape;
|
2017-03-01 19:18:25 -08:00
|
|
|
|
2020-01-30 22:21:56 -08:00
|
|
|
efitick_t previousVvtCamTime = DEEP_IN_THE_PAST_SECONDS * NT_PER_SECOND;
|
2019-02-02 23:47:20 -08:00
|
|
|
efitick_t previousVvtCamDuration = 0;
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
private:
|
2016-07-05 17:02:56 -07:00
|
|
|
IntListenerArray<15> triggerListeneres;
|
2020-01-27 21:16:33 -08:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void triggerInfo(void);
|
2020-01-09 10:19:11 -08:00
|
|
|
void hwHandleShaftSignal(trigger_event_e signal, efitick_t timestamp);
|
|
|
|
void hwHandleVvtCamSignal(trigger_value_e front, efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
|
2017-12-12 14:36:49 -08:00
|
|
|
|
2017-05-15 17:31:16 -07:00
|
|
|
void initTriggerCentral(Logging *sharedLogger);
|
2015-07-10 06:01:56 -07:00
|
|
|
void printAllTriggers();
|
|
|
|
|
|
|
|
void addTriggerEventListener(ShaftPositionListener handler, const char *name, Engine *engine);
|
|
|
|
int isSignalDecoderError(void);
|
2017-05-19 18:52:10 -07:00
|
|
|
void resetMaxValues();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-10-21 20:47:40 -07:00
|
|
|
void onConfigurationChangeTriggerCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
2019-01-09 18:08:04 -08:00
|
|
|
bool checkIfTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
2019-05-10 18:29:17 -07:00
|
|
|
bool isTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
2017-06-26 11:31:10 -07:00
|
|
|
|
2020-02-14 10:02:27 -08:00
|
|
|
#define SYMMETRICAL_CRANK_SENSOR_DIVIDER 4
|