VVT support for VAG trigger #883

This commit is contained in:
rusefi 2020-08-24 02:01:50 -04:00
parent 2d696cbc31
commit bdbee0d38b
10 changed files with 51 additions and 56 deletions

View File

@ -338,6 +338,10 @@ static void initStatusLeds(void) {
enginePins.runningLedPin.initPin("led: running status", engineConfiguration->runningLedPin);
enginePins.debugTriggerSync.initPin("debug: sync", CONFIG(debugTriggerSync));
#if EFI_GPIO_HARDWARE && EFI_SHAFT_POSITION_INPUT
enginePins.triggerDecoderErrorPin.initPin("led: trigger debug", CONFIG(triggerErrorPin),
&CONFIG(triggerErrorPinMode));
#endif /* EFI_GPIO_HARDWARE */
}
#if EFI_PROD_CODE

View File

@ -60,10 +60,11 @@ public:
class PrimaryTriggerConfiguration : public TriggerConfiguration {
public:
PrimaryTriggerConfiguration(Engine *engine);
bool isUseOnlyRisingEdgeForTrigger();
bool isSilentTriggerError();
bool isVerboseTriggerSynchDetails();
debug_mode_e getDebugMode();
bool isUseOnlyRisingEdgeForTrigger() const;
bool isSilentTriggerError() const;
bool isVerboseTriggerSynchDetails() const;
debug_mode_e getDebugMode() const;
trigger_type_e getType() const;
private:
Engine *engine;
};

View File

