refctoring trigger sync layer

This commit is contained in:
rusefi 2018-10-21 09:31:58 -04:00
parent 0c2d83b21c
commit c2be975f62
4 changed files with 28 additions and 24 deletions

View File

@ -733,5 +733,5 @@ int getRusEfiVersion(void) {
if (initBootloader() != 0)
return 123;
#endif /* EFI_BOOTLOADER_INCLUDE_CODE */
return 20180924;
return 20181021;
}

View File

@ -263,11 +263,11 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
bool primaryGap = currentDuration > toothed_previous_duration * TRIGGER_SHAPE(syncRatioFrom)
&& currentDuration < toothed_previous_duration * TRIGGER_SHAPE(syncRatioTo);
bool secondaryGap = cisnan(TRIGGER_SHAPE(secondSyncRatioFrom)) || (toothed_previous_duration > durationBeforePrevious * TRIGGER_SHAPE(secondSyncRatioFrom)
&& toothed_previous_duration < durationBeforePrevious * TRIGGER_SHAPE(secondSyncRatioTo));
bool secondaryGap = cisnan(TRIGGER_SHAPE(syncronizationRatioFrom[1])) || (toothed_previous_duration > durationBeforePrevious * TRIGGER_SHAPE(syncronizationRatioFrom[1])
&& toothed_previous_duration < durationBeforePrevious * TRIGGER_SHAPE(syncronizationRatioTo[1]));
bool thirdGap = cisnan(TRIGGER_SHAPE(thirdSyncRatioFrom)) || (durationBeforePrevious > thirdPreviousDuration * TRIGGER_SHAPE(thirdSyncRatioFrom)
&& durationBeforePrevious < thirdPreviousDuration * TRIGGER_SHAPE(thirdSyncRatioTo));
bool thirdGap = cisnan(TRIGGER_SHAPE(syncronizationRatioFrom[2])) || (durationBeforePrevious > thirdPreviousDuration * TRIGGER_SHAPE(syncronizationRatioFrom[2])
&& durationBeforePrevious < thirdPreviousDuration * TRIGGER_SHAPE(syncronizationRatioTo[2]));
/**
* Here I prefer to have two multiplications instead of one division, that's a micro-optimization
@ -290,8 +290,8 @@ void TriggerState::decodeTriggerEvent(trigger_event_e const signal, efitime_t no
gap, prevGap, gap3,
currentCycle.current_index,
TRIGGER_SHAPE(syncRatioFrom), TRIGGER_SHAPE(syncRatioTo),
TRIGGER_SHAPE(secondSyncRatioFrom), TRIGGER_SHAPE(secondSyncRatioTo),
TRIGGER_SHAPE(thirdSyncRatioFrom), TRIGGER_SHAPE(thirdSyncRatioTo),
TRIGGER_SHAPE(syncronizationRatioFrom[1]), TRIGGER_SHAPE(syncronizationRatioTo[1]),
TRIGGER_SHAPE(syncronizationRatioFrom[2]), TRIGGER_SHAPE(syncronizationRatioTo[2]),
someSortOfTriggerError);
#else
actualSynchGap = gap;

View File

@ -105,10 +105,10 @@ void TriggerShape::initialize(operation_mode_e operationMode, bool needSecondTri
// memset(triggerIndexByAngle, 0, sizeof(triggerIndexByAngle));
setTriggerSynchronizationGap(2);
secondSyncRatioFrom = NAN; // NaN means do not use this ratio
secondSyncRatioTo = 100000;
thirdSyncRatioFrom = NAN; // NaN means do not use this ratio
thirdSyncRatioTo = 100000;
syncronizationRatioFrom[1] = NAN; // NaN means do not use this ratio
syncronizationRatioTo[1] = 100000;
syncronizationRatioFrom[2] = NAN; // NaN means do not use this ratio
syncronizationRatioTo[2] = 100000;
tdcPosition = 0;
@ -457,8 +457,8 @@ void TriggerShape::setTriggerSynchronizationGap(float syncRatio) {
void TriggerShape::setSecondTriggerSynchronizationGap2(float syncRatioFrom, float syncRatioTo) {
isSynchronizationNeeded = true;
this->secondSyncRatioFrom = syncRatioFrom;
this->secondSyncRatioTo = syncRatioTo;
this->syncronizationRatioFrom[1] = syncRatioFrom;
this->syncronizationRatioTo[1] = syncRatioTo;
}
void TriggerShape::setThirdTriggerSynchronizationGap(float syncRatio) {
@ -467,8 +467,8 @@ void TriggerShape::setThirdTriggerSynchronizationGap(float syncRatio) {
void TriggerShape::setThirdTriggerSynchronizationGap2(float syncRatioFrom, float syncRatioTo) {
isSynchronizationNeeded = true;
this->thirdSyncRatioFrom = syncRatioFrom;
this->thirdSyncRatioTo = syncRatioTo;
this->syncronizationRatioFrom[2] = syncRatioFrom;
this->syncronizationRatioTo[2] = syncRatioTo;
}
void TriggerShape::setSecondTriggerSynchronizationGap(float syncRatio) {

View File

@ -45,6 +45,8 @@ private:
class Engine;
class TriggerState;
#define GAP_TRACKING_LENGHT 3
/**
* @brief Trigger shape has all the fields needed to describe and decode trigger signal.
* @see TriggerState for trigger decoder state which works based on this trigger shape model
@ -89,6 +91,17 @@ public:
*/
int triggerIndexByAngle[720];
/**
* Depending on trigger shape, we use betweeb one and three previous gap ranges to detect synchronizaiton.
*
* Usually second or third gap is not needed, but some crazy triggers like 36-2-2-2 require two consecutive
* gaps ratios to sync
*/
float syncronizationRatioFrom[GAP_TRACKING_LENGHT];
float syncronizationRatioTo[GAP_TRACKING_LENGHT];
float syncRatioFrom;
float syncRatioTo;
/**
@ -96,15 +109,6 @@ public:
*/
int syncRatioAvg;
/**
* Usually this is not needed, but some crazy triggers like 36-2-2-2 require two consecutive
* gaps ratios to sync
*/
float secondSyncRatioFrom;
float secondSyncRatioTo;
float thirdSyncRatioFrom;
float thirdSyncRatioTo;
/**
* Trigger indexes within trigger cycle are counted from synchronization point, and all