auto-sync

This commit is contained in:
rusEfi 2014-11-15 13:03:19 -06:00
parent bc4ce1729f
commit c64a27e5bd
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__)
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]));

View File

@ -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);

View File

@ -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;