auto-sync

This commit is contained in:
rusEfi 2014-11-15 13:03:19 -06:00
parent 5c9804e473
commit 5c0cbd2376
3 changed files with 34 additions and 14 deletions

View File

@ -59,11 +59,19 @@ void addTriggerEventListener(ShaftPositionListener listener, const char *name, E
} }
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) #if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
EXTERN_ENGINE; EXTERN_ENGINE
;
int triggerReentraint = 0;
int maxTriggerReentraint = 0;
void hwHandleShaftSignal(trigger_event_e signal) { void hwHandleShaftSignal(trigger_event_e signal) {
if (triggerReentraint > maxTriggerReentraint)
maxTriggerReentraint = triggerReentraint;
triggerReentraint++;
efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "lowstck#8"); efiAssertVoid(getRemainingStack(chThdSelf()) > 256, "lowstck#8");
triggerCentral.handleShaftSignal(engine, signal); triggerCentral.handleShaftSignal(engine, signal);
triggerReentraint--;
} }
#endif /* EFI_PROD_CODE */ #endif /* EFI_PROD_CODE */
@ -207,31 +215,30 @@ static void triggerInfo(Engine *engine) {
triggerCentral.getHwEventCounter(1), triggerCentral.getHwEventCounter(2), triggerCentral.getHwEventCounter(1), triggerCentral.getHwEventCounter(2),
triggerCentral.getHwEventCounter(3)); triggerCentral.getHwEventCounter(3));
scheduleMsg(&logger, "expected cycle events %d/%d/%d", engineConfiguration2->triggerShape.expectedEventCount[0], scheduleMsg(&logger, "expected cycle events %d/%d/%d", engineConfiguration2->triggerShape.expectedEventCount[0],
engineConfiguration2->triggerShape.expectedEventCount[1], engineConfiguration2->triggerShape.expectedEventCount[1], ts->expectedEventCount[2]);
ts->expectedEventCount[2]);
scheduleMsg(&logger, "trigger type=%d/need2ndChannel=%s", engineConfiguration->triggerConfig.triggerType, scheduleMsg(&logger, "trigger type=%d/need2ndChannel=%s", engineConfiguration->triggerConfig.triggerType,
boolToString(engineConfiguration->needSecondTriggerInput)); boolToString(engineConfiguration->needSecondTriggerInput));
scheduleMsg(&logger, "expected duty #0=%f/#1=%f", engineConfiguration2->triggerShape.dutyCycle[0], scheduleMsg(&logger, "expected duty #0=%f/#1=%f", engineConfiguration2->triggerShape.dutyCycle[0],
engineConfiguration2->triggerShape.dutyCycle[1]); 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()), boolToString(isTriggerDecoderError()),
triggerCentral.triggerState.totalTriggerErrorCounter, triggerCentral.triggerState.totalTriggerErrorCounter,
triggerCentral.triggerState.orderingErrorCounter,
triggerCentral.triggerState.getTotalRevolutionCounter(), triggerCentral.triggerState.getTotalRevolutionCounter(),
boolToString(engineConfiguration->directSelfStimulation)); boolToString(engineConfiguration->directSelfStimulation));
#endif #endif
#if EFI_PROD_CODE #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]), pinModeToString(boardConfiguration->triggerSimulatorPinModes[0]),
boardConfiguration->triggerSimulatorFrequency boardConfiguration->triggerSimulatorFrequency);
); scheduleMsg(&logger, "secondary trigger simulator: %s %s phase=%d",
scheduleMsg(&logger, "secondary trigger simulator: %s %s phase=%d", hwPortname(boardConfiguration->triggerSimulatorPins[1]), hwPortname(boardConfiguration->triggerSimulatorPins[1]),
pinModeToString(boardConfiguration->triggerSimulatorPinModes[1]), pinModeToString(boardConfiguration->triggerSimulatorPinModes[1]), triggerSignal.safe.phaseIndex);
triggerSignal.safe.phaseIndex
);
scheduleMsg(&logger, "3rd trigger simulator: %s %s", hwPortname(boardConfiguration->triggerSimulatorPins[2]), scheduleMsg(&logger, "3rd trigger simulator: %s %s", hwPortname(boardConfiguration->triggerSimulatorPins[2]),
pinModeToString(boardConfiguration->triggerSimulatorPinModes[2])); pinModeToString(boardConfiguration->triggerSimulatorPinModes[2]));
@ -257,8 +264,8 @@ void initTriggerCentral(Engine *engine) {
#if EFI_PROD_CODE || EFI_SIMULATOR #if EFI_PROD_CODE || EFI_SIMULATOR
initLogging(&logger, "ShaftPosition"); initLogging(&logger, "ShaftPosition");
addConsoleActionP("triggerinfo", (VoidPtr)triggerInfo, engine); addConsoleActionP("triggerinfo", (VoidPtr) triggerInfo, engine);
addConsoleActionP("triggershapeinfo", (VoidPtr)triggerShapeInfo, engine); addConsoleActionP("triggershapeinfo", (VoidPtr) triggerShapeInfo, engine);
#endif #endif
#if EFI_HISTOGRAMS #if EFI_HISTOGRAMS

View File

@ -73,7 +73,8 @@ static ALWAYS_INLINE bool isSynchronizationGap(TriggerState *shaftPositionState,
&& currentDuration < shaftPositionState->toothed_previous_duration * triggerShape->syncRatioTo; && 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) { if (triggerShape->isSynchronizationNeeded) {
return false; return false;
} }
@ -109,7 +110,15 @@ void TriggerState::decodeTriggerEvent(trigger_shape_s const*triggerShape, trigge
trigger_wheel_e triggerWheel = eventIndex[signal]; trigger_wheel_e triggerWheel = eventIndex[signal];
if (curSignal == prevSignal) {
orderingErrorCounter++;
}
prevSignal = curSignal;
curSignal = signal;
eventCount[triggerWheel]++; eventCount[triggerWheel]++;
eventCountExt[signal]++;
int isLessImportant = (triggerShape->useRiseEdge && signal != SHAFT_PRIMARY_UP) int isLessImportant = (triggerShape->useRiseEdge && signal != SHAFT_PRIMARY_UP)
|| (!triggerShape->useRiseEdge && signal != SHAFT_PRIMARY_DOWN); || (!triggerShape->useRiseEdge && signal != SHAFT_PRIMARY_DOWN);

View File

@ -52,6 +52,7 @@ public:
uint32_t prevTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; uint32_t prevTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM];
int expectedTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; int expectedTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM];
uint32_t totalTriggerErrorCounter; uint32_t totalTriggerErrorCounter;
uint32_t orderingErrorCounter;
private: private:
void clear(); void clear();
@ -64,6 +65,9 @@ private:
* see trigger_shape_s * see trigger_shape_s
*/ */
uint32_t eventCount[PWM_PHASE_MAX_WAVE_PER_PWM]; 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 timeOfPreviousEventNt[PWM_PHASE_MAX_WAVE_PER_PWM];
uint64_t totalEventCountBase; uint64_t totalEventCountBase;
uint32_t totalRevolutionCounter; uint32_t totalRevolutionCounter;