diff --git a/firmware/controllers/PwmTester.cpp b/firmware/controllers/PwmTester.cpp index 2d0498a4b9..91f4e8de6f 100644 --- a/firmware/controllers/PwmTester.cpp +++ b/firmware/controllers/PwmTester.cpp @@ -21,7 +21,7 @@ static LoggingWithStorage logger; static SimplePwm pwmTest[5]; extern OutputPin warningPin; -extern engine_pins_s enginePins; +extern EnginePins enginePins; EXTERN_ENGINE; diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 58c89aa400..c00759fb89 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -230,26 +230,6 @@ void Engine::init(persistent_config_s *config) { memset(config, 0, sizeof(persistent_config_s)); } -static bool stopPin(NamedOutputPin *output) { -#if EFI_PROD_CODE || defined(__DOXYGEN__) - if (output->isInitialized() && output->getLogicValue()) { - output->setValue(false); - scheduleMsg(&logger, "turning off %s", output->name); - return true; - } -#endif - return false; -} - -bool Engine::stopPins() { - bool result = false; - for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { - result |= stopPin(&enginePins.coils[i]); - result |= stopPin(&enginePins.injectors[i]); - } - return result; -} - void Engine::printKnockState(void) { scheduleMsg(&logger, "knock now=%s/ever=%s", boolToString(knockNow), boolToString(knockEver)); } @@ -287,7 +267,7 @@ void Engine::watchdog() { if (isRunningPwmTest) return; if (!isSpinning) { - if (!isRunningBenchTest() && stopPins()) { + if (!isRunningBenchTest() && enginePins.stopPins()) { firmwareError(CUSTOM_ERR_2ND_WATCHDOG, "Some pins were turned off by 2nd pass watchdog"); } return; @@ -318,7 +298,7 @@ void Engine::watchdog() { triggerInfo(); #endif - stopPins(); + enginePins.stopPins(); #endif } diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 3b95f89d70..9d20ad1818 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -424,7 +424,6 @@ private: * 'spinning' means the engine is not stopped */ bool isSpinning; - bool stopPins(); }; /** diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index d93f9c1f3d..0dc6687323 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -44,7 +44,7 @@ static LENameOrdinalPair leKnock(LE_METHOD_KNOCK, "knock"); #define LE_EVAL_POOL_SIZE 32 -extern engine_pins_s enginePins; +extern EnginePins enginePins; static LECalculator evalCalc; static LEElement evalPoolElements[LE_EVAL_POOL_SIZE]; diff --git a/firmware/controllers/malfunction_indicator.cpp b/firmware/controllers/malfunction_indicator.cpp index 6a149e81dc..77b97bed62 100644 --- a/firmware/controllers/malfunction_indicator.cpp +++ b/firmware/controllers/malfunction_indicator.cpp @@ -38,7 +38,7 @@ #define MFI_BLINK_SEPARATOR 400 #define MFI_CHECKENGINE_LIGHT 10000 -extern engine_pins_s enginePins; +extern EnginePins enginePins; static THD_WORKING_AREA(mfiThreadStack, UTILITY_THREAD_STACK_SIZE); // declare thread diff --git a/firmware/controllers/math/engine_math.cpp b/firmware/controllers/math/engine_math.cpp index 9144483877..6dc04c38c7 100644 --- a/firmware/controllers/math/engine_math.cpp +++ b/firmware/controllers/math/engine_math.cpp @@ -34,7 +34,7 @@ EXTERN_ENGINE ; -extern engine_pins_s enginePins; +extern EnginePins enginePins; /** * @return number of milliseconds in one crank shaft revolution diff --git a/firmware/controllers/system/efiGpio.cpp b/firmware/controllers/system/efiGpio.cpp index f92bb2eb99..da0740b756 100644 --- a/firmware/controllers/system/efiGpio.cpp +++ b/firmware/controllers/system/efiGpio.cpp @@ -16,7 +16,8 @@ pin_output_mode_e OUTPUT_MODE_DEFAULT = OM_DEFAULT; // todo: clean this mess, this should become 'static'/private -engine_pins_s enginePins; +EnginePins enginePins; +extern LoggingWithStorage sharedLogger; NamedOutputPin::NamedOutputPin() : OutputPin() { name = NULL; @@ -37,7 +38,7 @@ static const char *injectorNames[INJECTION_PIN_COUNT] = { "i1", "i2", "i3", "i4" "j9", "iA", "iB", "iC"}; -engine_pins_s::engine_pins_s() { +EnginePins::EnginePins() { dizzyOutput.name = DIZZY_NAME; tachOut.name = TACH_NAME; @@ -49,7 +50,18 @@ engine_pins_s::engine_pins_s() { } } -void engine_pins_s::reset() { +bool EnginePins::stopPins() { + bool result = false; + for (int i = 0; i < IGNITION_PIN_COUNT; i++) { + result |= coils[i].stop(); + } + for (int i = 0; i < INJECTION_PIN_COUNT; i++) { + result |= injectors[i].stop(); + } + return result; +} + +void EnginePins::reset() { for (int i = 0; i < INJECTION_PIN_COUNT;i++) { injectors[i].reset(); } @@ -58,6 +70,17 @@ void engine_pins_s::reset() { } } +bool NamedOutputPin::stop() { +#if EFI_PROD_CODE || defined(__DOXYGEN__) + if (isInitialized() && getLogicValue()) { + setValue(false); + scheduleMsg(&sharedLogger, "turning off %s", name); + return true; + } +#endif + return false; +} + void InjectorOutputPin::reset() { overlappingScheduleOffTime = 0; cancelNextTurningInjectorOff = false; diff --git a/firmware/controllers/system/efiGpio.h b/firmware/controllers/system/efiGpio.h index 85ef98fc29..bf31c625c2 100644 --- a/firmware/controllers/system/efiGpio.h +++ b/firmware/controllers/system/efiGpio.h @@ -44,6 +44,10 @@ class NamedOutputPin : public OutputPin { public: NamedOutputPin(); NamedOutputPin(const char *name); + /** + * @return true if pin was stopped + */ + bool stop(); const char *name; }; @@ -64,10 +68,11 @@ public: bool outOfOrder; // https://sourceforge.net/p/rusefi/tickets/319/ }; -class engine_pins_s { +class EnginePins { public: - engine_pins_s(); + EnginePins(); void reset(); + bool stopPins(); OutputPin mainRelay; OutputPin fanRelay; OutputPin acRelay; diff --git a/firmware/global.h b/firmware/global.h index c0cb4358e3..6a76eac9ec 100644 --- a/firmware/global.h +++ b/firmware/global.h @@ -93,7 +93,7 @@ typedef VirtualTimer virtual_timer_t; extern Engine _engine; \ extern persistent_config_s *config; \ extern engine_configuration2_s * engineConfiguration2; \ - extern engine_pins_s enginePins + extern EnginePins enginePins #define DECLARE_ENGINE_PARAMETER_F void #define DECLARE_ENGINE_PARAMETER_S diff --git a/firmware/hw_layer/HIP9011.cpp b/firmware/hw_layer/HIP9011.cpp index 8f0f0845f2..1bba003635 100644 --- a/firmware/hw_layer/HIP9011.cpp +++ b/firmware/hw_layer/HIP9011.cpp @@ -42,7 +42,7 @@ static NamedOutputPin intHold(HIP_NAME); extern uint32_t lastExecutionCount; -extern engine_pins_s enginePins; +extern EnginePins enginePins; uint32_t hipLastExecutionCount; diff --git a/firmware/hw_layer/io_pins.cpp b/firmware/hw_layer/io_pins.cpp index 46595be64a..6984436a0f 100644 --- a/firmware/hw_layer/io_pins.cpp +++ b/firmware/hw_layer/io_pins.cpp @@ -26,7 +26,7 @@ extern board_configuration_s *boardConfiguration; static LoggingWithStorage logger("io_pins"); -extern engine_pins_s enginePins; +extern EnginePins enginePins; #if defined(STM32F4XX) static ioportid_t PORTS[] = { GPIOA, GPIOB, GPIOC, GPIOD, GPIOE, GPIOF, GPIOG, GPIOH }; diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index b3bc47861d..84c2d97d43 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -119,11 +119,7 @@ #include "engine_emulator.h" #endif /* EFI_ENGINE_EMULATOR */ -#if FUEL_MATH_EXTREME_LOGGING LoggingWithStorage sharedLogger("main"); -#else -static LoggingWithStorage sharedLogger("main"); -#endif /* FUEL_MATH_EXTREME_LOGGING */ bool main_loop_started = false; diff --git a/unit_tests/engine_test_helper.cpp b/unit_tests/engine_test_helper.cpp index 6250672eb9..fa42eef3d2 100644 --- a/unit_tests/engine_test_helper.cpp +++ b/unit_tests/engine_test_helper.cpp @@ -15,7 +15,7 @@ #include "advance_map.h" extern int timeNow; -extern engine_pins_s enginePins; +extern EnginePins enginePins; EngineTestHelper::EngineTestHelper(engine_type_e engineType) : engine (&persistentConfig) { ec = &persistentConfig.engineConfiguration; diff --git a/unit_tests/global.h b/unit_tests/global.h index 7d6cf15f51..3357ae3471 100644 --- a/unit_tests/global.h +++ b/unit_tests/global.h @@ -35,7 +35,7 @@ typedef int bool_t; #define CCM_OPTIONAL -#define EXTERN_ENGINE extern engine_pins_s enginePins +#define EXTERN_ENGINE extern EnginePins enginePins #ifdef __cplusplus class Engine; diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index e7b77e4a04..fd5de5c368 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -286,7 +286,7 @@ static void assertREqualsM(const char *msg, void *expected, void *actual) { } extern bool_t debugSignalExecutor; -extern engine_pins_s enginePins; +extern EnginePins enginePins; // todo: move method body here after merge void assertEvent(const char *msg, int index, void *callback, efitime_t start, efitime_t momentX, long param); diff --git a/win32_functional_tests/simulator/global.h b/win32_functional_tests/simulator/global.h index d51a8a9f78..db2fa294e6 100644 --- a/win32_functional_tests/simulator/global.h +++ b/win32_functional_tests/simulator/global.h @@ -103,7 +103,7 @@ void applyNewConfiguration(void); extern persistent_config_s *config; \ extern persistent_config_container_s persistentState; \ extern engine_configuration2_s * engineConfiguration2; \ - extern engine_pins_s enginePins + extern EnginePins enginePins #define DECLARE_ENGINE_PARAMETER_F void #define DECLARE_ENGINE_PARAMETER_S