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 <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2021-03-11 05:38:52 -08:00 committed by GitHub
parent af21cd11b5
commit e0763c6994
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 73 additions and 40 deletions

View File

@ -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;

View File

@ -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")) {

View File

@ -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) {

View File

@ -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:

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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");

View File

@ -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

View File

@ -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";

View File

@ -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);