From 5c0cbd2376990f51b809c183d679e64bee54c55b Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sat, 15 Nov 2014 13:03:19 -0600 Subject: [PATCH] auto-sync --- .../controllers/trigger/trigger_central.cpp | 33 +++++++++++-------- .../controllers/trigger/trigger_decoder.cpp | 11 ++++++- .../controllers/trigger/trigger_decoder.h | 4 +++ 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 2107a23792..54c80f4cb6 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -59,11 +59,19 @@ void addTriggerEventListener(ShaftPositionListener listener, const char *name, E } #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) -EXTERN_ENGINE; +EXTERN_ENGINE +; + +int triggerReentraint = 0; +int maxTriggerReentraint = 0; void hwHandleShaftSignal(trigger_event_e signal) { + if (triggerReentraint > maxTriggerReentraint) + maxTriggerReentraint = triggerReentraint; + triggerReentraint++; efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "lowstck#8"); triggerCentral.handleShaftSignal(engine, signal); + triggerReentraint--; } #endif /* EFI_PROD_CODE */ @@ -207,31 +215,30 @@ static void triggerInfo(Engine *engine) { triggerCentral.getHwEventCounter(1), triggerCentral.getHwEventCounter(2), triggerCentral.getHwEventCounter(3)); scheduleMsg(&logger, "expected cycle events %d/%d/%d", engineConfiguration2->triggerShape.expectedEventCount[0], - engineConfiguration2->triggerShape.expectedEventCount[1], - ts->expectedEventCount[2]); + engineConfiguration2->triggerShape.expectedEventCount[1], ts->expectedEventCount[2]); scheduleMsg(&logger, "trigger type=%d/need2ndChannel=%s", engineConfiguration->triggerConfig.triggerType, boolToString(engineConfiguration->needSecondTriggerInput)); scheduleMsg(&logger, "expected duty #0=%f/#1=%f", engineConfiguration2->triggerShape.dutyCycle[0], engineConfiguration2->triggerShape.dutyCycle[1]); - scheduleMsg(&logger, "isError %s/total errors=%d/total revolutions=%d/self=%s", + scheduleMsg(&logger, "isError %s/total errors=%d %d/total revolutions=%d/self=%s", boolToString(isTriggerDecoderError()), triggerCentral.triggerState.totalTriggerErrorCounter, + triggerCentral.triggerState.orderingErrorCounter, triggerCentral.triggerState.getTotalRevolutionCounter(), boolToString(engineConfiguration->directSelfStimulation)); #endif #if EFI_PROD_CODE - scheduleMsg(&logger, "primary trigger simulator: %s %s freq=%d", hwPortname(boardConfiguration->triggerSimulatorPins[0]), + scheduleMsg(&logger, "primary trigger simulator: %s %s freq=%d", + hwPortname(boardConfiguration->triggerSimulatorPins[0]), pinModeToString(boardConfiguration->triggerSimulatorPinModes[0]), - boardConfiguration->triggerSimulatorFrequency - ); - scheduleMsg(&logger, "secondary trigger simulator: %s %s phase=%d", hwPortname(boardConfiguration->triggerSimulatorPins[1]), - pinModeToString(boardConfiguration->triggerSimulatorPinModes[1]), - triggerSignal.safe.phaseIndex - ); + boardConfiguration->triggerSimulatorFrequency); + scheduleMsg(&logger, "secondary trigger simulator: %s %s phase=%d", + hwPortname(boardConfiguration->triggerSimulatorPins[1]), + pinModeToString(boardConfiguration->triggerSimulatorPinModes[1]), triggerSignal.safe.phaseIndex); scheduleMsg(&logger, "3rd trigger simulator: %s %s", hwPortname(boardConfiguration->triggerSimulatorPins[2]), pinModeToString(boardConfiguration->triggerSimulatorPinModes[2])); @@ -257,8 +264,8 @@ void initTriggerCentral(Engine *engine) { #if EFI_PROD_CODE || EFI_SIMULATOR initLogging(&logger, "ShaftPosition"); - addConsoleActionP("triggerinfo", (VoidPtr)triggerInfo, engine); - addConsoleActionP("triggershapeinfo", (VoidPtr)triggerShapeInfo, engine); + addConsoleActionP("triggerinfo", (VoidPtr) triggerInfo, engine); + addConsoleActionP("triggershapeinfo", (VoidPtr) triggerShapeInfo, engine); #endif #if EFI_HISTOGRAMS diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index fd86219caa..12e039c0e2 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -73,7 +73,8 @@ static ALWAYS_INLINE bool isSynchronizationGap(TriggerState *shaftPositionState, && currentDuration < shaftPositionState->toothed_previous_duration * triggerShape->syncRatioTo; } -static ALWAYS_INLINE bool noSynchronizationResetNeeded(TriggerState *shaftPositionState, trigger_shape_s const *triggerShape) { +static ALWAYS_INLINE bool noSynchronizationResetNeeded(TriggerState *shaftPositionState, + trigger_shape_s const *triggerShape) { if (triggerShape->isSynchronizationNeeded) { return false; } @@ -109,7 +110,15 @@ void TriggerState::decodeTriggerEvent(trigger_shape_s const*triggerShape, trigge trigger_wheel_e triggerWheel = eventIndex[signal]; + if (curSignal == prevSignal) { + orderingErrorCounter++; + } + + prevSignal = curSignal; + curSignal = signal; + eventCount[triggerWheel]++; + eventCountExt[signal]++; int isLessImportant = (triggerShape->useRiseEdge && signal != SHAFT_PRIMARY_UP) || (!triggerShape->useRiseEdge && signal != SHAFT_PRIMARY_DOWN); diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index 4cd01f9b6d..bd49f69752 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -52,6 +52,7 @@ public: uint32_t prevTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; int expectedTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; uint32_t totalTriggerErrorCounter; + uint32_t orderingErrorCounter; private: void clear(); @@ -64,6 +65,9 @@ private: * see trigger_shape_s */ uint32_t eventCount[PWM_PHASE_MAX_WAVE_PER_PWM]; + trigger_event_e curSignal; + trigger_event_e prevSignal; + uint32_t eventCountExt[2 * PWM_PHASE_MAX_WAVE_PER_PWM]; uint64_t timeOfPreviousEventNt[PWM_PHASE_MAX_WAVE_PER_PWM]; uint64_t totalEventCountBase; uint32_t totalRevolutionCounter;