2015-07-10 06:01:56 -07:00
|
|
|
/*
|
|
|
|
* @file trigger_central.h
|
|
|
|
*
|
|
|
|
* @date Feb 23, 2014
|
2017-01-03 03:05:22 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2017
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef TRIGGER_CENTRAL_H_
|
|
|
|
#define TRIGGER_CENTRAL_H_
|
|
|
|
|
|
|
|
#include "rusefi_enums.h"
|
|
|
|
#include "listener_array.h"
|
|
|
|
#include "trigger_decoder.h"
|
|
|
|
|
|
|
|
class Engine;
|
2017-05-15 20:33:22 -07:00
|
|
|
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-05-10 18:56:33 -07:00
|
|
|
#define HAVE_CAM_INPUT() engineConfiguration->camInput != GPIO_UNASSIGNED
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#define HW_EVENT_TYPES 6
|
|
|
|
|
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
|
|
|
|
*/
|
2015-07-10 06:01:56 -07:00
|
|
|
class TriggerCentral {
|
|
|
|
public:
|
|
|
|
TriggerCentral();
|
|
|
|
void addEventListener(ShaftPositionListener handler, const char *name, Engine *engine);
|
2017-05-15 20:33:22 -07:00
|
|
|
void handleShaftSignal(trigger_event_e signal 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();
|
2018-04-25 23:11:51 -07:00
|
|
|
void resetAccumSignalData();
|
|
|
|
bool noiseFilter(efitick_t nowNt, trigger_event_e signal DECLARE_ENGINE_PARAMETER_SUFFIX);
|
2017-05-18 13:16:55 -07:00
|
|
|
TriggerStateWithRunningStatistics triggerState;
|
2019-01-22 16:07:36 -08:00
|
|
|
efitick_t nowNt = 0;
|
|
|
|
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
|
|
|
|
2017-03-01 19:18:25 -08:00
|
|
|
TriggerShape triggerShape;
|
|
|
|
|
2019-02-02 23:47:20 -08:00
|
|
|
efitick_t previousVvtCamTime = 0;
|
|
|
|
efitick_t previousVvtCamDuration = 0;
|
|
|
|
|
2016-01-26 19:03:19 -08:00
|
|
|
volatile efitime_t previousShaftEventTimeNt;
|
2015-07-10 06:01:56 -07:00
|
|
|
private:
|
2016-07-05 17:02:56 -07:00
|
|
|
IntListenerArray<15> triggerListeneres;
|
2015-07-10 06:01:56 -07:00
|
|
|
int hwEventCounters[HW_EVENT_TYPES];
|
2018-04-25 23:11:51 -07:00
|
|
|
|
|
|
|
// Used by 'useNoiselessTriggerDecoder', see handleShaftSignal()
|
|
|
|
efitick_t lastSignalTimes[HW_EVENT_TYPES];
|
|
|
|
efitick_t accumSignalPeriods[HW_EVENT_TYPES];
|
|
|
|
efitick_t accumSignalPrevPeriods[HW_EVENT_TYPES];
|
2015-07-10 06:01:56 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
void triggerInfo(void);
|
2017-05-15 20:33:22 -07:00
|
|
|
efitime_t getCrankEventCounter(DECLARE_ENGINE_PARAMETER_SIGNATURE);
|
2015-07-10 06:01:56 -07:00
|
|
|
void hwHandleShaftSignal(trigger_event_e signal);
|
2019-05-10 20:52:55 -07:00
|
|
|
void hwHandleVvtCamSignal(trigger_value_e front 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 printAllCallbacksHistogram(void);
|
|
|
|
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
|
|
|
|
2018-02-03 09:47:37 -08:00
|
|
|
void onConfigurationChangeTriggerCallback(engine_configuration_s *previousConfiguration DECLARE_ENGINE_PARAMETER_SUFFIX);
|
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
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif /* TRIGGER_CENTRAL_H_ */
|