diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index f2cc7c1d64..6976036b3b 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -433,6 +433,7 @@ void Engine::injectEngineReferences() { INJECT_ENGINE_REFERENCE(&primaryTriggerConfiguration); INJECT_ENGINE_REFERENCE(&vvtTriggerConfiguration); + INJECT_ENGINE_REFERENCE(&limpManager); primaryTriggerConfiguration.update(); vvtTriggerConfiguration.update(); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index af52a52c9c..eac02b47da 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -18,6 +18,7 @@ #include "local_version_holder.h" #include "buttonshift.h" #include "gear_controller.h" +#include "limp_manager.h" #if EFI_SIGNAL_EXECUTOR_ONE_TIMER // PROD real firmware uses this implementation @@ -262,7 +263,6 @@ public: efitimeus_t acSwitchLastChangeTime = 0; bool isRunningPwmTest = false; - bool isRpmHardLimit = false; int getRpmHardLimit(DECLARE_ENGINE_PARAMETER_SIGNATURE); @@ -375,6 +375,8 @@ public: AirmassModelBase* mockAirmassModel = nullptr; + LimpManager limpManager; + private: /** * By the way: diff --git a/firmware/controllers/algo/engine2.cpp b/firmware/controllers/algo/engine2.cpp index 1db4713fdf..699a964490 100644 --- a/firmware/controllers/algo/engine2.cpp +++ b/firmware/controllers/algo/engine2.cpp @@ -181,6 +181,8 @@ void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { updateLaunchConditions(PASS_ENGINE_PARAMETER_SIGNATURE); #endif //EFI_LAUNCH_CONTROL + engine->limpManager.updateState(rpm); + #endif // EFI_ENGINE_CONTROL } diff --git a/firmware/controllers/controllers.mk b/firmware/controllers/controllers.mk index 5a7e271b10..c2e6f1186b 100644 --- a/firmware/controllers/controllers.mk +++ b/firmware/controllers/controllers.mk @@ -56,6 +56,7 @@ CONTROLLERS_SRC_CPP = \ $(CONTROLLERS_DIR)/gear_controller.cpp \ $(CONTROLLERS_DIR)/start_stop.cpp \ $(CONTROLLERS_DIR)/simple_tcu.cpp \ + $(CONTROLLERS_DIR)/limp_manager.cpp \ CONTROLLERS_INC=\ $(CONTROLLERS_DIR) \ diff --git a/firmware/controllers/core/error_handling.cpp b/firmware/controllers/core/error_handling.cpp index 14bea08bc1..fb7344d404 100644 --- a/firmware/controllers/core/error_handling.cpp +++ b/firmware/controllers/core/error_handling.cpp @@ -244,6 +244,7 @@ void firmwareError(obd_code_e code, const char *fmt, ...) { #if EFI_PROD_CODE if (hasFirmwareErrorFlag) return; + engine->limpManager.fatalError(); engine->engineState.warnings.addWarningCode(code); #ifdef EFI_PRINT_ERRORS_AS_WARNINGS va_list ap; diff --git a/firmware/controllers/engine_cycle/main_trigger_callback.cpp b/firmware/controllers/engine_cycle/main_trigger_callback.cpp index a06747e54a..644af6c227 100644 --- a/firmware/controllers/engine_cycle/main_trigger_callback.cpp +++ b/firmware/controllers/engine_cycle/main_trigger_callback.cpp @@ -423,16 +423,10 @@ void mainTriggerCallback(uint32_t trgEventIndex, efitick_t edgeTimestamp DECLARE // TODO: add 'pin shutdown' invocation somewhere - coils might be still open here! return; } - bool limitedSpark = ENGINE(isRpmHardLimit); - bool limitedFuel = ENGINE(isRpmHardLimit); - if (CONFIG(boostCutPressure) != 0) { - // todo: move part of this to periodicFast? probably not cool to decode MAP sensor inside trigger callback? - if (getMap(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(boostCutPressure)) { - limitedSpark = true; - limitedFuel = true; - } - } + bool limitedSpark = !ENGINE(limpManager).allowIgnition(); + bool limitedFuel = !ENGINE(limpManager).allowInjection(); + #if EFI_LAUNCH_CONTROL if (engine->isLaunchCondition && !limitedSpark && !limitedFuel) { /* in case we are not already on a limited conditions, check launch as well */ diff --git a/firmware/controllers/engine_cycle/rpm_calculator.cpp b/firmware/controllers/engine_cycle/rpm_calculator.cpp index 5c4a6c3c37..ce618846b2 100644 --- a/firmware/controllers/engine_cycle/rpm_calculator.cpp +++ b/firmware/controllers/engine_cycle/rpm_calculator.cpp @@ -268,7 +268,6 @@ void rpmShaftPositionCallback(trigger_event_e ckpSignalType, } rpmState->onNewEngineCycle(); rpmState->lastRpmEventTimeNt = nowNt; - engine->isRpmHardLimit = GET_RPM() > engine->getRpmHardLimit(PASS_ENGINE_PARAMETER_SIGNATURE); } diff --git a/firmware/controllers/generated/signature_all.h b/firmware/controllers/generated/signature_all.h index 7634880640..5e0f8851a5 100644 --- a/firmware/controllers/generated/signature_all.h +++ b/firmware/controllers/generated/signature_all.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD all #define SIGNATURE_DATE 2020.12.26 -#define SIGNATURE_HASH 3327659370 -#define TS_SIGNATURE "rusEFI 2020.12.26.all.3327659370" +#define SIGNATURE_HASH 267210507 +#define TS_SIGNATURE "rusEFI 2020.12.26.all.267210507" diff --git a/firmware/controllers/generated/signature_frankenso_na6.h b/firmware/controllers/generated/signature_frankenso_na6.h index 33c78a433d..c7b798f76a 100644 --- a/firmware/controllers/generated/signature_frankenso_na6.h +++ b/firmware/controllers/generated/signature_frankenso_na6.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD frankenso_na6 #define SIGNATURE_DATE 2020.12.26 -#define SIGNATURE_HASH 1344846993 -#define TS_SIGNATURE "rusEFI 2020.12.26.frankenso_na6.1344846993" +#define SIGNATURE_HASH 2577268464 +#define TS_SIGNATURE "rusEFI 2020.12.26.frankenso_na6.2577268464" diff --git a/firmware/controllers/generated/signature_hellen_cypress.h b/firmware/controllers/generated/signature_hellen_cypress.h index 0ab7fa6999..cca275d6e7 100644 --- a/firmware/controllers/generated/signature_hellen_cypress.h +++ b/firmware/controllers/generated/signature_hellen_cypress.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD hellen_cypress #define SIGNATURE_DATE 2020.12.26 -#define SIGNATURE_HASH 262777769 -#define TS_SIGNATURE "rusEFI 2020.12.26.hellen_cypress.262777769" +#define SIGNATURE_HASH 3323783624 +#define TS_SIGNATURE "rusEFI 2020.12.26.hellen_cypress.3323783624" diff --git a/firmware/controllers/generated/signature_kin.h b/firmware/controllers/generated/signature_kin.h index 36bab6be1b..c1ddc2bfe6 100644 --- a/firmware/controllers/generated/signature_kin.h +++ b/firmware/controllers/generated/signature_kin.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD kin #define SIGNATURE_DATE 2020.12.26 -#define SIGNATURE_HASH 1588957523 -#define TS_SIGNATURE "rusEFI 2020.12.26.kin.1588957523" +#define SIGNATURE_HASH 2533413682 +#define TS_SIGNATURE "rusEFI 2020.12.26.kin.2533413682" diff --git a/firmware/controllers/generated/signature_mre_f4.h b/firmware/controllers/generated/signature_mre_f4.h index 987d337b77..ece5831ba8 100644 --- a/firmware/controllers/generated/signature_mre_f4.h +++ b/firmware/controllers/generated/signature_mre_f4.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD mre_f4 #define SIGNATURE_DATE 2020.12.26 -#define SIGNATURE_HASH 3515405075 -#define TS_SIGNATURE "rusEFI 2020.12.26.mre_f4.3515405075" +#define SIGNATURE_HASH 406688114 +#define TS_SIGNATURE "rusEFI 2020.12.26.mre_f4.406688114" diff --git a/firmware/controllers/generated/signature_mre_f7.h b/firmware/controllers/generated/signature_mre_f7.h index 0d4ab18ea8..8325770c3f 100644 --- a/firmware/controllers/generated/signature_mre_f7.h +++ b/firmware/controllers/generated/signature_mre_f7.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD mre_f7 #define SIGNATURE_DATE 2020.12.26 -#define SIGNATURE_HASH 3515405075 -#define TS_SIGNATURE "rusEFI 2020.12.26.mre_f7.3515405075" +#define SIGNATURE_HASH 406688114 +#define TS_SIGNATURE "rusEFI 2020.12.26.mre_f7.406688114" diff --git a/firmware/controllers/generated/signature_prometheus_405.h b/firmware/controllers/generated/signature_prometheus_405.h index acd07d71cf..6172b83271 100644 --- a/firmware/controllers/generated/signature_prometheus_405.h +++ b/firmware/controllers/generated/signature_prometheus_405.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD prometheus_405 #define SIGNATURE_DATE 2020.12.26 -#define SIGNATURE_HASH 2222983995 -#define TS_SIGNATURE "rusEFI 2020.12.26.prometheus_405.2222983995" +#define SIGNATURE_HASH 1295337818 +#define TS_SIGNATURE "rusEFI 2020.12.26.prometheus_405.1295337818" diff --git a/firmware/controllers/generated/signature_prometheus_469.h b/firmware/controllers/generated/signature_prometheus_469.h index 800947ff22..e57426daa6 100644 --- a/firmware/controllers/generated/signature_prometheus_469.h +++ b/firmware/controllers/generated/signature_prometheus_469.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD prometheus_469 #define SIGNATURE_DATE 2020.12.26 -#define SIGNATURE_HASH 2222983995 -#define TS_SIGNATURE "rusEFI 2020.12.26.prometheus_469.2222983995" +#define SIGNATURE_HASH 1295337818 +#define TS_SIGNATURE "rusEFI 2020.12.26.prometheus_469.1295337818" diff --git a/firmware/controllers/generated/signature_proteus_f4.h b/firmware/controllers/generated/signature_proteus_f4.h index 30f1a5a610..cf7dc6955c 100644 --- a/firmware/controllers/generated/signature_proteus_f4.h +++ b/firmware/controllers/generated/signature_proteus_f4.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD proteus_f4 #define SIGNATURE_DATE 2020.12.26 -#define SIGNATURE_HASH 267536308 -#define TS_SIGNATURE "rusEFI 2020.12.26.proteus_f4.267536308" +#define SIGNATURE_HASH 3326543317 +#define TS_SIGNATURE "rusEFI 2020.12.26.proteus_f4.3326543317" diff --git a/firmware/controllers/generated/signature_proteus_f7.h b/firmware/controllers/generated/signature_proteus_f7.h index 9e7199009d..5e171da64f 100644 --- a/firmware/controllers/generated/signature_proteus_f7.h +++ b/firmware/controllers/generated/signature_proteus_f7.h @@ -4,5 +4,5 @@ #define SIGNATURE_BOARD proteus_f7 #define SIGNATURE_DATE 2020.12.26 -#define SIGNATURE_HASH 267536308 -#define TS_SIGNATURE "rusEFI 2020.12.26.proteus_f7.267536308" +#define SIGNATURE_HASH 3326543317 +#define TS_SIGNATURE "rusEFI 2020.12.26.proteus_f7.3326543317" diff --git a/firmware/controllers/limp_manager.cpp b/firmware/controllers/limp_manager.cpp new file mode 100644 index 0000000000..606359b178 --- /dev/null +++ b/firmware/controllers/limp_manager.cpp @@ -0,0 +1,66 @@ +#include "limp_manager.h" +#include "engine.h" +#include "map.h" +#include "efilib.h" + +EXTERN_ENGINE; + +void LimpManager::updateState(int rpm) { + // User-configured hard RPM limit + bool isRevLimited = rpm > engine->getRpmHardLimit(PASS_ENGINE_PARAMETER_SIGNATURE); + + // TODO: user configurable what gets limited + bool limitFuel = isRevLimited; + bool limitSpark = isRevLimited; + + // Force fuel limiting on the fault rev limit + if (rpm > m_faultRevLimit) { + limitFuel = true; + } + + // Limit fuel only on boost pressure (limiting spark bends valves) + if (CONFIG(boostCutPressure) != 0) { + if (getMap(PASS_ENGINE_PARAMETER_SIGNATURE) > CONFIG(boostCutPressure)) { + limitFuel = true; + } + } + + m_transientLimitInjection = limitFuel; + m_transientLimitIgnition = limitSpark; +} + +void LimpManager::etbProblem() { + m_allowEtb.clear(); + setFaultRevLimit(1500); +} + +void LimpManager::fatalError() { + m_allowEtb.clear(); + m_allowIgnition.clear(); + m_allowInjection.clear(); + m_allowTriggerInput.clear(); + + setFaultRevLimit(0); +} + +void LimpManager::setFaultRevLimit(int limit) { + // Only allow decreasing the limit + // aka uses the limit of the worst fault to yet occur + m_faultRevLimit = minI(m_faultRevLimit, limit); +} + +bool LimpManager::allowElectronicThrottle() const { + return m_allowEtb; +} + +bool LimpManager::allowTriggerInput() const { + return m_allowTriggerInput; +} + +bool LimpManager::allowInjection() const { + return !m_transientLimitInjection && m_allowInjection; +} + +bool LimpManager::allowIgnition() const { + return !m_transientLimitIgnition && m_allowIgnition; +} diff --git a/firmware/controllers/limp_manager.h b/firmware/controllers/limp_manager.h new file mode 100644 index 0000000000..183524b77d --- /dev/null +++ b/firmware/controllers/limp_manager.h @@ -0,0 +1,54 @@ +#pragma once + +#include "engine_ptr.h" + +#include + +// Only allows clearing the value, but never resetting it. +class Clearable { +public: + void clear() { + m_value = false; + } + + operator bool() const { + return m_value; + } + +private: + bool m_value = true; +}; + +class LimpManager { +public: + DECLARE_ENGINE_PTR; + + // This is called from periodicFastCallback to update internal state + void updateState(int rpm); + + // Other subsystems call these APIs to determine their behavior + bool allowElectronicThrottle() const; + + bool allowInjection() const; + bool allowIgnition() const; + + bool allowTriggerInput() const; + + // Other subsystems call these APIs to indicate a problem has occured + void etbProblem(); + void fatalError(); + +private: + void setFaultRevLimit(int limit); + + // Start with no fault rev limit + int32_t m_faultRevLimit = INT32_MAX; + + Clearable m_allowEtb; + Clearable m_allowInjection; + Clearable m_allowIgnition; + Clearable m_allowTriggerInput; + + bool m_transientLimitInjection = false; + bool m_transientLimitIgnition = false; +}; diff --git a/firmware/controllers/trigger/trigger_central.cpp b/firmware/controllers/trigger/trigger_central.cpp index 234caec65f..94f39aba97 100644 --- a/firmware/controllers/trigger/trigger_central.cpp +++ b/firmware/controllers/trigger/trigger_central.cpp @@ -276,6 +276,11 @@ uint32_t triggerMaxDuration = 0; void hwHandleShaftSignal(trigger_event_e signal, efitick_t timestamp) { ScopePerf perf(PE::HandleShaftSignal); + // Don't accept trigger input in case of some problems + if (!engine->limpManager.allowTriggerInput()) { + return; + } + #if VR_HW_CHECK_MODE // some boards do not have hardware VR input LEDs which makes such boards harder to validate // from experience we know that assembly mistakes happen and quality control is required diff --git a/firmware/hw_layer/digital_input/trigger/trigger_input_exti.cpp b/firmware/hw_layer/digital_input/trigger/trigger_input_exti.cpp index 52835c62de..fc944f031e 100644 --- a/firmware/hw_layer/digital_input/trigger/trigger_input_exti.cpp +++ b/firmware/hw_layer/digital_input/trigger/trigger_input_exti.cpp @@ -37,8 +37,6 @@ static void shaft_callback(void *arg) { // todo: support for 3rd trigger input channel // todo: start using real event time from HW event, not just software timer? - if (hasFirmwareErrorFlag) - return; bool isPrimary = pal_line == primary_line; if (!isPrimary && !TRIGGER_WAVEFORM(needSecondTriggerInput)) { diff --git a/firmware/hw_layer/digital_input/trigger/trigger_input_icu.cpp b/firmware/hw_layer/digital_input/trigger/trigger_input_icu.cpp index b3a5eaf517..4f37e67d21 100644 --- a/firmware/hw_layer/digital_input/trigger/trigger_input_icu.cpp +++ b/firmware/hw_layer/digital_input/trigger/trigger_input_icu.cpp @@ -65,8 +65,7 @@ static void shaftRisingCallback(bool isPrimary) { } icuRisingCallbackCounter++; // todo: support for 3rd trigger input channel - if (hasFirmwareErrorFlag) - return; + if (!isPrimary && !TRIGGER_WAVEFORM(needSecondTriggerInput)) { return; } @@ -86,8 +85,6 @@ static void shaftFallingCallback(bool isPrimary) { icuFallingCallbackCounter++; - if (hasFirmwareErrorFlag) - return; if (!isPrimary && !TRIGGER_WAVEFORM(needSecondTriggerInput)) { return; } diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index d0b7d93674..9f857402d3 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -71,8 +71,6 @@ EXTERN_ENGINE; -extern bool hasFirmwareErrorFlag; - #if HAL_USE_SPI extern bool isSpiInitialized[5]; diff --git a/firmware/hw_layer/trigger_input_adc.cpp b/firmware/hw_layer/trigger_input_adc.cpp index 51176c9758..c3a3410d1d 100644 --- a/firmware/hw_layer/trigger_input_adc.cpp +++ b/firmware/hw_layer/trigger_input_adc.cpp @@ -20,9 +20,6 @@ extern "C" void toggleLed(int led, int mode); #define BOARD_MOD1_PORT GPIOD #define BOARD_MOD1_PIN 5 - -extern bool hasFirmwareErrorFlag; - EXTERN_ENGINE ; static Logging *logger; @@ -116,8 +113,6 @@ static void onTriggerChanged(efitick_t stamp, bool isPrimary, bool isRising) { #if 1 // todo: support for 3rd trigger input channel // todo: start using real event time from HW event, not just software timer? - if (hasFirmwareErrorFlag) - return; if (!isPrimary && !TRIGGER_WAVEFORM(needSecondTriggerInput)) { return; diff --git a/firmware/tunerstudio/generated/cache.zip b/firmware/tunerstudio/generated/cache.zip index d4474f0604..78fce35615 100644 Binary files a/firmware/tunerstudio/generated/cache.zip and b/firmware/tunerstudio/generated/cache.zip differ diff --git a/firmware/tunerstudio/generated/rusefi.ini b/firmware/tunerstudio/generated/rusefi.ini index c050dc3769..5409333c68 100644 --- a/firmware/tunerstudio/generated/rusefi.ini +++ b/firmware/tunerstudio/generated/rusefi.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.12.26.all.3327659370" + signature = "rusEFI 2020.12.26.all.267210507" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.12.26.all.3327659370" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.12.26.all.267210507" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -77,7 +77,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 18:43:04 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 21:17:38 UTC 2020 pageSize = 20000 page = 1 @@ -2954,10 +2954,6 @@ cmd_test_spk9 = "Z\x00\x12\x00\x09" cmd_test_spk10 = "Z\x00\x12\x00\x0a" cmd_test_spk11 = "Z\x00\x12\x00\x0b" cmd_test_spk12 = "Z\x00\x12\x00\x0c" -cmd_test_spk13 = "Z\x00\x12\x00\x0d" -cmd_test_spk14 = "Z\x00\x12\x00\x0e" -cmd_test_spk15 = "Z\x00\x12\x00\x0f" -cmd_test_spk16 = "Z\x00\x12\x00\x10" cmd_test_fsio1 = "Z\x00\x21\x00\x01" cmd_test_fsio2 = "Z\x00\x21\x00\x02" diff --git a/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini b/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini index 5eb40ae312..09d0aba13f 100644 --- a/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini +++ b/firmware/tunerstudio/generated/rusefi_frankenso_na6.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.12.26.frankenso_na6.1344846993" + signature = "rusEFI 2020.12.26.frankenso_na6.2577268464" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.12.26.frankenso_na6.1344846993" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.12.26.frankenso_na6.2577268464" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -77,7 +77,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 18:43:10 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 21:17:43 UTC 2020 pageSize = 20000 page = 1 @@ -2954,10 +2954,6 @@ cmd_test_spk9 = "Z\x00\x12\x00\x09" cmd_test_spk10 = "Z\x00\x12\x00\x0a" cmd_test_spk11 = "Z\x00\x12\x00\x0b" cmd_test_spk12 = "Z\x00\x12\x00\x0c" -cmd_test_spk13 = "Z\x00\x12\x00\x0d" -cmd_test_spk14 = "Z\x00\x12\x00\x0e" -cmd_test_spk15 = "Z\x00\x12\x00\x0f" -cmd_test_spk16 = "Z\x00\x12\x00\x10" cmd_test_fsio1 = "Z\x00\x21\x00\x01" cmd_test_fsio2 = "Z\x00\x21\x00\x02" diff --git a/firmware/tunerstudio/generated/rusefi_hellen_cypress.ini b/firmware/tunerstudio/generated/rusefi_hellen_cypress.ini index ca891dad73..f061731920 100644 --- a/firmware/tunerstudio/generated/rusefi_hellen_cypress.ini +++ b/firmware/tunerstudio/generated/rusefi_hellen_cypress.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.12.26.hellen_cypress.262777769" + signature = "rusEFI 2020.12.26.hellen_cypress.3323783624" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.12.26.hellen_cypress.262777769" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.12.26.hellen_cypress.3323783624" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -77,7 +77,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on hellen_cypress_gen_config.bat integration/rusefi_config.txt Sat Dec 26 18:43:31 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on hellen_cypress_gen_config.bat integration/rusefi_config.txt Sat Dec 26 21:18:00 UTC 2020 pageSize = 20000 page = 1 @@ -2954,10 +2954,6 @@ cmd_test_spk9 = "Z\x00\x12\x00\x09" cmd_test_spk10 = "Z\x00\x12\x00\x0a" cmd_test_spk11 = "Z\x00\x12\x00\x0b" cmd_test_spk12 = "Z\x00\x12\x00\x0c" -cmd_test_spk13 = "Z\x00\x12\x00\x0d" -cmd_test_spk14 = "Z\x00\x12\x00\x0e" -cmd_test_spk15 = "Z\x00\x12\x00\x0f" -cmd_test_spk16 = "Z\x00\x12\x00\x10" cmd_test_fsio1 = "Z\x00\x21\x00\x01" cmd_test_fsio2 = "Z\x00\x21\x00\x02" diff --git a/firmware/tunerstudio/generated/rusefi_kinetis.ini b/firmware/tunerstudio/generated/rusefi_kinetis.ini index f0e4d6c0d0..b0bd27c91d 100644 --- a/firmware/tunerstudio/generated/rusefi_kinetis.ini +++ b/firmware/tunerstudio/generated/rusefi_kinetis.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.12.26.kin.1588957523" + signature = "rusEFI 2020.12.26.kin.2533413682" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.12.26.kin.1588957523" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.12.26.kin.2533413682" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -77,7 +77,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on kinetis_gen_config.bat integration/rusefi_config.txt Sat Dec 26 18:43:23 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on kinetis_gen_config.bat integration/rusefi_config.txt Sat Dec 26 21:17:51 UTC 2020 pageSize = 20000 page = 1 @@ -2954,10 +2954,6 @@ cmd_test_spk9 = "Z\x00\x12\x00\x09" cmd_test_spk10 = "Z\x00\x12\x00\x0a" cmd_test_spk11 = "Z\x00\x12\x00\x0b" cmd_test_spk12 = "Z\x00\x12\x00\x0c" -cmd_test_spk13 = "Z\x00\x12\x00\x0d" -cmd_test_spk14 = "Z\x00\x12\x00\x0e" -cmd_test_spk15 = "Z\x00\x12\x00\x0f" -cmd_test_spk16 = "Z\x00\x12\x00\x10" cmd_test_fsio1 = "Z\x00\x21\x00\x01" cmd_test_fsio2 = "Z\x00\x21\x00\x02" diff --git a/firmware/tunerstudio/generated/rusefi_mre_f4.ini b/firmware/tunerstudio/generated/rusefi_mre_f4.ini index b1ae3a6b8b..e521d8cdda 100644 --- a/firmware/tunerstudio/generated/rusefi_mre_f4.ini +++ b/firmware/tunerstudio/generated/rusefi_mre_f4.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.12.26.mre_f4.3515405075" + signature = "rusEFI 2020.12.26.mre_f4.406688114" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.12.26.mre_f4.3515405075" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.12.26.mre_f4.406688114" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -77,7 +77,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 18:43:08 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 21:17:41 UTC 2020 pageSize = 20000 page = 1 @@ -2950,10 +2950,6 @@ cmd_test_spk9 = "Z\x00\x12\x00\x09" cmd_test_spk10 = "Z\x00\x12\x00\x0a" cmd_test_spk11 = "Z\x00\x12\x00\x0b" cmd_test_spk12 = "Z\x00\x12\x00\x0c" -cmd_test_spk13 = "Z\x00\x12\x00\x0d" -cmd_test_spk14 = "Z\x00\x12\x00\x0e" -cmd_test_spk15 = "Z\x00\x12\x00\x0f" -cmd_test_spk16 = "Z\x00\x12\x00\x10" cmd_test_fsio1 = "Z\x00\x21\x00\x01" cmd_test_fsio2 = "Z\x00\x21\x00\x02" diff --git a/firmware/tunerstudio/generated/rusefi_mre_f7.ini b/firmware/tunerstudio/generated/rusefi_mre_f7.ini index 8972423b57..7c168e524d 100644 --- a/firmware/tunerstudio/generated/rusefi_mre_f7.ini +++ b/firmware/tunerstudio/generated/rusefi_mre_f7.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.12.26.mre_f7.3515405075" + signature = "rusEFI 2020.12.26.mre_f7.406688114" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.12.26.mre_f7.3515405075" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.12.26.mre_f7.406688114" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -77,7 +77,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 18:43:06 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 21:17:39 UTC 2020 pageSize = 20000 page = 1 @@ -2950,10 +2950,6 @@ cmd_test_spk9 = "Z\x00\x12\x00\x09" cmd_test_spk10 = "Z\x00\x12\x00\x0a" cmd_test_spk11 = "Z\x00\x12\x00\x0b" cmd_test_spk12 = "Z\x00\x12\x00\x0c" -cmd_test_spk13 = "Z\x00\x12\x00\x0d" -cmd_test_spk14 = "Z\x00\x12\x00\x0e" -cmd_test_spk15 = "Z\x00\x12\x00\x0f" -cmd_test_spk16 = "Z\x00\x12\x00\x10" cmd_test_fsio1 = "Z\x00\x21\x00\x01" cmd_test_fsio2 = "Z\x00\x21\x00\x02" diff --git a/firmware/tunerstudio/generated/rusefi_prometheus_405.ini b/firmware/tunerstudio/generated/rusefi_prometheus_405.ini index 121fd2d0a9..8dd83cf55f 100644 --- a/firmware/tunerstudio/generated/rusefi_prometheus_405.ini +++ b/firmware/tunerstudio/generated/rusefi_prometheus_405.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.12.26.prometheus_405.2222983995" + signature = "rusEFI 2020.12.26.prometheus_405.1295337818" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.12.26.prometheus_405.2222983995" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.12.26.prometheus_405.1295337818" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -77,7 +77,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 18:43:15 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 21:17:46 UTC 2020 pageSize = 20000 page = 1 @@ -2950,10 +2950,6 @@ cmd_test_spk9 = "Z\x00\x12\x00\x09" cmd_test_spk10 = "Z\x00\x12\x00\x0a" cmd_test_spk11 = "Z\x00\x12\x00\x0b" cmd_test_spk12 = "Z\x00\x12\x00\x0c" -cmd_test_spk13 = "Z\x00\x12\x00\x0d" -cmd_test_spk14 = "Z\x00\x12\x00\x0e" -cmd_test_spk15 = "Z\x00\x12\x00\x0f" -cmd_test_spk16 = "Z\x00\x12\x00\x10" cmd_test_fsio1 = "Z\x00\x21\x00\x01" cmd_test_fsio2 = "Z\x00\x21\x00\x02" diff --git a/firmware/tunerstudio/generated/rusefi_prometheus_469.ini b/firmware/tunerstudio/generated/rusefi_prometheus_469.ini index 7ed58c24a0..4e106b5f66 100644 --- a/firmware/tunerstudio/generated/rusefi_prometheus_469.ini +++ b/firmware/tunerstudio/generated/rusefi_prometheus_469.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.12.26.prometheus_469.2222983995" + signature = "rusEFI 2020.12.26.prometheus_469.1295337818" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.12.26.prometheus_469.2222983995" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.12.26.prometheus_469.1295337818" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -77,7 +77,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 18:43:13 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 21:17:44 UTC 2020 pageSize = 20000 page = 1 @@ -2950,10 +2950,6 @@ cmd_test_spk9 = "Z\x00\x12\x00\x09" cmd_test_spk10 = "Z\x00\x12\x00\x0a" cmd_test_spk11 = "Z\x00\x12\x00\x0b" cmd_test_spk12 = "Z\x00\x12\x00\x0c" -cmd_test_spk13 = "Z\x00\x12\x00\x0d" -cmd_test_spk14 = "Z\x00\x12\x00\x0e" -cmd_test_spk15 = "Z\x00\x12\x00\x0f" -cmd_test_spk16 = "Z\x00\x12\x00\x10" cmd_test_fsio1 = "Z\x00\x21\x00\x01" cmd_test_fsio2 = "Z\x00\x21\x00\x02" diff --git a/firmware/tunerstudio/generated/rusefi_proteus_f4.ini b/firmware/tunerstudio/generated/rusefi_proteus_f4.ini index b72faa6960..ca8a88b4ee 100644 --- a/firmware/tunerstudio/generated/rusefi_proteus_f4.ini +++ b/firmware/tunerstudio/generated/rusefi_proteus_f4.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.12.26.proteus_f4.267536308" + signature = "rusEFI 2020.12.26.proteus_f4.3326543317" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.12.26.proteus_f4.267536308" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.12.26.proteus_f4.3326543317" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -77,7 +77,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 18:43:20 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 21:17:49 UTC 2020 pageSize = 20000 page = 1 @@ -2946,10 +2946,6 @@ cmd_test_spk9 = "Z\x00\x12\x00\x09" cmd_test_spk10 = "Z\x00\x12\x00\x0a" cmd_test_spk11 = "Z\x00\x12\x00\x0b" cmd_test_spk12 = "Z\x00\x12\x00\x0c" -cmd_test_spk13 = "Z\x00\x12\x00\x0d" -cmd_test_spk14 = "Z\x00\x12\x00\x0e" -cmd_test_spk15 = "Z\x00\x12\x00\x0f" -cmd_test_spk16 = "Z\x00\x12\x00\x10" cmd_test_fsio1 = "Z\x00\x21\x00\x01" cmd_test_fsio2 = "Z\x00\x21\x00\x02" diff --git a/firmware/tunerstudio/generated/rusefi_proteus_f7.ini b/firmware/tunerstudio/generated/rusefi_proteus_f7.ini index e18136e329..e30cecb1e0 100644 --- a/firmware/tunerstudio/generated/rusefi_proteus_f7.ini +++ b/firmware/tunerstudio/generated/rusefi_proteus_f7.ini @@ -33,12 +33,12 @@ enable2ndByteCanID = false [MegaTune] ; https://rusefi.com/forum/viewtopic.php?p=36201#p36201 - signature = "rusEFI 2020.12.26.proteus_f7.267536308" + signature = "rusEFI 2020.12.26.proteus_f7.3326543317" [TunerStudio] queryCommand = "S" versionInfo = "V" ; firmwave version for title bar. - signature = "rusEFI 2020.12.26.proteus_f7.267536308" ; signature is expected to be 7 or more characters. + signature = "rusEFI 2020.12.26.proteus_f7.3326543317" ; signature is expected to be 7 or more characters. [Constants] ; new packet serial format with CRC @@ -77,7 +77,7 @@ enable2ndByteCanID = false ; see PAGE_0_SIZE in C source code ; CONFIG_DEFINITION_START -; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 18:43:18 UTC 2020 +; this section was generated automatically by rusEfi tool ConfigDefinition.jar based on gen_config.sh integration/rusefi_config.txt Sat Dec 26 21:17:48 UTC 2020 pageSize = 20000 page = 1 @@ -2946,10 +2946,6 @@ cmd_test_spk9 = "Z\x00\x12\x00\x09" cmd_test_spk10 = "Z\x00\x12\x00\x0a" cmd_test_spk11 = "Z\x00\x12\x00\x0b" cmd_test_spk12 = "Z\x00\x12\x00\x0c" -cmd_test_spk13 = "Z\x00\x12\x00\x0d" -cmd_test_spk14 = "Z\x00\x12\x00\x0e" -cmd_test_spk15 = "Z\x00\x12\x00\x0f" -cmd_test_spk16 = "Z\x00\x12\x00\x10" cmd_test_fsio1 = "Z\x00\x21\x00\x01" cmd_test_fsio2 = "Z\x00\x21\x00\x02" diff --git a/java_console/autotest/src/com/rusefi/FunctionalTest.java b/java_console/autotest/src/com/rusefi/FunctionalTest.java index 2a67a77798..c5f62ad089 100644 --- a/java_console/autotest/src/com/rusefi/FunctionalTest.java +++ b/java_console/autotest/src/com/rusefi/FunctionalTest.java @@ -13,6 +13,7 @@ import org.junit.Test; import static com.rusefi.IoUtil.getEnableCommand; import static com.rusefi.TestingUtils.*; import static com.rusefi.config.generated.Fields.*; +import static org.junit.Assert.assertFalse; /** * rusEfi firmware simulator functional test suite @@ -93,6 +94,52 @@ public class FunctionalTest extends RusefiTestBase { } } + @Test + public void testRevLimiter() { + String msg = "rev limiter"; + + ecu.setEngineType(ET_FORD_ASPIRE); + ecu.changeRpm(2000); + + // Alpha-N mode so that we actually inject some fuel (without mocking tons of sensors) + ecu.sendCommand("set algorithm 5"); + // Set tps to 25% - make alpha-n happy + ecu.sendCommand("set_sensor_mock 10 25"); + ecu.sendCommand("set rpm_hard_limit 2500"); + + { + // Check that neither ignition nor injection is cut + EngineChart chart = nextChart(); + + assertWaveNotNull(chart, EngineChart.SPARK_1); + assertWaveNotNull(chart, EngineChart.INJECTOR_1); + } + + // Now go above the hard limiter + ecu.changeRpm(3000); + + { + // Check that both ignition and injection are cut + EngineChart chart = nextChart(); + + // These channels are allowed to have falling edges - aka closing injectors and firing coils + // but not allowed to have rising edges - aka opening injectors and charging coils + assertWaveNoRises(chart, EngineChart.SPARK_1); + assertWaveNoRises(chart, EngineChart.INJECTOR_1); + } + + // Check that it recovers when we go back under the limit + ecu.changeRpm(2000); + + { + // Check that neither ignition nor injection is cut + EngineChart chart = nextChart(); + + assertWaveNotNull(chart, EngineChart.SPARK_1); + assertWaveNotNull(chart, EngineChart.INJECTOR_1); + } + } + @Test public void testCustomEngine() { ecu.setEngineType(ET_DEFAULT_FRANKENSO); @@ -421,6 +468,18 @@ public class FunctionalTest extends RusefiTestBase { assertTrue(chart.get(key) != null); } + private static void assertWaveNoRises(EngineChart chart, String key) { + StringBuilder events = chart.get(key); + + // if no events of this type at all, return since this passes the test + if (events == null) { + return; + } + + // Assert that there are no up (rise) events in the channel's sequence + assertFalse(events.toString().contains("u")); + } + private EngineChart nextChart() { return TestingUtils.nextChart(ecu.commandQueue); } diff --git a/unit_tests/tests/test_limp.cpp b/unit_tests/tests/test_limp.cpp new file mode 100644 index 0000000000..128b418e5d --- /dev/null +++ b/unit_tests/tests/test_limp.cpp @@ -0,0 +1,76 @@ +#include "limp_manager.h" +#include "engine_test_helper.h" +#include + +TEST(limp, testFatalError) { + LimpManager dut; + + // Everything should work by default + ASSERT_TRUE(dut.allowElectronicThrottle()); + ASSERT_TRUE(dut.allowIgnition()); + ASSERT_TRUE(dut.allowInjection()); + ASSERT_TRUE(dut.allowTriggerInput()); + + dut.fatalError(); + + // Fatal error should kill everything + EXPECT_FALSE(dut.allowElectronicThrottle()); + EXPECT_FALSE(dut.allowIgnition()); + EXPECT_FALSE(dut.allowInjection()); + EXPECT_FALSE(dut.allowTriggerInput()); +} + +TEST(limp, revLimit) { + WITH_ENGINE_TEST_HELPER(TEST_ENGINE); + + engineConfiguration->rpmHardLimit = 2500; + + LimpManager dut; + INJECT_ENGINE_REFERENCE(&dut); + + // Under rev limit, inj/ign allowed + dut.updateState(2000); + EXPECT_TRUE(dut.allowIgnition()); + EXPECT_TRUE(dut.allowInjection()); + + // Over rev limit, no injection + dut.updateState(3000); + EXPECT_FALSE(dut.allowIgnition()); + EXPECT_FALSE(dut.allowInjection()); + + // Now recover back to under limit + dut.updateState(2000); + EXPECT_TRUE(dut.allowIgnition()); + EXPECT_TRUE(dut.allowInjection()); +} + +TEST(limp, boostCut) { + WITH_ENGINE_TEST_HELPER(TEST_ENGINE); + + // Cut above 100kPa + engineConfiguration->boostCutPressure = 100; + + LimpManager dut; + INJECT_ENGINE_REFERENCE(&dut); + + // Below threshold, injection allowed + engine->mockMapValue = 80; + dut.updateState(1000); + EXPECT_TRUE(dut.allowInjection()); + + // Above threshold, injection cut + engine->mockMapValue = 120; + dut.updateState(1000); + EXPECT_FALSE(dut.allowInjection()); + + // Below threshold, should recover + engine->mockMapValue = 80; + dut.updateState(1000); + EXPECT_TRUE(dut.allowInjection()); + + // SPECIAL CASE: threshold of 0 means never boost cut + engineConfiguration->boostCutPressure = 0; + engine->mockMapValue = 500; + dut.updateState(1000); + EXPECT_TRUE(dut.allowInjection()); +} diff --git a/unit_tests/tests/tests.mk b/unit_tests/tests/tests.mk index 8200b2bb72..abf0461973 100644 --- a/unit_tests/tests/tests.mk +++ b/unit_tests/tests/tests.mk @@ -64,4 +64,5 @@ TESTS_SRC_CPP = \ tests/test_binary_log.cpp \ tests/test_dynoview.cpp \ tests/test_gpio.cpp \ + tests/test_limp.cpp \