Refactor Trigger System #635

reducing global state magic
This commit is contained in:
rusefi 2019-02-03 02:47:20 -05:00
parent 3127b6fd24
commit 16da833501
3 changed files with 9 additions and 18 deletions

View File

@ -472,7 +472,7 @@ void updateDevConsoleState(void) {
systime_t nowSeconds = getTimeNowSeconds();
#if (EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT) || defined(__DOXYGEN__)
int currentCkpEventCounter = getCrankEventCounter();
int currentCkpEventCounter = engine->triggerCentral.triggerState.getTotalEventCounter();
if (prevCkpEventCounter == currentCkpEventCounter && timeOfPreviousReport == nowSeconds) {
return;
}

View File

@ -70,14 +70,6 @@ static histogram_s triggerCallbackHistogram;
static Logging *logger;
static LocalVersionHolder triggerVersion;
efitime_t getCrankEventCounter(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engine->triggerCentral.triggerState.getTotalEventCounter();
}
efitime_t getStartOfRevolutionIndex(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engine->triggerCentral.triggerState.getStartOfRevolutionIndex();
}
void TriggerCentral::addEventListener(ShaftPositionListener listener, const char *name, Engine *engine) {
print("registerCkpListener: %s\r\n", name);
triggerListeneres.registerCallback((VoidInt)(void*)listener, engine);
@ -102,9 +94,6 @@ uint32_t triggerMaxDuration = 0;
static bool isInsideTriggerHandler = false;
static efitick_t previousVvtCamTime = 0;
static efitick_t previousVvtCamDuration = 0;
void hwHandleVvtCamSignal(trigger_value_e front) {
addEngineSnifferEvent(VVT_NAME, front == TV_RISE ? WC_UP : WC_DOWN);
@ -124,12 +113,12 @@ void hwHandleVvtCamSignal(trigger_value_e front) {
efitick_t nowNt = getTimeNowNt();
if (engineConfiguration->vvtMode == MIATA_NB2) {
uint32_t currentDuration = nowNt - previousVvtCamTime;
float ratio = ((float) currentDuration) / previousVvtCamDuration;
uint32_t currentDuration = nowNt - tc->previousVvtCamTime;
float ratio = ((float) currentDuration) / tc->previousVvtCamDuration;
previousVvtCamDuration = currentDuration;
previousVvtCamTime = nowNt;
tc->previousVvtCamDuration = currentDuration;
tc->previousVvtCamTime = nowNt;
if (engineConfiguration->isPrintTriggerSynchDetails) {
scheduleMsg(logger, "vvt ratio %.2f", ratio);
@ -225,7 +214,7 @@ void TriggerCentral::resetCounters() {
static char shaft_signal_msg_index[15];
static bool isUpEvent[6] = { false, true, false, true, false, true };
static const bool isUpEvent[6] = { false, true, false, true, false, true };
static const char *eventId[6] = { CRANK1, CRANK1, CRANK2, CRANK2, CRANK3, CRANK3 };
static ALWAYS_INLINE void reportEventToWaveChart(trigger_event_e ckpSignalType, int index DECLARE_ENGINE_PARAMETER_SUFFIX) {

View File

@ -41,6 +41,9 @@ public:
TriggerShape triggerShape;
efitick_t previousVvtCamTime = 0;
efitick_t previousVvtCamDuration = 0;
volatile efitime_t previousShaftEventTimeNt;
private:
IntListenerArray<15> triggerListeneres;
@ -54,7 +57,6 @@ private:
void triggerInfo(void);
efitime_t getCrankEventCounter(DECLARE_ENGINE_PARAMETER_SIGNATURE);
efitime_t getStartOfRevolutionIndex(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void hwHandleShaftSignal(trigger_event_e signal);
void hwHandleVvtCamSignal(trigger_value_e front);