parent
212d80929d
commit
9f26e6d894
|
@ -75,8 +75,8 @@ extern bool main_loop_started;
|
|||
#include "vehicle_speed.h"
|
||||
#include "single_timer_executor.h"
|
||||
#include "periodic_task.h"
|
||||
extern int icuWidthCallbackCounter;
|
||||
extern int icuWidthPeriodCounter;
|
||||
extern int icuRisingCallbackCounter;
|
||||
extern int icuFallingCallbackCounter;
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
#if EFI_CJ125
|
||||
|
@ -954,7 +954,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_
|
|||
#if EFI_PROD_CODE && HAL_USE_ICU == TRUE
|
||||
tsOutputChannels->debugIntField4 = engine->triggerCentral.vvtEventRiseCounter;
|
||||
tsOutputChannels->debugIntField5 = engine->triggerCentral.vvtEventFallCounter;
|
||||
tsOutputChannels->debugFloatField5 = icuWidthCallbackCounter + icuWidthPeriodCounter;
|
||||
tsOutputChannels->debugFloatField5 = icuRisingCallbackCounter + icuFallingCallbackCounter;
|
||||
#endif /* EFI_PROD_CODE */
|
||||
|
||||
tsOutputChannels->debugFloatField1 = engine->triggerCentral.getHwEventCounter((int)SHAFT_PRIMARY_RISING);
|
||||
|
|
|
@ -270,7 +270,7 @@ void initMapDecoder(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|||
|
||||
if (engineConfiguration->hasFrequencyReportingMapSensor) {
|
||||
#if HAL_USE_ICU
|
||||
digital_input_s* digitalMapInput = startDigitalCapture("MAP freq", CONFIG(frequencyReportingMapInputPin), true);
|
||||
digital_input_s* digitalMapInput = startDigitalCapture("MAP freq", CONFIG(frequencyReportingMapInputPin));
|
||||
|
||||
digitalMapInput->setWidthCallback((VoidInt) digitalMapWidthCallback, NULL);
|
||||
#else
|
||||
|
|
|
@ -509,8 +509,8 @@ void resetMaxValues() {
|
|||
}
|
||||
|
||||
#if HAL_USE_ICU == TRUE
|
||||
extern int icuWidthCallbackCounter;
|
||||
extern int icuWidthPeriodCounter;
|
||||
extern int icuRisingCallbackCounter;
|
||||
extern int icuFallingCallbackCounter;
|
||||
#endif /* HAL_USE_ICU */
|
||||
|
||||
void triggerInfo(void) {
|
||||
|
@ -524,7 +524,7 @@ void triggerInfo(void) {
|
|||
#else
|
||||
|
||||
#if HAL_USE_ICU == TRUE
|
||||
scheduleMsg(logger, "trigger ICU hw: %d %d %d", icuWidthCallbackCounter, icuWidthPeriodCounter, engine->hwTriggerInputEnabled);
|
||||
scheduleMsg(logger, "trigger ICU hw: %d %d %d", icuRisingCallbackCounter, icuFallingCallbackCounter, engine->hwTriggerInputEnabled);
|
||||
#endif /* HAL_USE_ICU */
|
||||
|
||||
#endif /* HAL_TRIGGER_USE_PAL */
|
||||
|
|
|
@ -110,14 +110,12 @@ static void initWave(const char *name, int index) {
|
|||
if (brainPin == GPIO_UNASSIGNED)
|
||||
return;
|
||||
|
||||
bool mode = CONFIG(logicAnalyzerMode)[index];
|
||||
|
||||
waveReaderCount++;
|
||||
efiAssertVoid(CUSTOM_ERR_6655, index < MAX_ICU_COUNT, "too many ICUs");
|
||||
WaveReader *reader = &readers[index];
|
||||
reader->name = name;
|
||||
|
||||
reader->hw = startDigitalCapture("wave input", brainPin, mode);
|
||||
reader->hw = startDigitalCapture("wave input", brainPin);
|
||||
|
||||
if (reader->hw != NULL) {
|
||||
reader->hw->setWidthCallback((VoidInt)(void*) waAnaWidthCallback, (void*) reader);
|
||||
|
|
|
@ -216,26 +216,6 @@ void turnOffCapturePin(brain_pin_e brainPin) {
|
|||
efiSetPadUnused(brainPin);
|
||||
}
|
||||
|
||||
/**
|
||||
* takes next digital_input_s from the registeredIcus pool
|
||||
*/
|
||||
digital_input_s * addWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin) {
|
||||
ICUDriver *driver = getInputCaptureDriver(msg, brainPin);
|
||||
if (driver == NULL) {
|
||||
warning(CUSTOM_ERR_INVALID_INPUT_ICU_PIN, "w_not input pin");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
digital_input_s *hw = registeredIcus.add();
|
||||
hw->widthListeners.clear();
|
||||
hw->periodListeners.clear();
|
||||
hw->started = false;
|
||||
hw->brainPin = brainPin;
|
||||
hw->driver = driver;
|
||||
turnOnCapturePin(msg, brainPin);
|
||||
return hw;
|
||||
}
|
||||
|
||||
/**
|
||||
* turns pin off and returns digital_input_s back into registeredIcus pool
|
||||
*/
|
||||
|
@ -264,22 +244,16 @@ void stopDigitalCapture(const char *msg, brain_pin_e brainPin) {
|
|||
}
|
||||
}
|
||||
|
||||
void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw, bool isActiveHigh) {
|
||||
static void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw) {
|
||||
if (hw == NULL) {
|
||||
// we can get NULL driver if user somehow has invalid pin in his configuration
|
||||
warning(CUSTOM_ERR_INVALID_INPUT_ICU_PIN, "s_not input pin");
|
||||
return;
|
||||
}
|
||||
|
||||
hw->isActiveHigh = isActiveHigh;
|
||||
if (hw->isActiveHigh) {
|
||||
wave_icucfg.mode = ICU_INPUT_ACTIVE_HIGH;
|
||||
} else {
|
||||
wave_icucfg.mode = ICU_INPUT_ACTIVE_LOW;
|
||||
}
|
||||
ICUDriver *driver = hw->driver;
|
||||
|
||||
if (driver != NULL) {
|
||||
if (driver) {
|
||||
if (hw->started) {
|
||||
icuDisableNotificationsI(driver);
|
||||
icuStopCapture(driver);
|
||||
|
@ -295,10 +269,23 @@ void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw, bool isA
|
|||
hw->started = true;
|
||||
}
|
||||
|
||||
digital_input_s* startDigitalCapture(const char *msg, brain_pin_e brainPin, bool isActiveHigh) {
|
||||
digital_input_s* input = addWaveAnalyzerDriver(msg, brainPin);
|
||||
startInputDriver(msg, input, isActiveHigh);
|
||||
return input;
|
||||
digital_input_s* startDigitalCapture(const char *msg, brain_pin_e brainPin) {
|
||||
ICUDriver *driver = getInputCaptureDriver(msg, brainPin);
|
||||
if (!driver) {
|
||||
warning(CUSTOM_ERR_INVALID_INPUT_ICU_PIN, "w_not input pin");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
digital_input_s *hw = registeredIcus.add();
|
||||
hw->widthListeners.clear();
|
||||
hw->periodListeners.clear();
|
||||
hw->started = false;
|
||||
hw->brainPin = brainPin;
|
||||
hw->driver = driver;
|
||||
turnOnCapturePin(msg, brainPin);
|
||||
|
||||
startInputDriver(msg, hw);
|
||||
return hw;
|
||||
}
|
||||
|
||||
#endif /* EFI_ICU_INPUTS */
|
||||
|
|
|
@ -11,15 +11,11 @@
|
|||
|
||||
#if HAL_USE_ICU
|
||||
|
||||
digital_input_s* startDigitalCapture(const char *msg, brain_pin_e brainPin, bool isActiveHigh);
|
||||
digital_input_s* startDigitalCapture(const char *msg, brain_pin_e brainPin);
|
||||
|
||||
void turnOnCapturePin(const char *msg, brain_pin_e brainPin);
|
||||
void turnOffCapturePin(brain_pin_e brainPin);
|
||||
|
||||
// deprecated API
|
||||
digital_input_s *addWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin);
|
||||
void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw, bool isActiveHigh);
|
||||
|
||||
void stopDigitalCapture(const char *msg, brain_pin_e brainPin);
|
||||
|
||||
//Nullable
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
|
||||
#include "global.h"
|
||||
|
||||
volatile int icuWidthCallbackCounter = 0;
|
||||
volatile int icuWidthPeriodCounter = 0;
|
||||
int icuRisingCallbackCounter = 0;
|
||||
int icuFallingCallbackCounter = 0;
|
||||
|
||||
#if EFI_SHAFT_POSITION_INPUT && (HAL_USE_ICU == TRUE)
|
||||
|
||||
|
@ -28,27 +28,25 @@ extern bool hasFirmwareErrorFlag;
|
|||
|
||||
static Logging *logger;
|
||||
|
||||
static void vvtWidthCallback(void *) {
|
||||
static void vvtRisingCallback(void *) {
|
||||
hwHandleVvtCamSignal(TV_RISE, getTimeNowNt());
|
||||
}
|
||||
|
||||
static void vvtPeriodCallback(void *) {
|
||||
static void vvtFallingCallback(void *) {
|
||||
hwHandleVvtCamSignal(TV_FALL, getTimeNowNt());
|
||||
}
|
||||
|
||||
/**
|
||||
* that's hardware timer input capture IRQ entry point
|
||||
* 'width' events happens before the 'period' event
|
||||
*/
|
||||
static void shaftWidthCallback(bool isPrimary) {
|
||||
static void shaftRisingCallback(bool isPrimary) {
|
||||
efitick_t stamp = getTimeNowNt();
|
||||
|
||||
if (!engine->hwTriggerInputEnabled) {
|
||||
return;
|
||||
}
|
||||
icuWidthCallbackCounter++;
|
||||
icuRisingCallbackCounter++;
|
||||
// todo: support for 3rd trigger input channel
|
||||
// todo: start using real event time from HW event, not just software timer?
|
||||
if (hasFirmwareErrorFlag)
|
||||
return;
|
||||
if (!isPrimary && !TRIGGER_WAVEFORM(needSecondTriggerInput)) {
|
||||
|
@ -61,13 +59,15 @@ static void shaftWidthCallback(bool isPrimary) {
|
|||
hwHandleShaftSignal(signal, stamp);
|
||||
}
|
||||
|
||||
static void shaftPeriodCallback(bool isPrimary) {
|
||||
static void shaftFallingCallback(bool isPrimary) {
|
||||
efitick_t stamp = getTimeNowNt();
|
||||
|
||||
if (!engine->hwTriggerInputEnabled) {
|
||||
return;
|
||||
}
|
||||
icuWidthPeriodCounter++;
|
||||
|
||||
icuFallingCallbackCounter++;
|
||||
|
||||
if (hasFirmwareErrorFlag)
|
||||
return;
|
||||
if (!isPrimary && !TRIGGER_WAVEFORM(needSecondTriggerInput)) {
|
||||
|
@ -75,7 +75,6 @@ static void shaftPeriodCallback(bool isPrimary) {
|
|||
}
|
||||
|
||||
// todo: add support for 3rd channel
|
||||
// icucnt_t last_period = icuGetPeriod(icup); so far we are fine with system time
|
||||
trigger_event_e signal =
|
||||
isPrimary ? (engineConfiguration->invertPrimaryTriggerSignal ? SHAFT_PRIMARY_RISING : SHAFT_PRIMARY_FALLING) : (engineConfiguration->invertSecondaryTriggerSignal ? SHAFT_SECONDARY_RISING : SHAFT_SECONDARY_FALLING);
|
||||
hwHandleShaftSignal(signal, stamp);
|
||||
|
@ -92,7 +91,7 @@ int icuTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
|
|||
return -1;
|
||||
}
|
||||
|
||||
digital_input_s* input = startDigitalCapture("trigger", brainPin, true);
|
||||
digital_input_s* input = startDigitalCapture("trigger", brainPin);
|
||||
if (input == NULL) {
|
||||
/* error already reported */
|
||||
return -1;
|
||||
|
@ -100,11 +99,11 @@ int icuTriggerTurnOnInputPin(const char *msg, int index, bool isTriggerShaft) {
|
|||
|
||||
if (isTriggerShaft) {
|
||||
void * arg = (void*) (index == 0);
|
||||
input->setWidthCallback((VoidInt)(void*)shaftWidthCallback, arg);
|
||||
input->setPeriodCallback((VoidInt)(void*)shaftPeriodCallback, arg);
|
||||
input->setWidthCallback((VoidInt)(void*)shaftRisingCallback, arg);
|
||||
input->setPeriodCallback((VoidInt)(void*)shaftFallingCallback, arg);
|
||||
} else {
|
||||
input->setWidthCallback((VoidInt)(void*)vvtWidthCallback, NULL);
|
||||
input->setPeriodCallback((VoidInt)(void*)vvtPeriodCallback, NULL);
|
||||
input->setWidthCallback((VoidInt)(void*)vvtRisingCallback, NULL);
|
||||
input->setPeriodCallback((VoidInt)(void*)vvtFallingCallback, NULL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -73,8 +73,9 @@ void stopVSSPins(void) {
|
|||
void startVSSPins(void) {
|
||||
if (!hasVehicleSpeedSensor())
|
||||
return;
|
||||
digital_input_s* vehicleSpeedInput = addWaveAnalyzerDriver("VSS", CONFIG(vehicleSpeedSensorInputPin));
|
||||
startInputDriver("VSS", vehicleSpeedInput, true);
|
||||
|
||||
digital_input_s* vehicleSpeedInput = startDigitalCapture("VSS", CONFIG(vehicleSpeedSensorInputPin));
|
||||
|
||||
vehicleSpeedInput->widthListeners.registerCallback((VoidInt) vsAnaWidthCallback, NULL);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue