From 23e20e431988e3df0ae7bae6edafc3a4ac961e04 Mon Sep 17 00:00:00 2001 From: Andrei Date: Tue, 13 Jun 2017 01:14:39 +0300 Subject: [PATCH] EFI_MAIN_RELAY_CONTROL draft --- firmware/config/stm32f4ems/efifeatures.h | 5 +++++ firmware/controllers/core/fsio_impl.cpp | 14 ++++++++++++++ firmware/controllers/system_fsio.h | 7 ++++++- firmware/controllers/system_fsio.txt | 3 +++ simulator/simulator/efifeatures.h | 1 + 5 files changed, 29 insertions(+), 1 deletion(-) diff --git a/firmware/config/stm32f4ems/efifeatures.h b/firmware/config/stm32f4ems/efifeatures.h index 939986ae33..05f8a65421 100644 --- a/firmware/config/stm32f4ems/efifeatures.h +++ b/firmware/config/stm32f4ems/efifeatures.h @@ -124,6 +124,11 @@ #define EFI_IDLE_CONTROL TRUE +/** + * Control the main power relay based on measured ignition voltage (Vbatt) + */ +#define EFI_MAIN_RELAY_CONTROL FALSE + #define EFI_PWM TRUE #define EFI_VEHICLE_SPEED TRUE diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp index 6e79f9e31e..cb8cfcbe85 100644 --- a/firmware/controllers/core/fsio_impl.cpp +++ b/firmware/controllers/core/fsio_impl.cpp @@ -68,6 +68,10 @@ static LEElement * fuelPumpLogic; static LEElement * radiatorFanLogic; static LEElement * alternatorLogic; +#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__) +static LEElement * mainRelayLogic; +#endif /* EFI_MAIN_RELAY_CONTROL */ + EXTERN_ENGINE ; @@ -345,11 +349,16 @@ void runFsio(void) { } #endif /* EFI_FUEL_PUMP */ +#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__) + if (boardConfiguration->mainRelayPin != GPIO_UNASSIGNED) + setPinState("main_relay", &enginePins.mainRelay, mainRelayLogic); +#else /* EFI_MAIN_RELAY_CONTROL */ /** * main relay is always on if ECU is on, that's a good enough initial implementation */ if (boardConfiguration->mainRelayPin != GPIO_UNASSIGNED) enginePins.mainRelay.setValue(true); +#endif /* EFI_MAIN_RELAY_CONTROL */ enginePins.o2heater.setValue(engine->rpmCalculator.isRunning()); @@ -498,6 +507,11 @@ void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) { radiatorFanLogic = sysPool.parseExpression(FAN_CONTROL_LOGIC); alternatorLogic = sysPool.parseExpression(ALTERNATOR_LOGIC); + +#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__) + if (boardConfiguration->mainRelayPin != GPIO_UNASSIGNED) + mainRelayLogic = sysPool.parseExpression(MAIN_RELAY_LOGIC); +#endif /* EFI_MAIN_RELAY_CONTROL */ #if EFI_PROD_CODE || defined(__DOXYGEN__) for (int i = 0; i < LE_COMMAND_COUNT; i++) { diff --git a/firmware/controllers/system_fsio.h b/firmware/controllers/system_fsio.h index 2d5c6cb4ec..3d94a46062 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-04-25_15_33_33 +// on 2017-06-12_17_45_41 // // // in this file we define system FSIO expressions @@ -23,6 +23,11 @@ // Human-readable: ac_on_switch #define AC_RELAY_LOGIC "ac_on_switch" +// Combined RPM, CLT and VBATT warning light // Human-readable: (rpm > fsio_setting(2)) | ((coolant > fsio_setting(3)) | (vbatt < fsio_setting(4))) #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 > |" diff --git a/firmware/controllers/system_fsio.txt b/firmware/controllers/system_fsio.txt index 1a27f5895e..aff91693f2 100644 --- a/firmware/controllers/system_fsio.txt +++ b/firmware/controllers/system_fsio.txt @@ -18,3 +18,6 @@ AC_RELAY_LOGIC=ac_on_switch # Combined RPM, CLT and VBATT warning light 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) diff --git a/simulator/simulator/efifeatures.h b/simulator/simulator/efifeatures.h index 22b9cb4520..52824e4166 100644 --- a/simulator/simulator/efifeatures.h +++ b/simulator/simulator/efifeatures.h @@ -54,6 +54,7 @@ #define EFI_ENGINE_CONTROL TRUE #define EFI_IDLE_CONTROL FALSE +#define EFI_MAIN_RELAY_CONTROL FALSE #define EFI_HIP_9011 FALSE #define EFI_ELECTRONIC_THROTTLE_BODY FALSE #define EFI_AUX_PID FALSE