From 514531bc5cd1e48a64f5d46753450e4de8e884be Mon Sep 17 00:00:00 2001 From: rusefi Date: Sat, 18 Jun 2022 14:17:36 -0400 Subject: [PATCH] verbose trigger sync should reuse engineSnifferRpmThreshold #4259 reducing complexity --- firmware/controllers/algo/engine.cpp | 2 +- firmware/controllers/algo/engine.h | 10 ++++++---- firmware/controllers/algo/engine_configuration.cpp | 2 -- firmware/controllers/engine_cycle/rpm_calculator.cpp | 10 +++++++++- firmware/controllers/engine_cycle/rpm_calculator.h | 2 +- firmware/controllers/trigger/trigger_central.cpp | 2 +- firmware/development/engine_sniffer.cpp | 6 +++--- 7 files changed, 21 insertions(+), 13 deletions(-) diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 0c5afbc665..9335d503f1 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -274,7 +274,7 @@ void Engine::updateSlowSensors() { #if EFI_ENGINE_CONTROL int rpm = Sensor::getOrZero(SensorType::Rpm); - isEngineChartEnabled = engineConfiguration->isEngineChartEnabled && rpm < engineConfiguration->engineSnifferRpmThreshold; + isEngineSnifferEnabled = rpm < engineConfiguration->engineSnifferRpmThreshold; sensorChartMode = rpm < engineConfiguration->sensorSnifferRpmThreshold ? engineConfiguration->sensorChartMode : SC_OFF; engineState.updateSlowSensors(); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 2a4c16fe69..c29787c350 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -280,7 +280,7 @@ public: #endif #if EFI_UNIT_TEST TestExecutor executor; -#endif +#endif // EFI_UNIT_TEST #if EFI_ENGINE_CONTROL FuelSchedule injectionEvents; @@ -290,11 +290,13 @@ public: bool etbAutoTune = false; /** - * this is based on isEngineChartEnabled and engineSnifferRpmThreshold settings + * this is based on engineSnifferRpmThreshold settings and current RPM */ - bool isEngineChartEnabled = false; + bool isEngineSnifferEnabled = false; - bool tdcMarkEnabled = true; // used by unit tests only +#if EFI_UNIT_TEST + bool tdcMarkEnabled = true; +#endif // EFI_UNIT_TEST /** * this is based on sensorChartMode and sensorSnifferRpmThreshold settings diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index bb6266c37b..c5adac6266 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -656,8 +656,6 @@ static void setDefaultEngineConfiguration() { engineConfiguration->baroSensor.lowValue = 0; engineConfiguration->baroSensor.highValue = 500; - engineConfiguration->isEngineChartEnabled = true; - #if EFI_PROD_CODE engineConfiguration->engineChartSize = 300; #else diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index b4bdd56df2..200c99c0fe 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -332,7 +332,15 @@ static void onTdcCallback(void *) { void tdcMarkCallback( uint32_t index0, efitick_t edgeTimestamp) { bool isTriggerSynchronizationPoint = index0 == 0; - if (isTriggerSynchronizationPoint && engine->isEngineChartEnabled && engine->tdcMarkEnabled) { + if (isTriggerSynchronizationPoint && engine->isEngineSnifferEnabled) { + +#if EFI_UNIT_TEST + if (!engine->tdcMarkEnabled) { + return; + } +#endif // EFI_UNIT_TEST + + // two instances of scheduling_s are needed to properly handle event overlap int revIndex2 = getRevolutionCounter() % 2; int rpm = Sensor::getOrZero(SensorType::Rpm); diff --git a/firmware/controllers/engine_cycle/rpm_calculator.h b/firmware/controllers/engine_cycle/rpm_calculator.h index 4b877f66f0..7e7fd26bc4 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.h +++ b/firmware/controllers/engine_cycle/rpm_calculator.h @@ -174,7 +174,7 @@ void initRpmCalculator(); #define getRevolutionCounter() (engine->rpmCalculator.getRevolutionCounterM()) #if EFI_ENGINE_SNIFFER -#define addEngineSnifferEvent(name, msg) { if (engine->isEngineChartEnabled) { waveChart.addEvent3((name), (msg)); } } +#define addEngineSnifferEvent(name, msg) { if (engine->isEngineSnifferEnabled) { waveChart.addEvent3((name), (msg)); } } #else #define addEngineSnifferEvent(n, msg) {} #endif /* EFI_ENGINE_SNIFFER */ diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 6fa6367466..e1a8c3ef1b 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -510,7 +510,7 @@ static const bool isUpEvent[6] = { false, true, false, true, false, true }; static const char *eventId[6] = { PROTOCOL_CRANK1, PROTOCOL_CRANK1, PROTOCOL_CRANK2, PROTOCOL_CRANK2, PROTOCOL_CRANK3, PROTOCOL_CRANK3 }; static void reportEventToWaveChart(trigger_event_e ckpSignalType, int index) { - if (!engine->isEngineChartEnabled) { // this is here just as a shortcut so that we avoid engine sniffer as soon as possible + if (!engine->isEngineSnifferEnabled) { // this is here just as a shortcut so that we avoid engine sniffer as soon as possible return; // engineSnifferRpmThreshold is accounted for inside engine->isEngineChartEnabled } diff --git a/firmware/development/engine_sniffer.cpp b/firmware/development/engine_sniffer.cpp index 55c29748c0..b30b8e4159 100644 --- a/firmware/development/engine_sniffer.cpp +++ b/firmware/development/engine_sniffer.cpp @@ -145,7 +145,7 @@ void WaveChart::publish() { Logging *l = &chart->logging; efiPrintf("IT'S TIME", strlen(l->buffer)); #endif - if (engine->isEngineChartEnabled) { + if (engine->isEngineSnifferEnabled) { scheduleLogging(&logging); } } @@ -154,14 +154,14 @@ void WaveChart::publish() { * @brief Register an event for digital sniffer */ void WaveChart::addEvent3(const char *name, const char * msg) { +#if EFI_TEXT_LOGGING ScopePerf perf(PE::EngineSniffer); efitick_t nowNt = getTimeNowNt(); if (nowNt < pauseEngineSnifferUntilNt) { return; } -#if EFI_TEXT_LOGGING - if (!engine->isEngineChartEnabled) { + if (!engine->isEngineSnifferEnabled) { return; } if (skipUntilEngineCycle != 0 && getRevolutionCounter() < skipUntilEngineCycle)