From cc55c143f5c6134c606d072f6ce3c65ab23d7cd0 Mon Sep 17 00:00:00 2001 From: rusefi Date: Wed, 26 Apr 2017 11:57:02 -0400 Subject: [PATCH] icuStartCapture panic better state validation --- firmware/config/stm32f4ems/chconf.h | 10 ++++++++++ firmware/hw_layer/digital_input_hw.cpp | 2 ++ firmware/hw_layer/trigger_input.cpp | 2 ++ firmware/rusefi.cpp | 2 +- 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/firmware/config/stm32f4ems/chconf.h b/firmware/config/stm32f4ems/chconf.h index 830248fa0f..70ac579a9b 100644 --- a/firmware/config/stm32f4ems/chconf.h +++ b/firmware/config/stm32f4ems/chconf.h @@ -547,6 +547,16 @@ void chDbgPanic3(const char *msg, const char * file, int line); #define hasFatalError() (FALSE) #endif + +#define chDbgAssert(c, remark) do { \ + if (CH_DBG_ENABLE_ASSERTS != FALSE) { \ + if (!(c)) { \ + /*lint -restore*/ \ + chSysHalt(remark); \ + } \ + } \ +} while (false) + #endif /* _CHCONF_H_ */ /** @} */ diff --git a/firmware/hw_layer/digital_input_hw.cpp b/firmware/hw_layer/digital_input_hw.cpp index 3406d8e909..bd0b2ed4f2 100644 --- a/firmware/hw_layer/digital_input_hw.cpp +++ b/firmware/hw_layer/digital_input_hw.cpp @@ -211,6 +211,8 @@ void startInputDriver(digital_input_s *hw, bool isActiveHigh) { } wave_icucfg.channel = getInputCaptureChannel(hw->brainPin); efiIcuStart(driver, &wave_icucfg); + efiAssertVoid(driver != NULL, "di: driver is NULL"); + efiAssertVoid(driver->state == ICU_READY, "di: driver not ready"); icuStartCapture(driver); // this would change state from READY to WAITING icuEnableNotifications(driver); } diff --git a/firmware/hw_layer/trigger_input.cpp b/firmware/hw_layer/trigger_input.cpp index 04e8835ae2..34c7a3c0b5 100644 --- a/firmware/hw_layer/trigger_input.cpp +++ b/firmware/hw_layer/trigger_input.cpp @@ -123,6 +123,8 @@ static ICUDriver *turnOnTriggerInputPin(const char *msg, brain_pin_e hwPin, ICUC efiIcuStart(driver, icucfg); if (driver->state == ICU_READY) { + efiAssertVoid(driver != NULL, "ti: driver is NULL"); + efiAssertVoid(driver->state == ICU_READY, "ti: driver not ready"); icuStartCapture(driver); // this would change state from READY to WAITING icuEnableNotifications(driver); } else { diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 763da20926..6a79593967 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -251,5 +251,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20170424; + return 20170426; }