@ -285,19 +285,23 @@ PrimaryTriggerConfiguration::PrimaryTriggerConfiguration(Engine *engine) {
this->engine = engine;
}
bool PrimaryTriggerConfiguration::isUseOnlyRisingEdgeForTrigger() {
bool PrimaryTriggerConfiguration::isUseOnlyRisingEdgeForTrigger() const {
return engine->engineConfigurationPtr->useOnlyRisingEdgeForTrigger;
}
debug_mode_e PrimaryTriggerConfiguration::getDebugMode() {
debug_mode_e PrimaryTriggerConfiguration::getDebugMode() const {
return engine->engineConfigurationPtr->debugMode;
}
bool PrimaryTriggerConfiguration::isSilentTriggerError() {
trigger_type_e PrimaryTriggerConfiguration::getType() const {
return engine->engineConfigurationPtr->trigger.type;
}
bool PrimaryTriggerConfiguration::isSilentTriggerError() const {
return engine->engineConfigurationPtr->silentTriggerError;
}
bool PrimaryTriggerConfiguration::isVerboseTriggerSynchDetails() {
bool PrimaryTriggerConfiguration::isVerboseTriggerSynchDetails() const {
return engine->engineConfigurationPtr->verboseTriggerSynchDetails;
}

View File

@ -455,7 +455,7 @@ void TriggerCentral::handleShaftSignal(trigger_event_e signal, efitick_t timesta
nullptr,
engine,
&engine->primaryTriggerConfiguration,
signal, timestamp PASS_CONFIG_PARAMETER_SUFFIX);
signal, timestamp);
/**
* If we only have a crank position sensor with four stroke, here we are extending crank revolutions with a 360 degree
@ -792,8 +792,15 @@ void initTriggerCentral(Logging *sharedLogger) {
addConsoleAction(CMD_TRIGGERINFO, triggerInfo);
addConsoleAction("trigger_shape_info", triggerShapeInfo);
addConsoleAction("reset_trigger", resetRunningTriggerCounters);
#endif
#endif // EFI_PROD_CODE || EFI_SIMULATOR
}
#endif
/**
* @return TRUE is something is wrong with trigger decoding
*/
bool isTriggerDecoderError(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engine->triggerErrorDetection.sum(6) > 4;
}
#endif // EFI_SHAFT_POSITION_INPUT

View File

@ -12,8 +12,6 @@
#include "trigger_decoder.h"
#include "trigger_central_generated.h"
class Engine;
typedef void (*ShaftPositionListener)(trigger_event_e signal, uint32_t index, efitick_t edgeTimestamp DECLARE_ENGINE_PARAMETER_SUFFIX);
@ -87,4 +85,6 @@ void onConfigurationChangeTriggerCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool checkIfTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool isTriggerConfigChanged(DECLARE_ENGINE_PARAMETER_SIGNATURE);
bool isTriggerDecoderError(DECLARE_ENGINE_PARAMETER_SIGNATURE);
#define SYMMETRICAL_CRANK_SENSOR_DIVIDER 4

View File

@ -114,13 +114,6 @@ float actualSynchGap;
static Logging * logger = nullptr;
/**
* @return TRUE is something is wrong with trigger decoding
*/
bool isTriggerDecoderError(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engine->triggerErrorDetection.sum(6) > 4;
}
void calculateTriggerSynchPoint(TriggerWaveform *shape, TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX) {
#if EFI_PROD_CODE
efiAssertVoid(CUSTOM_TRIGGER_STACK, getCurrentRemainingStack() > EXPECTED_REMAINING_STACK, "calc s");
@ -302,7 +295,7 @@ static trigger_value_e eventType[6] = { TV_FALL, TV_RISE, TV_FALL, TV_RISE, TV_F
/* odd event - start accumulation */ \
currentCycle.timeOfPreviousEventNt[triggerWheel] = nowNt; \
} \
if (engineConfiguration->useOnlyRisingEdgeForTrigger) {currentCycle.current_index++;} \
if (triggerConfiguration->isUseOnlyRisingEdgeForTrigger()) {currentCycle.current_index++;} \
currentCycle.current_index++; \
PRINT_INC_INDEX; \
}
@ -389,7 +382,7 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape,
TriggerStateListener * triggerStateListener,
const TriggerConfiguration * triggerConfiguration,
const trigger_event_e signal,
const efitick_t nowNt DECLARE_CONFIG_PARAMETER_SUFFIX) {
const efitick_t nowNt) {
ScopePerf perf(PE::DecodeTriggerEvent);
if (nowNt - previousShaftEventTimeNt > NT_PER_SECOND) {
@ -439,7 +432,7 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape,
#if EFI_UNIT_TEST
if (printTriggerTrace) {
printf("%s isLessImportant %s now=%d index=%d\r\n",
getTrigger_type_e(engineConfiguration->trigger.type),
getTrigger_type_e(triggerConfiguration->getType()),
getTrigger_event_e(signal),
(int)nowNt,
currentCycle.current_index);
@ -456,7 +449,7 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape,
#if EFI_UNIT_TEST
if (printTriggerTrace) {
printf("%s event %s %d\r\n",
getTrigger_type_e(engineConfiguration->trigger.type),
getTrigger_type_e(triggerConfiguration->getType()),
getTrigger_event_e(signal),
nowNt);
}
@ -618,7 +611,7 @@ void TriggerState::decodeTriggerEvent(TriggerWaveform *triggerShape,
#if EFI_UNIT_TEST
if (printTriggerTrace) {
printf("decodeTriggerEvent %s isSynchronizationPoint=%d index=%d %s\r\n",
getTrigger_type_e(engineConfiguration->trigger.type),
getTrigger_type_e(triggerConfiguration->getType()),
isSynchronizationPoint, currentCycle.current_index,
getTrigger_event_e(signal));
}
@ -727,11 +720,4 @@ void initTriggerDecoderLogger(Logging *sharedLogger) {
logger = sharedLogger;
}
void initTriggerDecoder(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
#if EFI_GPIO_HARDWARE
enginePins.triggerDecoderErrorPin.initPin("led: trigger debug", CONFIG(triggerErrorPin),
&CONFIG(triggerErrorPinMode));
#endif /* EFI_GPIO_HARDWARE */
}
#endif /* EFI_SHAFT_POSITION_INPUT */

View File

@ -25,10 +25,11 @@ struct TriggerStateListener {
class TriggerConfiguration {
public:
virtual bool isUseOnlyRisingEdgeForTrigger() = 0;
virtual bool isSilentTriggerError() = 0;
virtual bool isVerboseTriggerSynchDetails() = 0;
virtual debug_mode_e getDebugMode() = 0;
virtual bool isUseOnlyRisingEdgeForTrigger() const = 0;
virtual bool isSilentTriggerError() const = 0;
virtual bool isVerboseTriggerSynchDetails() const = 0;
virtual debug_mode_e getDebugMode() const = 0;
virtual trigger_type_e getType() const = 0;
};
typedef void (*TriggerStateCallback)(TriggerState *);
@ -81,13 +82,12 @@ public:
TriggerStateListener * triggerStateListener,
const TriggerConfiguration * triggerConfiguration,
const trigger_event_e signal,
const efitime_t nowUs DECLARE_CONFIG_PARAMETER_SUFFIX);
const efitime_t nowUs);
bool validateEventCounters(TriggerWaveform *triggerShape) const;
void onShaftSynchronization(const TriggerStateCallback triggerCycleCallback,
efitick_t nowNt, TriggerWaveform *triggerShape);
bool isValidIndex(TriggerWaveform *triggerShape) const;
float getTriggerDutyCycle(int index);
@ -188,10 +188,7 @@ angle_t getEngineCycle(operation_mode_e operationMode);
class Engine;
void initTriggerDecoder(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void initTriggerDecoderLogger(Logging *sharedLogger);
bool isTriggerDecoderError(DECLARE_ENGINE_PARAMETER_SIGNATURE);
void calculateTriggerSynchPoint(TriggerWaveform *shape, TriggerState *state DECLARE_ENGINE_PARAMETER_SUFFIX);

View File

@ -72,7 +72,7 @@ void TriggerStimulatorHelper::feedSimulatedEvent(const TriggerStateCallback trig
triggerCycleCallback,
/* override */ nullptr,
triggerConfiguration,
s, time PASS_CONFIG_PARAMETER_SUFFIX);
s, time);
}
}
@ -84,7 +84,7 @@ void TriggerStimulatorHelper::feedSimulatedEvent(const TriggerStateCallback trig
triggerCycleCallback,
/* override */ nullptr,
triggerConfiguration,
s, time PASS_CONFIG_PARAMETER_SUFFIX);
s, time);
}
}
@ -96,7 +96,7 @@ void TriggerStimulatorHelper::feedSimulatedEvent(const TriggerStateCallback trig
triggerCycleCallback,
/* override */ nullptr,
triggerConfiguration,
s, time PASS_CONFIG_PARAMETER_SUFFIX);
s, time);
}
}
}

