From 98207669aa8d9a3495c3131dfc927a1ae6856f10 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sat, 12 Sep 2015 17:01:24 -0400 Subject: [PATCH] auto-sync --- .../controllers/trigger/trigger_decoder.cpp | 6 ++- .../controllers/trigger/trigger_decoder.h | 4 ++ .../controllers/trigger/trigger_structure.cpp | 6 +-- .../controllers/trigger/trigger_structure.h | 37 ++++++++++++------- firmware/svnversion.h | 4 +- 5 files changed, 36 insertions(+), 21 deletions(-) diff --git a/firmware/controllers/trigger/trigger_decoder.cpp b/firmware/controllers/trigger/trigger_decoder.cpp index 4cc4245ddc..bb778790b1 100644 --- a/firmware/controllers/trigger/trigger_decoder.cpp +++ b/firmware/controllers/trigger/trigger_decoder.cpp @@ -121,6 +121,8 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no prevSignal = curSignal; curSignal = signal; + timeOfLastEvent[currentCycle.current_index] = nowNt; + currentCycle.eventCount[triggerWheel]++; efitime_t currentDurationLong = getCurrentGapDuration(nowNt); @@ -288,8 +290,8 @@ void initializeSkippedToothTriggerShapeExt(TriggerShape *s, int totalTeethCount, operation_mode_e operationMode) { efiAssertVoid(totalTeethCount > 0, "totalTeethCount is zero"); - s->totalToothCount = totalTeethCount; - s->skippedToothCount = skippedCount; +// s->totalToothCount = totalTeethCount; +// s->skippedToothCount = skippedCount; s->setTriggerSynchronizationGap(skippedCount + 1); s->isSynchronizationNeeded = (skippedCount != 0); diff --git a/firmware/controllers/trigger/trigger_decoder.h b/firmware/controllers/trigger/trigger_decoder.h index ec3208d452..8c96a1f31c 100644 --- a/firmware/controllers/trigger/trigger_decoder.h +++ b/firmware/controllers/trigger/trigger_decoder.h @@ -76,6 +76,10 @@ public: */ uint32_t prevTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; int expectedTotalTime[PWM_PHASE_MAX_WAVE_PER_PWM]; + + uint32_t timeOfLastEvent[PWM_PHASE_MAX_COUNT]; + float instantRpmValue[PWM_PHASE_MAX_COUNT]; + /** * how many times since ECU reboot we had unexpected number of teeth in trigger cycle */ diff --git a/firmware/controllers/trigger/trigger_structure.cpp b/firmware/controllers/trigger/trigger_structure.cpp index 56a4507b86..1f849ebf73 100644 --- a/firmware/controllers/trigger/trigger_structure.cpp +++ b/firmware/controllers/trigger/trigger_structure.cpp @@ -45,7 +45,7 @@ TriggerShape::TriggerShape() : // todo: reuse 'clear' method? invertOnAdd = false; tdcPosition = 0; - skippedToothCount = totalToothCount = 0; +// skippedToothCount = totalToothCount = 0; syncRatioFrom = syncRatioTo = 0; secondSyncRatioFrom = 0.000001; secondSyncRatioTo = 100000; @@ -230,7 +230,7 @@ float TriggerShape::getAngle(int index) const { } } -void TriggerShape::addEvent(float angle, trigger_wheel_e const waveIndex, trigger_value_e const stateParam, float filterLeft, float filterRight) { +void TriggerShape::addEvent(angle_t angle, trigger_wheel_e const waveIndex, trigger_value_e const stateParam, float filterLeft, float filterRight) { if (angle > filterLeft && angle < filterRight) addEvent(angle, waveIndex, stateParam); } @@ -243,7 +243,7 @@ operation_mode_e TriggerShape::getOperationMode() { extern bool printTriggerDebug; #endif -void TriggerShape::addEvent(float angle, trigger_wheel_e const waveIndex, trigger_value_e const stateParam) { +void TriggerShape::addEvent(angle_t angle, trigger_wheel_e const waveIndex, trigger_value_e const stateParam) { efiAssertVoid(operationMode != OM_NONE, "operationMode not set"); efiAssertVoid(waveIndex!= T_SECONDARY || needSecondTriggerInput, "secondary needed or not?"); diff --git a/firmware/controllers/trigger/trigger_structure.h b/firmware/controllers/trigger/trigger_structure.h index bb261c3d8a..3a68078e19 100644 --- a/firmware/controllers/trigger/trigger_structure.h +++ b/firmware/controllers/trigger/trigger_structure.h @@ -27,6 +27,9 @@ private: class Engine; +/** + * @brief Trigger shape has all the fields needed to describe and decode trigger signal. + */ class TriggerShape { public: TriggerShape(); @@ -35,14 +38,22 @@ public: bool_t isSynchronizationNeeded; bool_t needSecondTriggerInput; - int totalToothCount; - int skippedToothCount; +// int totalToothCount; +// int skippedToothCount; + /** + * duty cycle for each individual trigger channel + */ float dutyCycle[PWM_PHASE_MAX_WAVE_PER_PWM]; + /** + * These angles are in event coordinates - with synchronization point located at angle zero. + * These values are pre-calculated for performance reasons. + */ + angle_t eventAngles[PWM_PHASE_MAX_COUNT]; /** * this cache allows us to find a close-enough (with one degree precision) trigger wheel index by - * given angle with fast constant speed + * given angle with fast constant speed. That's a performance optimization for event scheduling. */ int triggerIndexByAngle[720]; @@ -67,6 +78,9 @@ public: */ bool_t useRiseEdge; + /** + * In case of a multi-channel trigger, do we want to sync based on primary channel only? + */ bool_t useOnlyPrimaryForSync; /** * Should we measure gaps with events of both kinds? @@ -91,15 +105,6 @@ public: // tood: maybe even automate this flag calculation? int initialState[PWM_PHASE_MAX_WAVE_PER_PWM]; - /** - * These angles are in event coordinates - with synchronization point located at angle zero. - * These values are pre-calculated for performance reasons. - */ - float eventAngles[PWM_PHASE_MAX_COUNT]; - - uint32_t timeOfLastEvent[PWM_PHASE_MAX_COUNT]; - float instantRpmValue[PWM_PHASE_MAX_COUNT]; - int8_t isFrontEvent[PWM_PHASE_MAX_COUNT]; /** * this table translates trigger definition index into 'front-only' index. This translation is not so trivial @@ -107,6 +112,9 @@ public: */ int frontOnlyIndexes[PWM_PHASE_MAX_COUNT]; + /** + * This is a pretty questionable option which is considered by 'addEvent' method + */ bool_t invertOnAdd; /** * Total count of shaft events per CAM or CRANK shaft revolution. @@ -115,8 +123,8 @@ public: */ int size; - void addEvent(float angle, trigger_wheel_e const waveIndex, trigger_value_e const state); - void addEvent(float angle, trigger_wheel_e const waveIndex, trigger_value_e const stateParam, float filterLeft, float filterRight); + void addEvent(angle_t angle, trigger_wheel_e const waveIndex, trigger_value_e const state); + void addEvent(angle_t angle, trigger_wheel_e const waveIndex, trigger_value_e const stateParam, float filterLeft, float filterRight); operation_mode_e getOperationMode(); // todo: these two methods here, something could be improved @@ -143,6 +151,7 @@ private: */ int triggerShapeSynchPointIndex; /** + * Working buffer for 'wave' instance * Values are in the 0..1 range */ float switchTimesBuffer[PWM_PHASE_MAX_COUNT]; diff --git a/firmware/svnversion.h b/firmware/svnversion.h index 0985ece98c..f9e52c0e26 100644 --- a/firmware/svnversion.h +++ b/firmware/svnversion.h @@ -1,5 +1,5 @@ // This file was generated by Version2Header -// Mon Sep 07 22:47:08 EDT 2015 +// Sat Sep 12 16:00:07 EDT 2015 #ifndef VCS_VERSION -#define VCS_VERSION "8764" +#define VCS_VERSION "8791" #endif