fome-fw/firmware/controllers/trigger/trigger_central.h

105 lines
3.4 KiB
C
Raw Normal View History

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"
#include "timer.h"
#include "pin_repository.h"
2015-07-10 06:01:56 -07:00
class Engine;
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
#define HAVE_CAM_INPUT() (isBrainPinValid(engineConfiguration->camInputs[0]))
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
*/
class TriggerCentral final : public trigger_central_s {
2015-07-10 06:01:56 -07:00
public:
TriggerCentral();
void init(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void handleShaftSignal(trigger_event_e signal, efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
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();
float getTimeSinceTriggerEvent(efitick_t nowNt) const {
return m_lastEventTimer.getElapsedSeconds(nowNt);
}
bool engineMovedRecently() const {
// Trigger event some time in the past second = engine moving
2021-05-02 20:46:30 -07:00
// distributor single tooth, large engines crank at close to 120 RPM
// todo: make this logic account current trigger to stop idle much faster if we have more teeth on trigger wheels?
return getTimeSinceTriggerEvent(getTimeNowNt()) < 1.0f;
}
2020-01-27 21:16:33 -08:00
TriggerNoiseFilter noiseFilter;
2021-02-08 19:07:14 -08:00
trigger_type_e vvtTriggerType[CAMS_PER_BANK];
angle_t getVVTPosition(uint8_t bankIndex, uint8_t camIndex);
2021-01-26 19:54:25 -08:00
#if EFI_UNIT_TEST
2020-05-09 23:36:01 -07:00
// latest VVT event position (could be not synchronization event)
2021-02-08 17:38:38 -08:00
angle_t currentVVTEventPosition[BANKS_COUNT][CAMS_PER_BANK];
2021-01-26 19:54:25 -08:00
#endif // EFI_UNIT_TEST
2020-05-09 23:36:01 -07:00
// synchronization event position
2021-02-08 17:38:38 -08:00
angle_t vvtPosition[BANKS_COUNT][CAMS_PER_BANK];
2020-05-09 23:36:01 -07:00
Timer virtualZeroTimer;
2016-08-20 20:02:09 -07:00
2021-02-08 17:38:38 -08:00
efitick_t vvtSyncTimeNt[BANKS_COUNT][CAMS_PER_BANK];
2020-08-24 22:24:15 -07:00
TriggerStateWithRunningStatistics triggerState;
TriggerWaveform triggerShape;
2017-03-01 19:18:25 -08:00
2021-02-08 17:38:38 -08:00
TriggerState vvtState[BANKS_COUNT][CAMS_PER_BANK];
2021-02-08 18:28:57 -08:00
TriggerWaveform vvtShape[CAMS_PER_BANK];
2020-08-24 22:24:15 -07:00
2020-08-24 21:59:07 -07:00
TriggerFormDetails triggerFormDetails;
// Keep track of the last time we got a valid trigger event
Timer m_lastEventTimer;
2015-07-10 06:01:56 -07:00
};
void triggerInfo(void);
void hwHandleShaftSignal(int signalIndex, bool isRising, efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
void handleShaftSignal(int signalIndex, bool isRising, efitick_t timestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
2021-01-31 19:24:45 -08:00
void hwHandleVvtCamSignal(trigger_value_e front, efitick_t timestamp, int index DECLARE_ENGINE_PARAMETER_SUFFIX);
2017-12-12 14:36:49 -08:00
void initTriggerCentral();
2015-07-10 06:01:56 -07:00
int isSignalDecoderError(void);
2019-10-21 20:47:40 -07:00
void onConfigurationChangeTriggerCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool checkIfTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE);
2019-05-10 18:29:17 -07:00
bool isTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE);
2020-08-23 23:01:50 -07:00
bool isTriggerDecoderError(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#define SYMMETRICAL_CRANK_SENSOR_DIVIDER 4
#define SYMMETRICAL_THREE_TIMES_CRANK_SENSOR_DIVIDER 6