View File

@ -477,10 +477,6 @@ void initHardware(Logging *l) {
return;
}
#if EFI_SHAFT_POSITION_INPUT
initTriggerDecoder(PASS_ENGINE_PARAMETER_SIGNATURE);
#endif
#if HAL_USE_ADC
initAdcInputs();
// wait for first set of ADC values so that we do not produce invalid sensor data

View File

@ -126,28 +126,28 @@ TEST(misc, testSomethingWeird) {
ASSERT_FALSE(sta->shaft_is_synchronized) << "shaft_is_synchronized";
int r = 10;
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r PASS_CONFIG_PARAMETER_SUFFIX);
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r);
ASSERT_FALSE(sta->shaft_is_synchronized) << "shaft_is_synchronized"; // still no synchronization
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, ++r PASS_CONFIG_PARAMETER_SUFFIX);
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, ++r);
ASSERT_TRUE(sta->shaft_is_synchronized); // first signal rise synchronize
ASSERT_EQ(0, sta->getCurrentIndex());
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r++ PASS_CONFIG_PARAMETER_SUFFIX);
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r++);
ASSERT_EQ(1, sta->getCurrentIndex());
for (int i = 2; i < 10;) {
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, r++ PASS_CONFIG_PARAMETER_SUFFIX);
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, r++);
assertEqualsM("even", i++, sta->getCurrentIndex());
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r++ PASS_CONFIG_PARAMETER_SUFFIX);
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r++);
assertEqualsM("odd", i++, sta->getCurrentIndex());
}
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, r++ PASS_CONFIG_PARAMETER_SUFFIX);
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, r++);
ASSERT_EQ(10, sta->getCurrentIndex());
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r++ PASS_CONFIG_PARAMETER_SUFFIX);
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_FALLING, r++);
ASSERT_EQ(11, sta->getCurrentIndex());
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, r++ PASS_CONFIG_PARAMETER_SUFFIX);
sta->decodeTriggerEvent(&ENGINE(triggerCentral.triggerShape), nullptr, /* override */ nullptr, triggerConfiguration, SHAFT_PRIMARY_RISING, r++);
ASSERT_EQ(0, sta->getCurrentIndex()); // new revolution
}