From 77ba93d46406c6c61e69a1ae583988f9f532fb8e Mon Sep 17 00:00:00 2001 From: andreika-git Date: Sun, 25 Jun 2017 08:35:46 +0300 Subject: [PATCH] Fsio progress (#449) * gen_config.bat * FSIO: fuelPump & mainRelay progress * typo --- firmware/controllers/algo/engine.cpp | 27 +++++++++++++++++++ firmware/controllers/algo/engine.h | 11 ++++++++ .../controllers/algo/engine_configuration.cpp | 1 + ...ngine_configuration_generated_structures.h | 10 ++++--- firmware/controllers/algo/rusefi_generated.h | 6 +++-- firmware/controllers/core/fsio_core.h | 2 ++ firmware/controllers/core/fsio_impl.cpp | 12 +++++++++ firmware/controllers/engine_controller.cpp | 1 + firmware/controllers/system_fsio.h | 11 ++++---- firmware/controllers/system_fsio.txt | 5 ++-- .../models/src/com/rusefi/config/Fields.java | 8 +++--- java_console/rusefi.xml | 2 +- 12 files changed, 78 insertions(+), 18 deletions(-) diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 35084ee075..443acd675e 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -20,6 +20,7 @@ #include "speed_density.h" #include "advance_map.h" #include "efilib2.h" +#include "settings.h" #if EFI_PROD_CODE || defined(__DOXYGEN__) #include "injector_central.h" @@ -341,6 +342,32 @@ void Engine::watchdog() { #endif } +void Engine::checkShutdown() { +#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__) + int rpm = rpmCalculator.rpmValue; + + const float vBattThreshold = 5.0f; + if (isValidRpm(rpm) && sensors.vBatt < vBattThreshold) { + stopEngine(); + // todo: add stepper motor parking + } +#endif /* EFI_MAIN_RELAY_CONTROL */ +} + +bool Engine::isInShutdownMode() { +#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__) + if (stopEngineRequestTimeNt == 0) // the shutdown procedure is not started + return false; + + const efitime_t engineStopWaitTimeoutNt = 5LL * 1000000LL; + // The engine is still spinning! Give it some time to stop (but wait no more than 5 secs) + if (isSpinning && (getTimeNowNt() - stopEngineRequestTimeNt) < US2NT(engineStopWaitTimeoutNt)) + return true; + // todo: add checks for stepper motor parking +#endif /* EFI_MAIN_RELAY_CONTROL */ + return false; +} + injection_mode_e Engine::getCurrentInjectionMode(DECLARE_ENGINE_PARAMETER_SIGNATURE) { int rpm = rpmCalculator.rpmValue; return isCrankingR(rpm) ? CONFIG(crankingInjectionMode) : CONFIG(injectionMode); diff --git a/firmware/controllers/algo/engine.h b/firmware/controllers/algo/engine.h index 05600f7a87..beae4c5846 100644 --- a/firmware/controllers/algo/engine.h +++ b/firmware/controllers/algo/engine.h @@ -427,6 +427,17 @@ public: void watchdog(); + /** + * Needed by EFI_MAIN_RELAY_CONTROL to shut down the engine correctly. + */ + void checkShutdown(); + + /** + * Allows to finish some long-term shutdown procedures (stepper motor parking etc.) + Returns true if some operations are in progress on background. + */ + bool isInShutdownMode(); + monitoring_timestamps_s m; void knockLogic(float knockVolts); diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index a88e019053..8043cdd143 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -697,6 +697,7 @@ void setDefaultConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) { engineConfiguration->fuelClosedLoopPid.pFactor = -0.1; engineConfiguration->cranking.baseFuel = 5; + engineConfiguration->startUpFuelPumpDuration = 4; engineConfiguration->idleRpmPid.pFactor = 0.05; engineConfiguration->idleRpmPid.iFactor = 0.002; diff --git a/firmware/controllers/algo/engine_configuration_generated_structures.h b/firmware/controllers/algo/engine_configuration_generated_structures.h index 5833a9884d..9f7b4fd0d5 100644 --- a/firmware/controllers/algo/engine_configuration_generated_structures.h +++ b/firmware/controllers/algo/engine_configuration_generated_structures.h @@ -1,4 +1,4 @@ -// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jun 22 09:24:53 MSK 2017 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jun 25 00:14:59 EEST 2017 // begin #ifndef ENGINE_CONFIGURATION_GENERATED_H_ #define ENGINE_CONFIGURATION_GENERATED_H_ @@ -1551,7 +1551,11 @@ typedef struct { /** * offset 2024 */ - float unusedetb; + int16_t startUpFuelPumpDuration; + /** + * offset 2026 + */ + int16_t unusedetb; /** * CLT-based target RPM for automatic idle controller * offset 2028 @@ -2122,4 +2126,4 @@ typedef struct { #endif // end -// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jun 22 09:24:53 MSK 2017 +// this section was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jun 25 00:14:59 EEST 2017 diff --git a/firmware/controllers/algo/rusefi_generated.h b/firmware/controllers/algo/rusefi_generated.h index 99a6a45307..7d1086543d 100644 --- a/firmware/controllers/algo/rusefi_generated.h +++ b/firmware/controllers/algo/rusefi_generated.h @@ -1102,8 +1102,10 @@ #define throttlePedalWOTVoltage_offset_hex 7e0 #define stepperDirectionPinMode_offset 2020 #define stepperDirectionPinMode_offset_hex 7e4 -#define unusedetb_offset 2024 -#define unusedetb_offset_hex 7e8 +#define startUpFuelPumpDuration_offset 2024 +#define startUpFuelPumpDuration_offset_hex 7e8 +#define unusedetb_offset 2026 +#define unusedetb_offset_hex 7ea #define cltIdleRpmBins_offset 2028 #define cltIdleRpmBins_offset_hex 7ec #define cltIdleRpm_offset 2092 diff --git a/firmware/controllers/core/fsio_core.h b/firmware/controllers/core/fsio_core.h index d21484e225..c226663231 100644 --- a/firmware/controllers/core/fsio_core.h +++ b/firmware/controllers/core/fsio_core.h @@ -54,6 +54,8 @@ typedef enum { LE_METHOD_EXHAUST_VVT = 118, LE_METHOD_IS_COOLANT_BROKEN = 119, LE_METHOD_CRANKING_RPM = 120, + LE_METHOD_STARTUP_FUEL_PUMP_DURATION = 121, + LE_METHOD_IN_SHUTDOWN = 122, Force_4b_le_action = ENUM_32_BITS, diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index a83610495e..f2b49da833 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -45,6 +45,8 @@ static LENameOrdinalPair leKnock(LE_METHOD_KNOCK, "knock"); static LENameOrdinalPair leIntakeVVT(LE_METHOD_INTAKE_VVT, "ivvt"); static LENameOrdinalPair leExhaustVVT(LE_METHOD_EXHAUST_VVT, "evvt"); static LENameOrdinalPair leCrankingRpm(LE_METHOD_CRANKING_RPM, "cranking_rpm"); +static LENameOrdinalPair leStartupFuelPumpDuration(LE_METHOD_STARTUP_FUEL_PUMP_DURATION, "startup_fuel_pump_duration"); +static LENameOrdinalPair leInShutdown(LE_METHOD_IN_SHUTDOWN, "in_shutdown"); #define LE_EVAL_POOL_SIZE 32 @@ -109,6 +111,11 @@ float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) { return engineConfiguration->fanOnTemperature; case LE_METHOD_CRANKING_RPM: return engineConfiguration->cranking.rpm; + case LE_METHOD_STARTUP_FUEL_PUMP_DURATION: + // todo: remove default value check and finish migration to startUpFuelPumpDuration param. + return (engineConfiguration->startUpFuelPumpDuration == 0) ? 4 : engineConfiguration->startUpFuelPumpDuration; + case LE_METHOD_IN_SHUTDOWN: + return engine->isInShutdownMode(); case LE_METHOD_VBATT: return getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE); default: @@ -301,6 +308,11 @@ static const char * action2String(le_action_e action) { return "fan_off"; case LE_METHOD_FAN: return "fan"; + case LE_METHOD_STARTUP_FUEL_PUMP_DURATION: + return "startup_fuel_pump_duration"; + case LE_METHOD_IN_SHUTDOWN: + return "in_shutdown"; + default: { // this is here to make compiler happy } diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 69766128b0..276b9ca1aa 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -273,6 +273,7 @@ static void periodicSlowCallback(Engine *engine) { engine->watchdog(); engine->updateSlowSensors(); + engine->checkShutdown(); #if (EFI_PROD_CODE && EFI_FSIO) || defined(__DOXYGEN__) runFsio(); diff --git a/firmware/controllers/system_fsio.h b/firmware/controllers/system_fsio.h index 24609452d9..84366f6400 100644 --- a/firmware/controllers/system_fsio.h +++ b/firmware/controllers/system_fsio.h @@ -1,6 +1,6 @@ // this https://en.wikipedia.org/wiki/Reverse_Polish_notation is generated automatically // from controllers/system_fsio.txt -// on 2017-06-14_11_10_39 +// on 2017-06-25_01_22_09 // // // in this file we define system FSIO expressions @@ -15,10 +15,9 @@ // Human-readable: (fan and (coolant > fan_off_setting)) | (coolant > fan_on_setting) #define FAN_CONTROL_LOGIC "fan coolant fan_off_setting > and coolant fan_on_setting > |" -// todo: start-up fuel pump priming time should probably be configurable? -// Human-readable: (time_since_boot < 4) | (rpm > 0) -#define FUEL_PUMP_LOGIC "time_since_boot 4 < rpm 0 > |" +// Human-readable: (time_since_boot < startup_fuel_pump_duration) | (rpm > 0) +#define FUEL_PUMP_LOGIC "time_since_boot startup_fuel_pump_duration < rpm 0 > |" // Human-readable: vbatt < 14.5 #define ALTERNATOR_LOGIC "vbatt 14.5 <" @@ -31,8 +30,8 @@ #define COMBINED_WARNING_LIGHT "rpm 2 fsio_setting > coolant 3 fsio_setting > vbatt 4 fsio_setting < | |" //needed by EFI_MAIN_RELAY_CONTROL -// Human-readable: (time_since_boot < 2) | (vbatt > 5) -#define MAIN_RELAY_LOGIC "time_since_boot 2 < vbatt 5 > |" +// Human-readable: (time_since_boot < 2) | (vbatt > 5) | in_shutdown +#define MAIN_RELAY_LOGIC "time_since_boot 2 < vbatt 5 > | in_shutdown |" // could be used for simple variable intake geometry setups or warning light or starter block // Human-readable: rpm > fsio_setting(1) diff --git a/firmware/controllers/system_fsio.txt b/firmware/controllers/system_fsio.txt index d35bc1c8e0..ad516c2f67 100644 --- a/firmware/controllers/system_fsio.txt +++ b/firmware/controllers/system_fsio.txt @@ -11,8 +11,7 @@ FAN_CONTROL_LOGIC=(fan and (coolant > fan_off_setting)) | (coolant > fan_on_setting) -# todo: start-up fuel pump priming time should probably be configurable? -FUEL_PUMP_LOGIC=(time_since_boot < 4) | (rpm > 0) +FUEL_PUMP_LOGIC=(time_since_boot < startup_fuel_pump_duration) | (rpm > 0) ALTERNATOR_LOGIC=vbatt < 14.5 @@ -22,7 +21,7 @@ AC_RELAY_LOGIC=ac_on_switch COMBINED_WARNING_LIGHT=(rpm > fsio_setting(2)) | ((coolant > fsio_setting(3)) | (vbatt < fsio_setting(4))) #needed by EFI_MAIN_RELAY_CONTROL -MAIN_RELAY_LOGIC=(time_since_boot < 2) | (vbatt > 5) +MAIN_RELAY_LOGIC=(time_since_boot < 2) | (vbatt > 5) | in_shutdown # could be used for simple variable intake geometry setups or warning light or starter block RPM_ABOVE_USER_SETTING_1=rpm > fsio_setting(1) diff --git a/java_console/models/src/com/rusefi/config/Fields.java b/java_console/models/src/com/rusefi/config/Fields.java index a39b59d4c1..0ab502a4d2 100644 --- a/java_console/models/src/com/rusefi/config/Fields.java +++ b/java_console/models/src/com/rusefi/config/Fields.java @@ -1,6 +1,6 @@ package com.rusefi.config; -// this file was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Thu Jun 22 09:24:53 MSK 2017 +// this file was generated automatically by ConfigDefinition.jar based on rusefi_config.txt Sun Jun 25 00:14:59 EEST 2017 public class Fields { public static final int LE_COMMAND_LENGTH = 200; public static final int BLOCKING_FACTOR = 400; @@ -802,7 +802,8 @@ public class Fields { public static final int throttlePedalUpVoltage_offset = 2012; public static final int throttlePedalWOTVoltage_offset = 2016; public static final int stepperDirectionPinMode_offset = 2020; - public static final int unusedetb_offset = 2024; + public static final int startUpFuelPumpDuration_offset = 2024; + public static final int unusedetb_offset = 2026; public static final int cltIdleRpmBins_offset = 2028; public static final int cltIdleRpm_offset = 2092; public static final int targetVBatt_offset = 2156; @@ -1591,7 +1592,8 @@ public class Fields { public static final Field THROTTLEPEDALUPVOLTAGE = Field.create("THROTTLEPEDALUPVOLTAGE", 2012, FieldType.FLOAT); public static final Field THROTTLEPEDALWOTVOLTAGE = Field.create("THROTTLEPEDALWOTVOLTAGE", 2016, FieldType.FLOAT); public static final Field STEPPERDIRECTIONPINMODE = Field.create("STEPPERDIRECTIONPINMODE", 2020, FieldType.INT, pin_output_mode_e); - public static final Field UNUSEDETB = Field.create("UNUSEDETB", 2024, FieldType.FLOAT); + public static final Field STARTUPFUELPUMPDURATION = Field.create("STARTUPFUELPUMPDURATION", 2024, FieldType.INT); + public static final Field UNUSEDETB = Field.create("UNUSEDETB", 2026, FieldType.INT); public static final Field TARGETVBATT = Field.create("TARGETVBATT", 2156, FieldType.FLOAT); public static final Field ALTERNATOROFFABOVETPS = Field.create("ALTERNATOROFFABOVETPS", 2160, FieldType.FLOAT); public static final Field TPSACCELLENGTH = Field.create("TPSACCELLENGTH", 2184, FieldType.INT); diff --git a/java_console/rusefi.xml b/java_console/rusefi.xml index bf344e36fb..c7733a4995 100644 --- a/java_console/rusefi.xml +++ b/java_console/rusefi.xml @@ -1,6 +1,6 @@ - +