From d94b6d74e703eb57e9b70ea0ad672da5440d6a9a Mon Sep 17 00:00:00 2001 From: rusefi Date: Sun, 7 Apr 2019 18:25:46 -0400 Subject: [PATCH] better ICU error handling --- firmware/controllers/sensors/map.cpp | 2 +- firmware/development/wave_analyzer.cpp | 4 ++-- firmware/hw_layer/digital_input_hw.cpp | 4 ++-- firmware/hw_layer/digital_input_hw.h | 2 +- firmware/hw_layer/io_pins.cpp | 11 +++++++---- firmware/hw_layer/io_pins.h | 2 +- firmware/hw_layer/trigger_input_icu.cpp | 2 +- firmware/hw_layer/vehicle_speed.cpp | 2 +- 8 files changed, 16 insertions(+), 13 deletions(-) diff --git a/firmware/controllers/sensors/map.cpp b/firmware/controllers/sensors/map.cpp index 5829a6f8f0..062b8ba93d 100644 --- a/firmware/controllers/sensors/map.cpp +++ b/firmware/controllers/sensors/map.cpp @@ -266,7 +266,7 @@ void initMapDecoder(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { #if HAL_USE_ICU || defined(__DOXYGEN__) if (engineConfiguration->hasFrequencyReportingMapSensor) { digital_input_s* digitalMapInput = addWaveAnalyzerDriver("map freq", CONFIGB(frequencyReportingMapInputPin)); - startInputDriver(digitalMapInput, true); + startInputDriver("MAP", digitalMapInput, true); digitalMapInput->widthListeners.registerCallback((VoidInt) digitalMapWidthCallback, NULL); } diff --git a/firmware/development/wave_analyzer.cpp b/firmware/development/wave_analyzer.cpp index c4550b95cd..9e5dbf100c 100644 --- a/firmware/development/wave_analyzer.cpp +++ b/firmware/development/wave_analyzer.cpp @@ -108,7 +108,7 @@ static void waIcuPeriodCallback(WaveReader *reader) { static void setWaveModeSilent(int index, int mode) { WaveReader *reader = &readers[index]; - startInputDriver(reader->hw, mode); + startInputDriver("wave", reader->hw, mode); } //static int getEventCounter(int index) { @@ -135,7 +135,7 @@ static void initWave(const char *name, int index) { } print("wave%d input on %s\r\n", index, hwPortname(brainPin)); - startInputDriver(reader->hw, mode); + startInputDriver("wave", reader->hw, mode); } #endif diff --git a/firmware/hw_layer/digital_input_hw.cpp b/firmware/hw_layer/digital_input_hw.cpp index eebadb13ed..dc31b3255b 100644 --- a/firmware/hw_layer/digital_input_hw.cpp +++ b/firmware/hw_layer/digital_input_hw.cpp @@ -253,7 +253,7 @@ void removeWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin) { } } -void startInputDriver(/*nullable*/digital_input_s *hw, bool isActiveHigh) { +void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw, bool isActiveHigh) { 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"); @@ -275,7 +275,7 @@ void startInputDriver(/*nullable*/digital_input_s *hw, bool isActiveHigh) { icuStop(driver); } wave_icucfg.channel = getInputCaptureChannel(hw->brainPin); - efiIcuStart(driver, &wave_icucfg); + efiIcuStart(msg, driver, &wave_icucfg); efiAssertVoid(CUSTOM_ERR_6672, driver != NULL, "di: driver is NULL"); efiAssertVoid(CUSTOM_ERR_6673, driver->state == ICU_READY, "di: driver not ready"); icuStartCapture(driver); // this would change state from READY to WAITING diff --git a/firmware/hw_layer/digital_input_hw.h b/firmware/hw_layer/digital_input_hw.h index 384d77a71c..9ed26e1088 100644 --- a/firmware/hw_layer/digital_input_hw.h +++ b/firmware/hw_layer/digital_input_hw.h @@ -26,7 +26,7 @@ typedef struct { void turnOnCapturePin(const char *msg, brain_pin_e brainPin); digital_input_s *addWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin); -void startInputDriver(/*nullable*/digital_input_s *hw, bool isActiveHigh); +void startInputDriver(const char *msg, /*nullable*/digital_input_s *hw, bool isActiveHigh); void removeWaveAnalyzerDriver(const char *msg, brain_pin_e brainPin); //Nullable diff --git a/firmware/hw_layer/io_pins.cpp b/firmware/hw_layer/io_pins.cpp index 7dca27b1b1..015ec3a4ca 100644 --- a/firmware/hw_layer/io_pins.cpp +++ b/firmware/hw_layer/io_pins.cpp @@ -78,10 +78,13 @@ iomode_t getInputMode(pin_input_mode_e mode) { } #if HAL_USE_ICU || defined(__DOXYGEN__) -void efiIcuStart(ICUDriver *icup, const ICUConfig *config) { - efiAssertVoid(CUSTOM_ERR_6679, (icup->state == ICU_STOP) || (icup->state == ICU_READY), - "input already used?"); - +void efiIcuStart(const char *msg, ICUDriver *icup, const ICUConfig *config) { + if (icup->state != ICU_STOP && icup->state != ICU_READY) { + static char icuError[30]; + sprintf(icuError, "ICU already used %s", msg); + firmwareError(CUSTOM_ERR_6679, icuError); + return; + } icuStart(icup, config); } #endif /* HAL_USE_ICU */ diff --git a/firmware/hw_layer/io_pins.h b/firmware/hw_layer/io_pins.h index 9bf12ba099..d605297c89 100644 --- a/firmware/hw_layer/io_pins.h +++ b/firmware/hw_layer/io_pins.h @@ -58,7 +58,7 @@ bool efiReadPin(brain_pin_e pin); iomode_t getInputMode(pin_input_mode_e mode); #if HAL_USE_ICU || defined(__DOXYGEN__) -void efiIcuStart(ICUDriver *icup, const ICUConfig *config); +void efiIcuStart(const char *msg, ICUDriver *icup, const ICUConfig *config); #endif /* HAL_USE_ICU */ #endif /* EFI_GPIO_HARDWARE */ diff --git a/firmware/hw_layer/trigger_input_icu.cpp b/firmware/hw_layer/trigger_input_icu.cpp index f16cfe533f..e12e89b641 100644 --- a/firmware/hw_layer/trigger_input_icu.cpp +++ b/firmware/hw_layer/trigger_input_icu.cpp @@ -125,7 +125,7 @@ static ICUDriver *turnOnTriggerInputPin(const char *msg, brain_pin_e hwPin, ICUC // bool needPeriodCallback = !CONFIG(useOnlyRisingEdgeForTrigger) || !TRIGGER_SHAPE(useRiseEdge); // shaft_icucfg.period_cb = needPeriodCallback ? shaft_icu_period_callback : NULL; - efiIcuStart(driver, icucfg); + efiIcuStart(msg, driver, icucfg); if (driver->state == ICU_READY) { efiAssert(CUSTOM_ERR_ASSERT, driver != NULL, "ti: driver is NULL", NULL); efiAssert(CUSTOM_ERR_ASSERT, driver->state == ICU_READY, "ti: driver not ready", NULL); diff --git a/firmware/hw_layer/vehicle_speed.cpp b/firmware/hw_layer/vehicle_speed.cpp index 48acafcc52..f108195bdd 100644 --- a/firmware/hw_layer/vehicle_speed.cpp +++ b/firmware/hw_layer/vehicle_speed.cpp @@ -74,7 +74,7 @@ void startVSSPins(void) { if (!hasVehicleSpeedSensor()) return; digital_input_s* vehicleSpeedInput = addWaveAnalyzerDriver("VSS", CONFIGB(vehicleSpeedSensorInputPin)); - startInputDriver(vehicleSpeedInput, true); + startInputDriver("VSS", vehicleSpeedInput, true); vehicleSpeedInput->widthListeners.registerCallback((VoidInt) vsAnaWidthCallback, NULL); }