From 8c32b13567b63bb6005c262a3ced806977f161fe Mon Sep 17 00:00:00 2001 From: rusefillc Date: Sun, 4 Oct 2020 01:43:02 -0400 Subject: [PATCH] 60/2 perf grab #1850 a) removing more of stack validating - one validation within the deepest method would be enough b) un-wrapping main callback loop for explicit order of execution --- .../engine_cycle/main_trigger_callback.cpp | 3 +-- .../engine_cycle/main_trigger_callback.h | 2 ++ .../engine_cycle/map_averaging.cpp | 6 +---- .../controllers/engine_cycle/map_averaging.h | 3 +++ .../engine_cycle/rpm_calculator.cpp | 8 +------ .../controllers/engine_cycle/rpm_calculator.h | 6 ++++- .../controllers/trigger/trigger_central.cpp | 22 +++++++++++++++++++ 7 files changed, 35 insertions(+), 15 deletions(-) diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index 8169e5cf48..db2bd03283 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -368,7 +368,7 @@ uint32_t *cyccnt = (uint32_t*) &DWT->CYCCNT; * This is the main trigger event handler. * Both injection and ignition are controlled from this method. */ -static void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX) { +void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX) { ScopePerf perf(PE::MainTriggerCallback); (void) ckpSignalType; @@ -559,7 +559,6 @@ void initMainEventListener(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX printMsg(logger, "!!!!!!!!!!!!!!!!!!! injection disabled"); #endif - addTriggerEventListener(mainTriggerCallback, "main loop", engine); // We start prime injection pulse at the early init stage - don't wait for the engine to start spinning! if (CONFIG(startOfCrankingPrimingPulse) > 0) diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.h b/firmware/controllers/engine_cycle/main_trigger_callback.h index a61e0ca5f4..62e6e0201e 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.h +++ b/firmware/controllers/engine_cycle/main_trigger_callback.h @@ -15,6 +15,8 @@ void initMainEventListener(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX); +void mainTriggerCallback(trigger_event_e ckpSignalType, uint32_t trgEventIndex, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX); + void startPrimeInjectionPulse(DECLARE_ENGINE_PARAMETER_SIGNATURE); void startSimultaniousInjection(Engine *engine); diff --git a/firmware/controllers/engine_cycle/map_averaging.cpp b/firmware/controllers/engine_cycle/map_averaging.cpp index af7a19c5de..071100984a 100644 --- a/firmware/controllers/engine_cycle/map_averaging.cpp +++ b/firmware/controllers/engine_cycle/map_averaging.cpp @@ -267,7 +267,7 @@ void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { /** * Shaft Position callback used to schedule start and end of MAP averaging */ -static void mapAveragingTriggerCallback(trigger_event_e ckpEventType, +void mapAveragingTriggerCallback(trigger_event_e ckpEventType, uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX) { ScopePerf perf(PE::MapAveragingTriggerCallback); @@ -351,10 +351,6 @@ void initMapAveraging(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { logger = sharedLogger; #if !EFI_UNIT_TEST -#if EFI_SHAFT_POSITION_INPUT - addTriggerEventListener(&mapAveragingTriggerCallback, "MAP averaging", engine); -#endif /* EFI_SHAFT_POSITION_INPUT */ - addConsoleAction("faststat", showMapStats); #endif /* EFI_UNIT_TEST */ diff --git a/firmware/controllers/engine_cycle/map_averaging.h b/firmware/controllers/engine_cycle/map_averaging.h index 1596f42f94..3b0fe66b66 100644 --- a/firmware/controllers/engine_cycle/map_averaging.h +++ b/firmware/controllers/engine_cycle/map_averaging.h @@ -18,6 +18,9 @@ void mapAveragingAdcCallback(adcsample_t newValue); void initMapAveraging(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX); void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE); +void mapAveragingTriggerCallback(trigger_event_e ckpEventType, + uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX); + #if EFI_TUNER_STUDIO void postMapState(TunerStudioOutputChannels *tsOutputChannels); #endif diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 6579bde843..160e0fd427 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -241,7 +241,6 @@ void RpmCalculator::setSpinningUp(efitick_t nowNt) { */ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, efitick_t nowNt DECLARE_ENGINE_PARAMETER_SUFFIX) { - efiAssertVoid(CUSTOM_ERR_6632, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "lowstckRCL"); RpmCalculator *rpmState = &engine->rpmCalculator; @@ -326,7 +325,7 @@ static void onTdcCallback(Engine *engine) { /** * This trigger callback schedules the actual physical TDC callback in relation to trigger synchronization point. */ -static void tdcMarkCallback(trigger_event_e ckpSignalType, +void tdcMarkCallback(trigger_event_e ckpSignalType, uint32_t index0, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX) { (void) ckpSignalType; bool isTriggerSynchronizationPoint = index0 == 0; @@ -377,11 +376,6 @@ void initRpmCalculator(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { ENGINE(rpmCalculator).Register(); } -#if !EFI_UNIT_TEST - addTriggerEventListener(tdcMarkCallback, "chart TDC mark", engine); -#endif - - addTriggerEventListener(rpmShaftPositionCallback, "rpm reporter", engine); } /** diff --git a/firmware/controllers/engine_cycle/rpm_calculator.h b/firmware/controllers/engine_cycle/rpm_calculator.h index fdf159c324..6b33859a6a 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.h +++ b/firmware/controllers/engine_cycle/rpm_calculator.h @@ -154,7 +154,11 @@ private: #define isValidRpm(rpm) ((rpm) > 0 && (rpm) < UNREALISTIC_RPM) -void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index DECLARE_ENGINE_PARAMETER_SUFFIX); +void rpmShaftPositionCallback(trigger_event_e ckpSignalType, uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX); + +void tdcMarkCallback(trigger_event_e ckpSignalType, + uint32_t index0, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX); + /** * @brief Initialize RPM calculator */ diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index d2418911ca..ffb59dce0a 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -25,6 +25,9 @@ #include "rpm_calculator.h" #include "tooth_logger.h" #include "perf_trace.h" +#include "map_averaging.h" +#include "main_trigger_callback.h" + #if EFI_PROD_CODE #include "pin_repository.h" @@ -482,6 +485,22 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta scheduleMsg(logger, "trigger %d %d %d", triggerIndexForListeners, getRevolutionCounter(), (int)getTimeNowUs()); #endif /* TRIGGER_EXTREME_LOGGING */ + + rpmShaftPositionCallback(signal, triggerIndexForListeners, timestamp PASS_ENGINE_PARAMETER_SUFFIX); + +#if !EFI_UNIT_TEST + tdcMarkCallback(signal, triggerIndexForListeners, timestamp PASS_ENGINE_PARAMETER_SUFFIX); +#endif + +#if !EFI_UNIT_TEST +#if EFI_SHAFT_POSITION_INPUT + mapAveragingTriggerCallback(signal, triggerIndexForListeners, timestamp PASS_ENGINE_PARAMETER_SUFFIX); +#endif /* EFI_SHAFT_POSITION_INPUT */ +#endif /* EFI_UNIT_TEST */ + +//auxValveTriggerCallback + + /** * Here we invoke all the listeners - the main engine control logic is inside these listeners */ @@ -490,6 +509,9 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta (listener)(signal, triggerIndexForListeners, timestamp PASS_ENGINE_PARAMETER_SUFFIX); } + mainTriggerCallback(signal, triggerIndexForListeners, timestamp PASS_ENGINE_PARAMETER_SUFFIX); + + } }