From e0763c69948d09a68096a28b35c5120321ac9cd4 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Thu, 11 Mar 2021 05:38:52 -0800 Subject: [PATCH] stop trigger emulator PWM when disabled (#2443) * simplify trig emulator * spelling is hard * fix various builds * spelling again * add command/button for external stimulation * enable hw stim for HW-in-loop test * s * I does spelling good * clear flag when disabled * generate enough for console build * don't disable that * this test needs external stimulation enabled * import * ui improvements Co-authored-by: Matthew Kennedy --- firmware/controllers/bench_test.cpp | 14 ++++-- firmware/controllers/settings.cpp | 14 +++++- .../trigger/trigger_emulator_algo.cpp | 49 +++++++++++-------- .../trigger/trigger_emulator_algo.h | 4 ++ firmware/integration/rusefi_config.txt | 1 + firmware/rusefi.cpp | 3 +- firmware/tunerstudio/rusefi.input | 18 ++++--- .../rusefi/f4discovery/PwmHardwareTest.java | 1 - .../f4discovery/VssHardwareLoopTest.java | 4 +- .../com/rusefi/config/generated/Fields.java | 3 +- simulator/simulator/rusEfiFunctionalTest.cpp | 2 +- 11 files changed, 73 insertions(+), 40 deletions(-) diff --git a/firmware/controllers/bench_test.cpp b/firmware/controllers/bench_test.cpp index 26f28d3f0a..afe57e36aa 100644 --- a/firmware/controllers/bench_test.cpp +++ b/firmware/controllers/bench_test.cpp @@ -42,6 +42,7 @@ #include "cj125.h" #include "malfunction_central.h" #include "tunerstudio_outputs.h" +#include "trigger_emulator_algo.h" #if EFI_WIDEBAND_FIRMWARE_UPDATE #include "can.h" @@ -344,9 +345,17 @@ static void handleCommandX14(uint16_t index) { writeToFlashNow(); #endif /* EFI_INTERNAL_FLASH */ return; +#if EFI_EMULATE_POSITION_SENSORS case 0xD: - engine->directSelfStimulation = true; + enableTriggerStimulator(); return; + case 0xF: + disableTriggerStimulator(); + return; + case 0x13: + enableExternalTriggerStimulator(); + return; +#endif // EFI_EMULATE_POSITION_SENSORS #if EFI_ELECTRONIC_THROTTLE_BODY case 0xE: etbAutocal(0); @@ -364,9 +373,6 @@ static void handleCommandX14(uint16_t index) { #endif // EFI_TUNER_STUDIO return; #endif - case 0xF: - engine->directSelfStimulation = false; - return; case 0x12: widebandUpdatePending = true; return; diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 55d1432642..436168300a 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -891,8 +891,20 @@ static void enableOrDisable(const char *param, bool isEnabled) { engineConfiguration->invertCamVVTSignal = isEnabled; } else if (strEqualCaseInsensitive(param, CMD_IGNITION)) { engineConfiguration->isIgnitionEnabled = isEnabled; +#if EFI_EMULATE_POSITION_SENSORS } else if (strEqualCaseInsensitive(param, CMD_SELF_STIMULATION)) { - engine->directSelfStimulation = isEnabled; + if (isEnabled) { + enableTriggerStimulator(); + } else { + disableTriggerStimulator(); + } + } else if (strEqualCaseInsensitive(param, CMD_EXTERNAL_STIMULATION)) { + if (isEnabled) { + enableExternalTriggerStimulator(); + } else { + disableTriggerStimulator(); + } +#endif } else if (strEqualCaseInsensitive(param, "engine_control")) { engineConfiguration->isEngineControlEnabled = isEnabled; } else if (strEqualCaseInsensitive(param, "map_avg")) { diff --git a/firmware/controllers/trigger/trigger_emulator_algo.cpp b/firmware/controllers/trigger/trigger_emulator_algo.cpp index 3addd9c806..58b74034e6 100644 --- a/firmware/controllers/trigger/trigger_emulator_algo.cpp +++ b/firmware/controllers/trigger/trigger_emulator_algo.cpp @@ -86,7 +86,6 @@ PwmConfig triggerSignal(pwmSwitchTimesBuffer, sr); #define DO_NOT_STOP 999999999 static int stopEmulationAtIndex = DO_NOT_STOP; -static bool isEmulating = true; static Logging *logger; static int atTriggerVersion = 0; @@ -135,13 +134,6 @@ static TriggerEmulatorHelper helper; static bool hasStimPins = false; static void emulatorApplyPinState(int stateIndex, PwmConfig *state) /* pwm_gen_callback */ { - if (stopEmulationAtIndex == stateIndex) { - isEmulating = false; - } - if (!isEmulating) { - return; - } - if (engine->directSelfStimulation) { /** * this callback would invoke the input signal handlers directly @@ -155,20 +147,15 @@ static void emulatorApplyPinState(int stateIndex, PwmConfig *state) /* pwm_gen_c applyPinState(stateIndex, state); } #endif /* EFI_PROD_CODE */ - } -static void setEmulatorAtIndex(int index) { - stopEmulationAtIndex = index; -} +static bool hasInitTriggerEmulator = false; -static void resumeStimulator() { - isEmulating = true; - stopEmulationAtIndex = DO_NOT_STOP; -} - -void initTriggerEmulatorLogic(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { - logger = sharedLogger; +static void initTriggerPwm() { + // No need to start more than once + if (hasInitTriggerEmulator) { + return; + } TriggerWaveform *s = &engine->triggerCentral.triggerShape; setTriggerEmulatorRPM(engineConfiguration->triggerSimulatorFrequency PASS_ENGINE_PARAMETER_SUFFIX); @@ -183,9 +170,29 @@ void initTriggerEmulatorLogic(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUF phaseCount, s->wave.switchTimes, PWM_PHASE_MAX_WAVE_PER_PWM, pinStates, updateTriggerWaveformIfNeeded, (pwm_gen_callback*)emulatorApplyPinState); + hasInitTriggerEmulator = true; +} + +void enableTriggerStimulator() { + initTriggerPwm(); + engine->directSelfStimulation = true; +} + +void enableExternalTriggerStimulator() { + initTriggerPwm(); + engine->directSelfStimulation = false; +} + +void disableTriggerStimulator() { + engine->directSelfStimulation = false; + triggerSignal.stop(); + hasInitTriggerEmulator = false; +} + +void initTriggerEmulatorLogic(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { + logger = sharedLogger; + addConsoleActionI(CMD_RPM, setTriggerEmulatorRPM); - addConsoleActionI("stop_stimulator_at_index", setEmulatorAtIndex); - addConsoleAction("resume_stimulator", resumeStimulator); } void onConfigurationChangeRpmEmulatorCallback(engine_configuration_s *previousConfiguration) { diff --git a/firmware/controllers/trigger/trigger_emulator_algo.h b/firmware/controllers/trigger/trigger_emulator_algo.h index 8038fe6991..dddfd57f8e 100644 --- a/firmware/controllers/trigger/trigger_emulator_algo.h +++ b/firmware/controllers/trigger/trigger_emulator_algo.h @@ -19,6 +19,10 @@ void stopTriggerEmulatorPins(); void setTriggerEmulatorRPM(int value DECLARE_ENGINE_PARAMETER_SUFFIX); void onConfigurationChangeRpmEmulatorCallback(engine_configuration_s *previousConfiguration); +// Start & stop trigger emulation +void enableTriggerStimulator(); +void enableExternalTriggerStimulator(); +void disableTriggerStimulator(); class TriggerEmulatorHelper { public: diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 7b81593fa2..ded0b27ff7 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -1764,6 +1764,7 @@ end_struct #define CMD_CALIBRATE_PEDAL_DOWN "calibrate_pedal_down" #define CMD_ETB_DUTY "set_etb_duty" #define CMD_SELF_STIMULATION "self_stimulation" +#define CMD_EXTERNAL_STIMULATION "ext_stimulation" #define CMD_RPM "rpm" #define CMD_VSS_PIN "vss_pin" #define CMD_TRIGGER_PIN "set_trigger_input_pin" diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 9b76866847..b05bf19f7e 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -126,6 +126,7 @@ #include "mpu_util.h" #include "tunerstudio.h" #include "mmc_card.h" +#include "trigger_emulator_algo.h" #if EFI_HD44780_LCD #include "lcd_HD44780.h" @@ -201,7 +202,7 @@ void runRusEfi(void) { #if HW_CHECK_ALWAYS_STIMULATE // we need a special binary for final assembly check. We cannot afford to require too much software or too many steps // to be executed at the place of assembly - engine->directSelfStimulation = true; + enableTriggerStimulator(); #endif // HW_CHECK_ALWAYS_STIMULATE diff --git a/firmware/tunerstudio/rusefi.input b/firmware/tunerstudio/rusefi.input index 8bc91dd994..3a291f12c7 100644 --- a/firmware/tunerstudio/rusefi.input +++ b/firmware/tunerstudio/rusefi.input @@ -1661,6 +1661,7 @@ cmd_disable_self_stim = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x0F" cmd_etb_autotune_stop = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x10" cmb_etb_auto_calibrate_2 = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x11" cmd_wideband_firmare_update = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x12" +cmd_enable_ext_stim = "@@TS_IO_TEST_COMMAND_char@@\x00\x14\x00\x13" cmd_cj125_calibrate = "@@TS_IO_TEST_COMMAND_char@@\x00\x18\x00\x00" cmd_call_from_pit = "@@TS_IO_TEST_COMMAND_char@@\x00\x20\x34\x56" @@ -3389,14 +3390,15 @@ cmd_set_engine_type_default = "@@TS_IO_TEST_COMMAND_char@@\x00\x31\x00\x00" ; Board->ECU stimulator dialog = ecuStimulator, "ECU stimulator" field = "Trigger Simulator", triggerSimulatorFrequency - commandButton = "Enable Internal Trigger Simulation", cmd_enable_self_stim - commandButton = "Disable Internal Trigger Simulation", cmd_disable_self_stim - field = "" - field = "digipot spi", digitalPotentiometerSpiDevice - field = "digipot CS #0", digitalPotentiometerChipSelect1 - field = "digipot CS #1", digitalPotentiometerChipSelect2 - field = "digipot CS #2", digitalPotentiometerChipSelect3 - field = "digipot CS #3", digitalPotentiometerChipSelect4 + commandButton = "Enable internal trigger simulation", cmd_enable_self_stim + commandButton = "Enable external trigger simulation", cmd_enable_ext_stim + commandButton = "Disable trigger simulation", cmd_disable_self_stim +; field = "" +; field = "digipot spi", digitalPotentiometerSpiDevice +; field = "digipot CS #0", digitalPotentiometerChipSelect1 +; field = "digipot CS #1", digitalPotentiometerChipSelect2 +; field = "digipot CS #2", digitalPotentiometerChipSelect3 +; field = "digipot CS #3", digitalPotentiometerChipSelect4 field = "" field = "trigger stimulator pin #1", triggerSimulatorPins1 field = "trigger stimulator pin mode #1", triggerSimulatorPinModes1 diff --git a/java_console/autotest/src/com/rusefi/f4discovery/PwmHardwareTest.java b/java_console/autotest/src/com/rusefi/f4discovery/PwmHardwareTest.java index 38184eef9e..dbc59ac241 100644 --- a/java_console/autotest/src/com/rusefi/f4discovery/PwmHardwareTest.java +++ b/java_console/autotest/src/com/rusefi/f4discovery/PwmHardwareTest.java @@ -32,7 +32,6 @@ public class PwmHardwareTest extends RusefiTestBase { @Test public void testIdlePin() { ecu.setEngineType(ET_FRANKENSO_MIATA_NA6); - ecu.sendCommand(getDisableCommand(Fields.CMD_SELF_STIMULATION)); ecu.changeRpm(1000); ecu.sendCommand(CMD_TRIGGER_SIMULATOR_PIN + " 0 none"); diff --git a/java_console/autotest/src/com/rusefi/f4discovery/VssHardwareLoopTest.java b/java_console/autotest/src/com/rusefi/f4discovery/VssHardwareLoopTest.java index 209738cb32..37514d5325 100644 --- a/java_console/autotest/src/com/rusefi/f4discovery/VssHardwareLoopTest.java +++ b/java_console/autotest/src/com/rusefi/f4discovery/VssHardwareLoopTest.java @@ -9,7 +9,7 @@ import com.rusefi.core.SensorCentral; import com.rusefi.functional_tests.EcuTestHelper; import org.junit.Test; -import static com.rusefi.IoUtil.getDisableCommand; +import static com.rusefi.IoUtil.getEnableCommand; import static com.rusefi.binaryprotocol.BinaryProtocol.sleep; import static com.rusefi.config.generated.Fields.*; @@ -28,7 +28,7 @@ public class VssHardwareLoopTest extends RusefiTestBase { @Test public void test() { ecu.setEngineType(ET_FRANKENSO_MIATA_NA6); - ecu.sendCommand(getDisableCommand(Fields.CMD_SELF_STIMULATION)); + ecu.sendCommand(getEnableCommand(Fields.CMD_EXTERNAL_STIMULATION)); ecu.changeRpm(1400); // moving second trigger to another pin diff --git a/java_console/models/src/main/java/com/rusefi/config/generated/Fields.java b/java_console/models/src/main/java/com/rusefi/config/generated/Fields.java index ecae6aa0f7..1457b2b18d 100644 --- a/java_console/models/src/main/java/com/rusefi/config/generated/Fields.java +++ b/java_console/models/src/main/java/com/rusefi/config/generated/Fields.java @@ -1,6 +1,6 @@ package com.rusefi.config.generated; -// this file was generated automatically by rusEFI tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Mar 06 02:08:20 UTC 2021 +// this file was generated automatically by rusEFI tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Wed Mar 10 22:58:01 PST 2021 // by class com.rusefi.output.FileJavaFieldsConsumer import com.rusefi.config.*; @@ -227,6 +227,7 @@ public class Fields { public static final String CMD_ENGINE_TYPE = "engine_type"; public static final String CMD_ENGINESNIFFERRPMTHRESHOLD = "engineSnifferRpmThreshold"; public static final String CMD_ETB_DUTY = "set_etb_duty"; + public static final String CMD_EXTERNAL_STIMULATION = "ext_stimulation"; public static final String CMD_FUEL_BENCH = "fuelbench"; public static final String CMD_FUNCTIONAL_TEST_MODE = "test_mode"; public static final String CMD_HPFP_BENCH = "hpfpbench"; diff --git a/simulator/simulator/rusEfiFunctionalTest.cpp b/simulator/simulator/rusEfiFunctionalTest.cpp index c9e5221fbf..3350acd7aa 100644 --- a/simulator/simulator/rusEfiFunctionalTest.cpp +++ b/simulator/simulator/rusEfiFunctionalTest.cpp @@ -114,7 +114,7 @@ void rusEfiFunctionalTest(void) { // todo: reduce code duplication with initEngineContoller resetConfigurationExt(NULL, FORD_ESCORT_GT PASS_ENGINE_PARAMETER_SUFFIX); - engine->directSelfStimulation = true; + enableTriggerStimulator(); commonInitEngineController(&sharedLogger);