docs & names

This commit is contained in:
rusefi 2018-02-06 01:16:34 +03:00
parent eaf6440530
commit 3d5e93534d
6 changed files with 31 additions and 17 deletions

View File

@ -148,7 +148,7 @@ void hwHandleVvtCamSignal(trigger_value_e front) {
* let's increase the trigger event counter, that would adjust the state of * let's increase the trigger event counter, that would adjust the state of
* virtual crank-based trigger * virtual crank-based trigger
*/ */
tc->triggerState.intTotalEventCounter(); tc->triggerState.incrementTotalEventCounter();
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
if (engineConfiguration->debugMode == DBG_VVT) { if (engineConfiguration->debugMode == DBG_VVT) {
tsOutputChannels.debugIntField1++; tsOutputChannels.debugIntField1++;
@ -160,7 +160,7 @@ void hwHandleVvtCamSignal(trigger_value_e front) {
if (isEven) { if (isEven) {
// see above comment // see above comment
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
tc->triggerState.intTotalEventCounter(); tc->triggerState.incrementTotalEventCounter();
if (engineConfiguration->debugMode == DBG_VVT) { if (engineConfiguration->debugMode == DBG_VVT) {
tsOutputChannels.debugIntField1++; tsOutputChannels.debugIntField1++;
} }
@ -172,7 +172,7 @@ void hwHandleVvtCamSignal(trigger_value_e front) {
* NB2 is a symmetrical crank, there are four phases total * NB2 is a symmetrical crank, there are four phases total
*/ */
while (tc->triggerState.getTotalRevolutionCounter() % 4 != engineConfiguration->nbVvtIndex) { while (tc->triggerState.getTotalRevolutionCounter() % 4 != engineConfiguration->nbVvtIndex) {
tc->triggerState.intTotalEventCounter(); tc->triggerState.incrementTotalEventCounter();
} }
} }
@ -468,7 +468,7 @@ void triggerInfo(void) {
scheduleMsg(logger, "trigger type=%d/need2ndChannel=%s", engineConfiguration->trigger.type, scheduleMsg(logger, "trigger type=%d/need2ndChannel=%s", engineConfiguration->trigger.type,
boolToString(TRIGGER_SHAPE(needSecondTriggerInput))); boolToString(TRIGGER_SHAPE(needSecondTriggerInput)));
scheduleMsg(logger, "expected duty #0=%.2f/#1=%.2f", TRIGGER_SHAPE(dutyCycle[0]), TRIGGER_SHAPE(dutyCycle[1])); scheduleMsg(logger, "expected duty #0=%.2f/#1=%.2f", TRIGGER_SHAPE(expectedDutyCycle[0]), TRIGGER_SHAPE(expectedDutyCycle[1]));
scheduleMsg(logger, "synchronizationNeeded=%s/isError=%s/total errors=%d ord_err=%d/total revolutions=%d/self=%s", scheduleMsg(logger, "synchronizationNeeded=%s/isError=%s/total errors=%d ord_err=%d/total revolutions=%d/self=%s",
boolToString(ts->isSynchronizationNeeded), boolToString(ts->isSynchronizationNeeded),

View File

@ -114,12 +114,12 @@ static trigger_value_e eventType[6] = { TV_FALL, TV_RISE, TV_FALL, TV_RISE, TV_F
} }
#define nextRevolution() { \ #define nextRevolution() { \
if (cycleCallback != NULL) { \ if (triggerCycleCallback != NULL) { \
cycleCallback(this); \ triggerCycleCallback(this); \
} \ } \
startOfCycleNt = nowNt; \ startOfCycleNt = nowNt; \
resetCurrentCycleState(); \ resetCurrentCycleState(); \
intTotalEventCounter(); \ incrementTotalEventCounter(); \
runningRevolutionCounter++; \ runningRevolutionCounter++; \
totalEventCountBase += TRIGGER_SHAPE(size); \ totalEventCountBase += TRIGGER_SHAPE(size); \
} }
@ -645,7 +645,7 @@ uint32_t findTriggerZeroEventIndex(TriggerState *state, TriggerShape * shape,
* *
* todo: add a comment why are we doing '2 * shape->getSize()' here? * todo: add a comment why are we doing '2 * shape->getSize()' here?
*/ */
state->cycleCallback = onFindIndex; state->triggerCycleCallback = onFindIndex;
helper.assertSyncPositionAndSetDutyCycle(syncIndex, state, shape, triggerConfig PASS_ENGINE_PARAMETER_SUFFIX); helper.assertSyncPositionAndSetDutyCycle(syncIndex, state, shape, triggerConfig PASS_ENGINE_PARAMETER_SUFFIX);

View File

@ -41,23 +41,29 @@ typedef struct {
uint32_t totalTimeNt[PWM_PHASE_MAX_WAVE_PER_PWM]; uint32_t totalTimeNt[PWM_PHASE_MAX_WAVE_PER_PWM];
} current_cycle_state_s; } current_cycle_state_s;
/**
* @see TriggerShape for trigger wheel shape deginition
*/
class TriggerState { class TriggerState {
public: public:
TriggerState(); TriggerState();
/**
* current trigger processing index, between zero and #size
*/
int getCurrentIndex(); int getCurrentIndex();
int getTotalRevolutionCounter(); int getTotalRevolutionCounter();
/** /**
* this is important for crank-based virtual trigger and VVT magic * this is important for crank-based virtual trigger and VVT magic
*/ */
bool isEvenRevolution(); bool isEvenRevolution();
void intTotalEventCounter(); void incrementTotalEventCounter();
efitime_t getTotalEventCounter(); efitime_t getTotalEventCounter();
efitime_t getStartOfRevolutionIndex(); efitime_t getStartOfRevolutionIndex();
void decodeTriggerEvent(trigger_event_e const signal, efitime_t nowUs DECLARE_ENGINE_PARAMETER_SUFFIX); void decodeTriggerEvent(trigger_event_e const signal, efitime_t nowUs DECLARE_ENGINE_PARAMETER_SUFFIX);
bool isValidIndex(DECLARE_ENGINE_PARAMETER_SIGNATURE); bool isValidIndex(DECLARE_ENGINE_PARAMETER_SIGNATURE);
float getTriggerDutyCycle(int index); float getTriggerDutyCycle(int index);
TriggerStateCallback cycleCallback; TriggerStateCallback triggerCycleCallback;
/** /**
* TRUE if we know where we are * TRUE if we know where we are

View File

@ -96,7 +96,7 @@ void TriggerStimulatorHelper::assertSyncPositionAndSetDutyCycle(const uint32_t s
shape->shapeDefinitionError = false; shape->shapeDefinitionError = false;
for (int i = 0; i < PWM_PHASE_MAX_WAVE_PER_PWM; i++) { for (int i = 0; i < PWM_PHASE_MAX_WAVE_PER_PWM; i++) {
shape->dutyCycle[i] = 1.0 * state->expectedTotalTime[i] / SIMULATION_CYCLE_PERIOD; shape->expectedDutyCycle[i] = 1.0 * state->expectedTotalTime[i] / SIMULATION_CYCLE_PERIOD;
} }
} }

View File

@ -101,7 +101,7 @@ void TriggerShape::calculateTriggerSynchPoint(TriggerState *state DECLARE_ENGINE
void TriggerShape::initialize(operation_mode_e operationMode, bool needSecondTriggerInput) { void TriggerShape::initialize(operation_mode_e operationMode, bool needSecondTriggerInput) {
isSynchronizationNeeded = true; // that's default value isSynchronizationNeeded = true; // that's default value
this->needSecondTriggerInput = needSecondTriggerInput; this->needSecondTriggerInput = needSecondTriggerInput;
memset(dutyCycle, 0, sizeof(dutyCycle)); memset(expectedDutyCycle, 0, sizeof(expectedDutyCycle));
memset(eventAngles, 0, sizeof(eventAngles)); memset(eventAngles, 0, sizeof(eventAngles));
// memset(triggerIndexByAngle, 0, sizeof(triggerIndexByAngle)); // memset(triggerIndexByAngle, 0, sizeof(triggerIndexByAngle));
setTriggerSynchronizationGap(2); setTriggerSynchronizationGap(2);
@ -171,7 +171,7 @@ TriggerState::TriggerState() {
} }
void TriggerState::reset() { void TriggerState::reset() {
cycleCallback = NULL; triggerCycleCallback = NULL;
shaft_is_synchronized = false; shaft_is_synchronized = false;
toothed_previous_time = 0; toothed_previous_time = 0;
toothed_previous_duration = 0; toothed_previous_duration = 0;
@ -271,7 +271,7 @@ int TriggerState::getTotalRevolutionCounter() {
} }
void TriggerState::intTotalEventCounter() { void TriggerState::incrementTotalEventCounter() {
totalRevolutionCounter++; totalRevolutionCounter++;
} }
@ -419,7 +419,7 @@ void TriggerShape::addEvent2(angle_t angle, trigger_wheel_e const waveIndex, tri
int index = wave.waveIndertionAngle(angle, size); int index = wave.waveIndertionAngle(angle, size);
// shifting existing data // shifting existing data
// todo: does this logic actually work? I think it does not! // todo: does this logic actually work? I think it does not! due to broken state handling
for (int i = size - 1; i >= index; i--) { for (int i = size - 1; i >= index; i--) {
for (int j = 0; j < PWM_PHASE_MAX_WAVE_PER_PWM; j++) { for (int j = 0; j < PWM_PHASE_MAX_WAVE_PER_PWM; j++) {
wave.waves[j].pinStates[i + 1] = wave.getChannelState(j, index); wave.waves[j].pinStates[i + 1] = wave.getChannelState(j, index);

View File

@ -47,6 +47,7 @@ class TriggerState;
/** /**
* @brief Trigger shape has all the fields needed to describe and decode trigger signal. * @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
*/ */
class TriggerShape { class TriggerShape {
public: public:
@ -56,7 +57,14 @@ public:
event_trigger_position_s *position, angle_t angleOffset DECLARE_ENGINE_PARAMETER_SUFFIX); event_trigger_position_s *position, angle_t angleOffset DECLARE_ENGINE_PARAMETER_SUFFIX);
bool isSynchronizationNeeded; bool isSynchronizationNeeded;
/**
* this flag tells us if we should ignore events on second input channel
* that's the way to ignore noise from the disconnected wire
*/
bool needSecondTriggerInput; bool needSecondTriggerInput;
/**
* true value here means that we do not have a valid trigger configuration
*/
bool shapeDefinitionError; bool shapeDefinitionError;
/** /**
@ -68,7 +76,7 @@ public:
/** /**
* duty cycle for each individual trigger channel * duty cycle for each individual trigger channel
*/ */
float dutyCycle[PWM_PHASE_MAX_WAVE_PER_PWM]; float expectedDutyCycle[PWM_PHASE_MAX_WAVE_PER_PWM];
/** /**
* These angles are in event coordinates - with synchronization point located at angle zero. * These angles are in event coordinates - with synchronization point located at angle zero.
@ -94,7 +102,6 @@ public:
float thirdSyncRatioFrom; float thirdSyncRatioFrom;
float thirdSyncRatioTo; float thirdSyncRatioTo;
/** /**
* Trigger indexes within trigger cycle are counted from synchronization point, and all * Trigger indexes within trigger cycle are counted from synchronization point, and all
* engine processes are defined in angles from TDC. * engine processes are defined in angles from TDC.
@ -199,6 +206,7 @@ private:
/** /**
* This variable is used to confirm that events are added in the right order. * This variable is used to confirm that events are added in the right order.
* todo: this variable is pribably not needed, could be reimplemented by accessing by index
*/ */
angle_t previousAngle; angle_t previousAngle;
/** /**