From 0dff692a2d65f710b7a83fd35b446a9e0cc460b5 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sat, 27 Dec 2014 15:03:38 -0600 Subject: [PATCH] auto-sync --- firmware/config/engines/dodge_neon.cpp | 5 +- firmware/config/engines/mazda_miata.cpp | 4 +- firmware/config/engines/mitsubishi.cpp | 2 +- .../controllers/algo/engine_configuration.cpp | 13 +- firmware/controllers/core/core.mk | 4 +- firmware/controllers/core/fl_stack.h | 2 + .../{logic_expression.cpp => fsio_core.cpp} | 69 +--- .../core/{logic_expression.h => fsio_core.h} | 4 +- firmware/controllers/core/fsio_impl.cpp | 340 ++++++++++++++++++ .../core/{le_functions.h => fsio_impl.h} | 9 +- firmware/controllers/core/le_functions.cpp | 75 ---- firmware/controllers/engine_controller.cpp | 214 +---------- firmware/rusefi.cpp | 2 +- unit_tests/test_logic_expression.cpp | 4 +- 14 files changed, 374 insertions(+), 373 deletions(-) rename firmware/controllers/core/{logic_expression.cpp => fsio_core.cpp} (81%) rename firmware/controllers/core/{logic_expression.h => fsio_core.h} (95%) create mode 100644 firmware/controllers/core/fsio_impl.cpp rename firmware/controllers/core/{le_functions.h => fsio_impl.h} (82%) delete mode 100644 firmware/controllers/core/le_functions.cpp diff --git a/firmware/config/engines/dodge_neon.cpp b/firmware/config/engines/dodge_neon.cpp index 86837c542a..70d8b70369 100644 --- a/firmware/config/engines/dodge_neon.cpp +++ b/firmware/config/engines/dodge_neon.cpp @@ -20,7 +20,7 @@ #include "engine_configuration.h" #include "thermistors.h" #include "engine_math.h" -#include "le_functions.h" +#include "fsio_impl.h" #if EFI_PROD_CODE #include "HIP9011.h" #endif @@ -357,7 +357,8 @@ void setDodgeNeonNGCEngineConfiguration(engine_configuration_s *engineConfigurat /** * set_fsio_setting 0 0.11 */ -// todo setFsio(engineConfiguration, 0, GPIOE_5, ""); + engineConfiguration->bc.fsio_setting[0] = 0.2; + setFsioExt(engineConfiguration, 0, GPIOE_5, "0 fsio_setting", 400); // engineConfiguration->isCanEnabled = true; boardConfiguration->canTxPin = GPIOB_6; diff --git a/firmware/config/engines/mazda_miata.cpp b/firmware/config/engines/mazda_miata.cpp index dd8a69d5d8..43b2790978 100644 --- a/firmware/config/engines/mazda_miata.cpp +++ b/firmware/config/engines/mazda_miata.cpp @@ -12,13 +12,11 @@ * @author Andrey Belomutskiy, (c) 2012-2014 */ +#include "fsio_impl.h" #include "mazda_miata.h" #include "engine_math.h" #include "advance_map.h" #include "allsensors.h" -#include "le_functions.h" - -// setFrankenso_01_LCD #include "honda_accord.h" static const fuel_table_t miata_maf_fuel_table = { {/*0 engineLoad=1.2*//*0 800.0*/1.53, /*1 1213.0*/0.92, /*2 1626.0*/ diff --git a/firmware/config/engines/mitsubishi.cpp b/firmware/config/engines/mitsubishi.cpp index e2c15a421d..3a279c2837 100644 --- a/firmware/config/engines/mitsubishi.cpp +++ b/firmware/config/engines/mitsubishi.cpp @@ -9,9 +9,9 @@ * @author Andrey Belomutskiy, (c) 2012-2014 */ +#include "fsio_impl.h" #include "mitsubishi.h" #include "allsensors.h" -#include "le_functions.h" void setMitsubishiConfiguration(engine_configuration_s *engineConfiguration, board_configuration_s *boardConfiguration) { engineConfiguration->engineType = MITSU_4G93; diff --git a/firmware/controllers/algo/engine_configuration.cpp b/firmware/controllers/algo/engine_configuration.cpp index c666e15162..f3aea4b747 100644 --- a/firmware/controllers/algo/engine_configuration.cpp +++ b/firmware/controllers/algo/engine_configuration.cpp @@ -22,17 +22,12 @@ #include "main.h" #include "engine_configuration.h" +#include "fsio_impl.h" #include "allsensors.h" #include "interpolation.h" #include "trigger_decoder.h" #include "engine_math.h" #include "speed_density.h" -#include "logic_expression.h" - -#if EFI_TUNER_STUDIO -#include "tunerstudio.h" -#endif - #include "audi_aan.h" #include "bmw_e34.h" #include "dodge_neon.h" @@ -54,6 +49,10 @@ #include "subaru.h" #include "test_engine.h" +#if EFI_TUNER_STUDIO +#include "tunerstudio.h" +#endif + //#define TS_DEFAULT_SPEED 115200 #define TS_DEFAULT_SPEED 38400 @@ -683,7 +682,7 @@ void applyNonPersistentConfiguration(Logging * logger, Engine *engine) { return; } engine->engineCycleEventCount = engine->triggerShape.getLength(); - parseUserFsio(PASS_ENGINE_PARAMETER_F); + applyFsioConfiguration(PASS_ENGINE_PARAMETER_F); } #if EFI_ENGINE_CONTROL || defined(__DOXYGEN__) diff --git a/firmware/controllers/core/core.mk b/firmware/controllers/core/core.mk index 3186186cb5..0341a42829 100644 --- a/firmware/controllers/core/core.mk +++ b/firmware/controllers/core/core.mk @@ -3,6 +3,6 @@ CONTROLLERS_CORE_SRC = $(PROJECT_DIR)/controllers/core/avg_values.c CONTROLLERS_CORE_SRC_CPP = $(PROJECT_DIR)/controllers/core/EfiWave.cpp \ $(PROJECT_DIR)/controllers/core/table_helper.cpp \ - $(PROJECT_DIR)/controllers/core/logic_expression.cpp \ + $(PROJECT_DIR)/controllers/core/fsio_core.cpp \ $(PROJECT_DIR)/controllers/core/interpolation.cpp \ - $(PROJECT_DIR)/controllers/core/le_functions.cpp + $(PROJECT_DIR)/controllers/core/fsio_impl.cpp diff --git a/firmware/controllers/core/fl_stack.h b/firmware/controllers/core/fl_stack.h index 7331b3a557..7a10c68484 100644 --- a/firmware/controllers/core/fl_stack.h +++ b/firmware/controllers/core/fl_stack.h @@ -9,6 +9,8 @@ #ifndef FL_STACK_H_ #define FL_STACK_H_ +#include "error_handling.h" + template class FLStack { public: diff --git a/firmware/controllers/core/logic_expression.cpp b/firmware/controllers/core/fsio_core.cpp similarity index 81% rename from firmware/controllers/core/logic_expression.cpp rename to firmware/controllers/core/fsio_core.cpp index 27c31781d8..997960bce6 100644 --- a/firmware/controllers/core/logic_expression.cpp +++ b/firmware/controllers/core/fsio_core.cpp @@ -1,6 +1,6 @@ /** - * @file logic_expression.cpp - * @brief Logical expressions handling logic + * @file fsio_core.cpp + * @brief core FSUI handling logic * * Here we parse and evaluate logical expressions in * http://en.wikipedia.org/wiki/Reverse_Polish_notation @@ -17,8 +17,8 @@ #if EFI_FSIO || defined(__DOXYGEN__) -#include "logic_expression.h" -#include "le_functions.h" +#include "fsio_core.h" +#include "fsio_impl.h" LENameOrdinalPair * LE_FIRST = NULL; @@ -47,26 +47,6 @@ static LENameOrdinalPair leMax(LE_METHOD_MAX, "max"); static LENameOrdinalPair leMin(LE_METHOD_MIN, "min"); static LENameOrdinalPair leIf(LE_METHOD_IF, "if"); -#define LE_EVAL_POOL_SIZE 32 - -#if EFI_PROD_CODE || EFI_SIMULATOR -static Logging logger; -#endif - -static LECalculator evalCalc; -static LEElement evalPoolElements[LE_EVAL_POOL_SIZE]; -static LEElementPool evalPool(evalPoolElements, LE_EVAL_POOL_SIZE); - -#define SYS_ELEMENT_POOL_SIZE 128 -#define UD_ELEMENT_POOL_SIZE 128 - -static LEElement sysElements[SYS_ELEMENT_POOL_SIZE]; -LEElementPool sysPool(sysElements, SYS_ELEMENT_POOL_SIZE); - -static LEElement userElements[UD_ELEMENT_POOL_SIZE]; -LEElementPool userPool(userElements, UD_ELEMENT_POOL_SIZE); -LEElement * fsioLogics[LE_COMMAND_COUNT] CCM_OPTIONAL; - LENameOrdinalPair::LENameOrdinalPair(le_action_e action, const char *name) { this->action = action; this->name = name; @@ -385,45 +365,4 @@ LEElement *LEElementPool::parseExpression(const char * line) { return first; } -EXTERN_ENGINE; - -void parseUserFsio(DECLARE_ENGINE_PARAMETER_F) { - board_configuration_s * boardConfiguration = &engineConfiguration->bc; - for (int i = 0; i < LE_COMMAND_COUNT; i++) { - brain_pin_e brainPin = boardConfiguration->fsioPins[i]; - - if (brainPin != GPIO_UNASSIGNED) { - const char *formula = boardConfiguration->le_formulas[i]; - LEElement *logic = userPool.parseExpression(formula); - if (logic == NULL) { - warning(OBD_PCM_Processor_Fault, "parsing [%s]", formula); - } - - fsioLogics[i] = logic; - } - } -} - -#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) - -static void eval(char *line, Engine *engine) { - line = unquote(line); - scheduleMsg(&logger, "Parsing [%s]", line); - evalPool.reset(); - LEElement * e = evalPool.parseExpression(line); - if (e == NULL) { - scheduleMsg(&logger, "parsing failed"); - } else { - float result = evalCalc.getValue2(e, engine); - scheduleMsg(&logger, "Eval result: %f", result); - } -} - -void initEval(Engine *engine) { - initLogging(&logger, "le"); - addConsoleActionSP("eval", (VoidCharPtrVoidPtr) eval, engine); -} - -#endif - #endif /* EFI_FSIO */ diff --git a/firmware/controllers/core/logic_expression.h b/firmware/controllers/core/fsio_core.h similarity index 95% rename from firmware/controllers/core/logic_expression.h rename to firmware/controllers/core/fsio_core.h index 72568ad769..1c75625d2b 100644 --- a/firmware/controllers/core/logic_expression.h +++ b/firmware/controllers/core/fsio_core.h @@ -1,5 +1,5 @@ /** - * @file logic_expression.h + * @file fsio_core.h * * @date Oct 3, 2014 * @author Andrey Belomutskiy, (c) 2012-2014 @@ -112,7 +112,5 @@ public: const char *getNextToken(const char *line, char *buffer); bool isNumeric(const char* line); le_action_e parseAction(const char * line); -void initEval(Engine *engine); -void parseUserFsio(DECLARE_ENGINE_PARAMETER_F); #endif /* LOGIC_EXPRESSION_H_ */ diff --git a/firmware/controllers/core/fsio_impl.cpp b/firmware/controllers/core/fsio_impl.cpp new file mode 100644 index 0000000000..46dc81b9be --- /dev/null +++ b/firmware/controllers/core/fsio_impl.cpp @@ -0,0 +1,340 @@ +/** + * @file fsio_impl.cpp + * @brief FSIO as it's used for GPIO + * + * @date Oct 5, 2014 + * @author Andrey Belomutskiy, (c) 2012-2014 + */ + +#include "main.h" + +#if EFI_FSIO || defined(__DOXYGEN__) + +#include "fsio_impl.h" +#include "allsensors.h" +#include "rpm_calculator.h" +#include "efiGpio.h" +#include "pin_repository.h" +#include "pwm_generator.h" +// todo: that's about bench test mode, wrong header for sure! +#include "injector_central.h" + +/** + * Here we define all rusEfi-specific methods + */ +static LENameOrdinalPair leRpm(LE_METHOD_RPM, "rpm"); +static LENameOrdinalPair leTps(LE_METHOD_TPS, "tps"); +static LENameOrdinalPair leMaf(LE_METHOD_MAF, "maf"); +static LENameOrdinalPair leVBatt(LE_METHOD_VBATT, "vbatt"); +static LENameOrdinalPair leFan(LE_METHOD_FAN, "fan"); +static LENameOrdinalPair leCoolant(LE_METHOD_COOLANT, "coolant"); +static LENameOrdinalPair leAcToggle(LE_METHOD_AC_TOGGLE, "ac_on_switch"); +static LENameOrdinalPair leFanOnSetting(LE_METHOD_FAN_ON_SETTING, "fan_on_setting"); +static LENameOrdinalPair leFanOffSetting(LE_METHOD_FAN_OFF_SETTING, "fan_off_setting"); +static LENameOrdinalPair leTimeSinceBoot(LE_METHOD_TIME_SINCE_BOOT, "time_since_boot"); +static LENameOrdinalPair leFsioSsetting(LE_METHOD_FSIO_SETTING, "fsio_setting"); + +#define LE_EVAL_POOL_SIZE 32 + +#if EFI_PROD_CODE || EFI_SIMULATOR +static Logging logger; +#endif + +static LECalculator evalCalc; +static LEElement evalPoolElements[LE_EVAL_POOL_SIZE]; +static LEElementPool evalPool(evalPoolElements, LE_EVAL_POOL_SIZE); + +#define SYS_ELEMENT_POOL_SIZE 128 +#define UD_ELEMENT_POOL_SIZE 128 + +static LEElement sysElements[SYS_ELEMENT_POOL_SIZE]; +LEElementPool sysPool(sysElements, SYS_ELEMENT_POOL_SIZE); + +static LEElement userElements[UD_ELEMENT_POOL_SIZE]; +LEElementPool userPool(userElements, UD_ELEMENT_POOL_SIZE); +static LEElement * fsioLogics[LE_COMMAND_COUNT] CCM_OPTIONAL; + +static LEElement * acRelayLogic; +static LEElement * fuelPumpLogic; +static LEElement * radiatorFanLogic; +static LEElement * alternatorLogic; + +void setFsioExt(engine_configuration_s *engineConfiguration, int index, brain_pin_e pin, const char * exp, int freq) { + board_configuration_s *boardConfiguration = &engineConfiguration->bc; + + boardConfiguration->fsioPins[index] = pin; + strcpy(boardConfiguration->le_formulas[index], exp); + boardConfiguration->fsioFrequency[index] = freq; +} + +void setFsio(engine_configuration_s *engineConfiguration, int index, brain_pin_e pin, const char * exp) { + setFsioExt(engineConfiguration, index, pin, exp, 0); +} + +EXTERN_ENGINE; + +void applyFsioConfiguration(DECLARE_ENGINE_PARAMETER_F) { + board_configuration_s * boardConfiguration = &engineConfiguration->bc; + for (int i = 0; i < LE_COMMAND_COUNT; i++) { + brain_pin_e brainPin = boardConfiguration->fsioPins[i]; + + if (brainPin != GPIO_UNASSIGNED) { + const char *formula = boardConfiguration->le_formulas[i]; + LEElement *logic = userPool.parseExpression(formula); + if (logic == NULL) { + warning(OBD_PCM_Processor_Fault, "parsing [%s]", formula); + } + + fsioLogics[i] = logic; + } + } +} + +#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__) + +static SimplePwm fsioPwm[LE_COMMAND_COUNT] CCM_OPTIONAL; + +static LECalculator calc; +extern LEElement * fsioLogics[LE_COMMAND_COUNT]; + +static void handleFsio(Engine *engine, int index) { + if (boardConfiguration->fsioPins[index] == GPIO_UNASSIGNED) + return; + + bool_t isPwmMode = boardConfiguration->fsioFrequency[index] != 0; + + io_pin_e pin = (io_pin_e) ((int) GPIO_0 + index); + + float fvalue = calc.getValue2(fsioLogics[index], engine); + engine->engineConfiguration2->fsioLastValue[index] = fvalue; + + if (isPwmMode) { + fsioPwm[index].setSimplePwmDutyCycle(fvalue); + } else { + int value = (int) fvalue; + if (value != getOutputPinValue(pin)) { + // scheduleMsg(&logger, "setting %s %s", getIo_pin_e(pin), boolToString(value)); + setOutputPinValue(pin, value); + } + } +} + +static void setPinState(io_pin_e ioPin, LEElement *element, Engine *engine) { + if (element == NULL) { + warning(OBD_PCM_Processor_Fault, "invalid expression for %s", getIo_pin_e(ioPin)); + } else { + int value = calc.getValue2(element, engine); + if (value != getOutputPinValue(ioPin)) { + if (isRunningBenchTest()) + return; // let's not mess with bench testing + scheduleMsg(&logger, "setting %s %s", getIo_pin_e(ioPin), boolToString(value)); + setOutputPinValue(ioPin, value); + } + } +} + +static void showFsio(const char *msg, LEElement *element) { + if (msg != NULL) + scheduleMsg(&logger, "%s:", msg); + while (element != NULL) { + scheduleMsg(&logger, "action %d: fValue=%f iValue=%d", element->action, element->fValue, element->iValue); + element = element->next; + } + scheduleMsg(&logger, ""); +} + +static void showFsioInfo(void) { + scheduleMsg(&logger, "sys used %d/user used %d", sysPool.getSize(), userPool.getSize()); + showFsio("a/c", acRelayLogic); + showFsio("fuel", fuelPumpLogic); + showFsio("fan", radiatorFanLogic); + showFsio("alt", alternatorLogic); + + for (int i = 0; i < LE_COMMAND_COUNT; i++) { + char * exp = boardConfiguration->le_formulas[i]; + if (exp[0] != 0) { + /** + * in case of FSIO user interface indexes are starting with 0, the argument for that + * is the fact that the target audience is more software developers + */ + scheduleMsg(&logger, "FSIO #%d [%s] at %s@%dHz value=%f", i, exp, + hwPortname(boardConfiguration->fsioPins[i]), boardConfiguration->fsioFrequency[i], + engineConfiguration2->fsioLastValue[i]); +// scheduleMsg(&logger, "user-defined #%d value=%f", i, engine->engineConfiguration2->fsioLastValue[i]); + showFsio(NULL, fsioLogics[i]); + } + } + for (int i = 0; i < LE_COMMAND_COUNT; i++) { + float v = boardConfiguration->fsio_setting[i]; + if (!cisnan(v)) { + scheduleMsg(&logger, "user property #%d: %f", i + 1, v); + } + } +} + +/** + * set_fsio_setting 0 0.11 + */ +static void setFsioSetting(float indexF, float value) { + int index = indexF; + if (index < 0 || index >= LE_COMMAND_COUNT) { + scheduleMsg(&logger, "invalid index %d", index); + return; + } + engineConfiguration->bc.fsio_setting[index] = value; + showFsioInfo(); +} + +static void setFsioFrequency(int index, int frequency) { + index--; + if (index < 0 || index >= LE_COMMAND_COUNT) { + scheduleMsg(&logger, "invalid index %d", index); + return; + } + boardConfiguration->fsioFrequency[index] = frequency; + scheduleMsg(&logger, "Setting FSIO frequency %d on #%d", frequency, index + 1); +} + +static void setFsioPin(const char *indexStr, const char *pinName) { + int index = atoi(indexStr) - 1; + if (index < 0 || index >= LE_COMMAND_COUNT) { + scheduleMsg(&logger, "invalid index %d", index); + return; + } + brain_pin_e pin = parseBrainPin(pinName); + // todo: extract method - code duplication with other 'set_xxx_pin' methods? + if (pin == GPIO_INVALID) { + scheduleMsg(&logger, "invalid pin name [%s]", pinName); + return; + } + boardConfiguration->fsioPins[index] = pin; + scheduleMsg(&logger, "FSIO pin #%d [%s]", (index + 1), hwPortname(pin)); +} + +static void setUserOutput(const char *indexStr, const char *quotedLine, Engine *engine) { + int index = atoi(indexStr) - 1; + if (index < 0 || index >= LE_COMMAND_COUNT) { + scheduleMsg(&logger, "invalid index %d", index); + return; + } + char * l = unquote((char*) quotedLine); + if (strlen(l) > LE_COMMAND_LENGTH - 1) { + scheduleMsg(&logger, "Too long %d", strlen(l)); + return; + } + + scheduleMsg(&logger, "setting user out #%d to [%s]", index + 1, l); + strcpy(engine->engineConfiguration->bc.le_formulas[index], l); + // this would apply the changes + applyFsioConfiguration(PASS_ENGINE_PARAMETER_F); + showFsioInfo(); +} + +static void eval(char *line, Engine *engine) { + line = unquote(line); + scheduleMsg(&logger, "Parsing [%s]", line); + evalPool.reset(); + LEElement * e = evalPool.parseExpression(line); + if (e == NULL) { + scheduleMsg(&logger, "parsing failed"); + } else { + float result = evalCalc.getValue2(e, engine); + scheduleMsg(&logger, "Eval result: %f", result); + } +} + +float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action) { + efiAssert(engine!=NULL, "getLEValue", NAN); + switch (action) { + case LE_METHOD_FAN: + return getOutputPinValue(FAN_RELAY); + case LE_METHOD_AC_TOGGLE: + return getAcToggle(engine); + case LE_METHOD_COOLANT: + return getCoolantTemperature(engine); + case LE_METHOD_INTAKE_AIR: + return getIntakeAirTemperature(engine); + case LE_METHOD_RPM: + return engine->rpmCalculator.rpm(); + case LE_METHOD_TIME_SINCE_BOOT: + return getTimeNowSeconds(); + case LE_METHOD_FAN_OFF_SETTING: + return engine->engineConfiguration->fanOffTemperature; + case LE_METHOD_FAN_ON_SETTING: + return engine->engineConfiguration->fanOnTemperature; + case LE_METHOD_VBATT: + return getVBatt(engine->engineConfiguration); + default: + firmwareError("FSIO unexpected %d", action); + return NAN; + } +} + +void runFsio(void) { + for (int i = 0; i < LE_COMMAND_COUNT; i++) { + handleFsio(engine, i); + } + +#if EFI_FUEL_PUMP + if (boardConfiguration->fuelPumpPin != GPIO_UNASSIGNED && engineConfiguration->isFuelPumpEnabled) { + setPinState(FUEL_PUMP_RELAY, fuelPumpLogic, engine); + } +#endif + + if (boardConfiguration->acRelayPin != GPIO_UNASSIGNED) { + setPinState(AC_RELAY, acRelayLogic, engine); + } + + if (boardConfiguration->alternatorControlPin != GPIO_UNASSIGNED) { + setPinState(ALTERNATOR_SWITCH, alternatorLogic, engine); + } + + if (boardConfiguration->fanPin != GPIO_UNASSIGNED) { +// setPinState(FAN_RELAY, radiatorFanLogic, engine); + } + +} + +static pin_output_mode_e defa = OM_DEFAULT; + +void initFsioImpl(Engine *engine) { + initLogging(&logger, "le"); + +#if EFI_FUEL_PUMP + fuelPumpLogic = sysPool.parseExpression(FUEL_PUMP_LOGIC); +#endif + + acRelayLogic = sysPool.parseExpression(AC_RELAY_LOGIC); + radiatorFanLogic = sysPool.parseExpression(FAN_CONTROL_LOGIC); + + alternatorLogic = sysPool.parseExpression(ALTERNATOR_LOGIC); + + for (int i = 0; i < LE_COMMAND_COUNT; i++) { + brain_pin_e brainPin = boardConfiguration->fsioPins[i]; + + if (brainPin != GPIO_UNASSIGNED) { + //mySetPadMode2("user-defined", boardConfiguration->gpioPins[i], PAL_STM32_MODE_OUTPUT); + + io_pin_e pin = (io_pin_e) ((int) GPIO_0 + i); + + int frequency = boardConfiguration->fsioFrequency[i]; + if (frequency == 0) { + outputPinRegisterExt2(getPinName(pin), pin, boardConfiguration->fsioPins[i], &defa); + } else { + startSimplePwmExt(&fsioPwm[i], "FSIO", brainPin, pin, frequency, 0.5f, applyPinState); + } + } + } + + addConsoleActionSSP("set_fsio", (VoidCharPtrCharPtrVoidPtr) setUserOutput, engine); + addConsoleActionSS("set_fsio_pin", (VoidCharPtrCharPtr) setFsioPin); + addConsoleActionII("set_fsio_frequency", (VoidIntInt) setFsioFrequency); + addConsoleActionFF("set_fsio_setting", setFsioSetting); + addConsoleAction("fsioinfo", showFsioInfo); + + addConsoleActionSP("eval", (VoidCharPtrVoidPtr) eval, engine); +} + +#endif + +#endif /* EFI_FSIO */ diff --git a/firmware/controllers/core/le_functions.h b/firmware/controllers/core/fsio_impl.h similarity index 82% rename from firmware/controllers/core/le_functions.h rename to firmware/controllers/core/fsio_impl.h index 42f410c1bb..d727118eab 100644 --- a/firmware/controllers/core/le_functions.h +++ b/firmware/controllers/core/fsio_impl.h @@ -1,5 +1,6 @@ /** - * @file le_functions.h + * @file fsio_impl.h + * @brief FSIO as it's used for GPIO * * @date Oct 5, 2014 * @author Andrey Belomutskiy, (c) 2012-2014 @@ -8,8 +9,8 @@ #ifndef LE_FUNCTIONS_H_ #define LE_FUNCTIONS_H_ +#include "fsio_core.h" #include "engine.h" -#include "logic_expression.h" /** * In human language that's @@ -32,4 +33,8 @@ float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action); void setFsio(engine_configuration_s *engineConfiguration, int index, brain_pin_e pin, const char * exp); void setFsioExt(engine_configuration_s *engineConfiguration, int index, brain_pin_e pin, const char * exp, int freq); +void initFsioImpl(Engine *engine); +void runFsio(void); +void applyFsioConfiguration(DECLARE_ENGINE_PARAMETER_F); + #endif /* LE_FUNCTIONS_H_ */ diff --git a/firmware/controllers/core/le_functions.cpp b/firmware/controllers/core/le_functions.cpp deleted file mode 100644 index 3bcabf9aee..0000000000 --- a/firmware/controllers/core/le_functions.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/** - * @file le_functions.cpp - * - * @date Oct 5, 2014 - * @author Andrey Belomutskiy, (c) 2012-2014 - */ - -#include "main.h" - -#if EFI_FSIO || defined(__DOXYGEN__) - -#include "le_functions.h" -#include "allsensors.h" -#include "rpm_calculator.h" -#include "efiGpio.h" - -//extern LENameOrdinalPair * LE_FIRST; - -/** - * Here we define all rusEfi-specific methods - */ -static LENameOrdinalPair leRpm(LE_METHOD_RPM, "rpm"); -static LENameOrdinalPair leTps(LE_METHOD_TPS, "tps"); -static LENameOrdinalPair leMaf(LE_METHOD_MAF, "maf"); -static LENameOrdinalPair leVBatt(LE_METHOD_VBATT, "vbatt"); -static LENameOrdinalPair leFan(LE_METHOD_FAN, "fan"); -static LENameOrdinalPair leCoolant(LE_METHOD_COOLANT, "coolant"); -static LENameOrdinalPair leAcToggle(LE_METHOD_AC_TOGGLE, "ac_on_switch"); -static LENameOrdinalPair leFanOnSetting(LE_METHOD_FAN_ON_SETTING, "fan_on_setting"); -static LENameOrdinalPair leFanOffSetting(LE_METHOD_FAN_OFF_SETTING, "fan_off_setting"); -static LENameOrdinalPair leTimeSinceBoot(LE_METHOD_TIME_SINCE_BOOT, "time_since_boot"); -static LENameOrdinalPair leFsioSsetting(LE_METHOD_FSIO_SETTING, "fsio_setting"); - -#if EFI_PROD_CODE || EFI_SIMULATOR -float getLEValue(Engine *engine, calc_stack_t *s, le_action_e action) { - efiAssert(engine!=NULL, "getLEValue", NAN); - switch (action) { - case LE_METHOD_FAN: - return getOutputPinValue(FAN_RELAY); - case LE_METHOD_AC_TOGGLE: - return getAcToggle(engine); - case LE_METHOD_COOLANT: - return getCoolantTemperature(engine); - case LE_METHOD_INTAKE_AIR: - return getIntakeAirTemperature(engine); - case LE_METHOD_RPM: - return engine->rpmCalculator.rpm(); - case LE_METHOD_TIME_SINCE_BOOT: - return getTimeNowSeconds(); - case LE_METHOD_FAN_OFF_SETTING: - return engine->engineConfiguration->fanOffTemperature; - case LE_METHOD_FAN_ON_SETTING: - return engine->engineConfiguration->fanOnTemperature; - case LE_METHOD_VBATT: - return getVBatt(engine->engineConfiguration); - default: - firmwareError("FSIO unexpected %d", action); - return NAN; - } -} -#endif - -void setFsioExt(engine_configuration_s *engineConfiguration, int index, brain_pin_e pin, const char * exp, int freq) { - board_configuration_s *boardConfiguration = &engineConfiguration->bc; - - boardConfiguration->fsioPins[index] = pin; - strcpy(boardConfiguration->le_formulas[index], exp); - boardConfiguration->fsioFrequency[index] = freq; -} - -void setFsio(engine_configuration_s *engineConfiguration, int index, brain_pin_e pin, const char * exp) { - setFsioExt(engineConfiguration, index, pin, exp, 0); -} - -#endif /* EFI_FSIO */ diff --git a/firmware/controllers/engine_controller.cpp b/firmware/controllers/engine_controller.cpp index 4289b8188b..bf87143e57 100644 --- a/firmware/controllers/engine_controller.cpp +++ b/firmware/controllers/engine_controller.cpp @@ -22,8 +22,11 @@ */ #include "main.h" +#include "engine_configuration.h" #include "trigger_central.h" #include "engine_controller.h" +#include "fsio_core.h" +#include "fsio_impl.h" #include "idle_thread.h" #include "rpm_calculator.h" #include "signal_executor.h" @@ -35,7 +38,6 @@ #include "injector_central.h" #include "ignition_central.h" #include "rfiutil.h" -#include "engine_configuration.h" #include "engine_math.h" #include "wave_analyzer.h" #include "allsensors.h" @@ -52,23 +54,13 @@ #include "ec2.h" #include "PwmTester.h" #include "engine.h" -#include "logic_expression.h" -#include "le_functions.h" #include "pin_repository.h" #include "pwm_generator.h" -static LEElement * acRelayLogic; -static LEElement * fuelPumpLogic; -static LEElement * radiatorFanLogic; -static LEElement * alternatorLogic; - extern OutputPin outputs[IO_PIN_COUNT]; extern pin_output_mode_e *pinDefaultState[IO_PIN_COUNT]; extern bool hasFirmwareErrorFlag; -extern LEElementPool sysPool; -extern LEElementPool userPool; - persistent_config_container_s persistentState CCM_OPTIONAL; /** @@ -194,144 +186,6 @@ static void cylinderCleanupControl(Engine *engine) { } } -#if EFI_FSIO -static SimplePwm fsioPwm[LE_COMMAND_COUNT] CCM_OPTIONAL; - -static LECalculator calc; -extern LEElement * fsioLogics[LE_COMMAND_COUNT]; - -static void handleFsio(Engine *engine, int index) { - if (boardConfiguration->fsioPins[index] == GPIO_UNASSIGNED) - return; - - bool_t isPwmMode = boardConfiguration->fsioFrequency[index] != 0; - - io_pin_e pin = (io_pin_e) ((int) GPIO_0 + index); - - float fvalue = calc.getValue2(fsioLogics[index], engine); - engine->engineConfiguration2->fsioLastValue[index] = fvalue; - - if (isPwmMode) { - fsioPwm[index].setSimplePwmDutyCycle(fvalue); - } else { - int value = (int) fvalue; - if (value != getOutputPinValue(pin)) { - // scheduleMsg(&logger, "setting %s %s", getIo_pin_e(pin), boolToString(value)); - setOutputPinValue(pin, value); - } - } -} - -static void setPinState(io_pin_e ioPin, LEElement *element, Engine *engine) { - if (element == NULL) { - warning(OBD_PCM_Processor_Fault, "invalid expression for %s", getIo_pin_e(ioPin)); - } else { - int value = calc.getValue2(element, engine); - if (value != getOutputPinValue(ioPin)) { - if (isRunningBenchTest()) - return; // let's not mess with bench testing - scheduleMsg(&logger, "setting %s %s", getIo_pin_e(ioPin), boolToString(value)); - setOutputPinValue(ioPin, value); - } - } -} - -static void showFsio(const char *msg, LEElement *element) { - if (msg != NULL) - scheduleMsg(&logger, "%s:", msg); - while (element != NULL) { - scheduleMsg(&logger, "action %d: fValue=%f iValue=%d", element->action, element->fValue, element->iValue); - element = element->next; - } - scheduleMsg(&logger, ""); -} - -static void showFsioInfo(void) { - scheduleMsg(&logger, "sys used %d/user used %d", sysPool.getSize(), userPool.getSize()); - showFsio("a/c", acRelayLogic); - showFsio("fuel", fuelPumpLogic); - showFsio("fan", radiatorFanLogic); - showFsio("alt", alternatorLogic); - - for (int i = 0; i < LE_COMMAND_COUNT; i++) { - char * exp = boardConfiguration->le_formulas[i]; - if (exp[0] != 0) { - /** - * in case of FSIO user interface indexes are starting with 0, the argument for that - * is the fact that the target audience is more software developers - */ - scheduleMsg(&logger, "FSIO #%d [%s] at %s@%dHz value=%f", i, exp, - hwPortname(boardConfiguration->fsioPins[i]), boardConfiguration->fsioFrequency[i], - engineConfiguration2->fsioLastValue[i]); -// scheduleMsg(&logger, "user-defined #%d value=%f", i, engine->engineConfiguration2->fsioLastValue[i]); - showFsio(NULL, fsioLogics[i]); - } - } - for (int i = 0; i < LE_COMMAND_COUNT; i++) { - float v = boardConfiguration->fsio_setting[i]; - if (!cisnan(v)) { - scheduleMsg(&logger, "user property #%d: %f", i + 1, v); - } - } -} - -static void setFsioSetting(float indexF, float value) { - int index = indexF; - if (index < 0 || index >= LE_COMMAND_COUNT) { - scheduleMsg(&logger, "invalid index %d", index); - return; - } - engineConfiguration->bc.fsio_setting[index] = value; - showFsioInfo(); -} - -static void setFsioFrequency(int index, int frequency) { - index--; - if (index < 0 || index >= LE_COMMAND_COUNT) { - scheduleMsg(&logger, "invalid index %d", index); - return; - } - boardConfiguration->fsioFrequency[index] = frequency; - scheduleMsg(&logger, "Setting FSIO frequency %d on #%d", frequency, index + 1); -} - -static void setFsioPin(const char *indexStr, const char *pinName) { - int index = atoi(indexStr) - 1; - if (index < 0 || index >= LE_COMMAND_COUNT) { - scheduleMsg(&logger, "invalid index %d", index); - return; - } - brain_pin_e pin = parseBrainPin(pinName); - // todo: extract method - code duplication with other 'set_xxx_pin' methods? - if (pin == GPIO_INVALID) { - scheduleMsg(&logger, "invalid pin name [%s]", pinName); - return; - } - boardConfiguration->fsioPins[index] = pin; - scheduleMsg(&logger, "FSIO pin #%d [%s]", (index + 1), hwPortname(pin)); -} - -static void setUserOutput(const char *indexStr, const char *quotedLine, Engine *engine) { - int index = atoi(indexStr) - 1; - if (index < 0 || index >= LE_COMMAND_COUNT) { - scheduleMsg(&logger, "invalid index %d", index); - return; - } - char * l = unquote((char*) quotedLine); - if (strlen(l) > LE_COMMAND_LENGTH - 1) { - scheduleMsg(&logger, "Too long %d", strlen(l)); - return; - } - - scheduleMsg(&logger, "setting user out #%d to [%s]", index + 1, l); - strcpy(engine->engineConfiguration->bc.le_formulas[index], l); - // this would apply the changes - parseUserFsio(PASS_ENGINE_PARAMETER_F); - showFsioInfo(); -} - -#endif /* EFI_FSIO */ - static void onEvenyGeneralMilliseconds(Engine *engine) { /** * We need to push current value into the 64 bit counter often enough so that we do not miss an overflow @@ -348,30 +202,8 @@ static void onEvenyGeneralMilliseconds(Engine *engine) { engine->watchdog(); engine->updateSlowSensors(); -#if EFI_FSIO + runFsio(); - for (int i = 0; i < LE_COMMAND_COUNT; i++) { - handleFsio(engine, i); - } - -#if EFI_FUEL_PUMP - if (boardConfiguration->fuelPumpPin != GPIO_UNASSIGNED && engineConfiguration->isFuelPumpEnabled) { - setPinState(FUEL_PUMP_RELAY, fuelPumpLogic, engine); - } -#endif - - if (boardConfiguration->acRelayPin != GPIO_UNASSIGNED) { - setPinState(AC_RELAY, acRelayLogic, engine); - } - - if (boardConfiguration->alternatorControlPin != GPIO_UNASSIGNED) { - setPinState(ALTERNATOR_SWITCH, alternatorLogic, engine); - } - - if (boardConfiguration->fanPin != GPIO_UNASSIGNED) { -// setPinState(FAN_RELAY, radiatorFanLogic, engine); - } -#endif updateErrorCodes(); @@ -474,8 +306,6 @@ static void setFloat(const char *offsetStr, const char *valueStr) { scheduleMsg(&logger, "setting float @%d to %f", offset, value); } -static pin_output_mode_e d = OM_DEFAULT; - void initEngineContoller(Engine *engine) { if (hasFirmwareError()) { return; @@ -565,46 +395,12 @@ void initEngineContoller(Engine *engine) { } #endif -#if EFI_FUEL_PUMP - fuelPumpLogic = sysPool.parseExpression(FUEL_PUMP_LOGIC); -#endif - - acRelayLogic = sysPool.parseExpression(AC_RELAY_LOGIC); - radiatorFanLogic = sysPool.parseExpression(FAN_CONTROL_LOGIC); - - alternatorLogic = sysPool.parseExpression(ALTERNATOR_LOGIC); - addConsoleAction("analoginfo", printAnalogInfo); -#if EFI_FSIO - for (int i = 0; i < LE_COMMAND_COUNT; i++) { - brain_pin_e brainPin = boardConfiguration->fsioPins[i]; - - if (brainPin != GPIO_UNASSIGNED) { - //mySetPadMode2("user-defined", boardConfiguration->gpioPins[i], PAL_STM32_MODE_OUTPUT); - - io_pin_e pin = (io_pin_e) ((int) GPIO_0 + i); - - int frequency = boardConfiguration->fsioFrequency[i]; - if (frequency == 0) { - outputPinRegisterExt2(getPinName(pin), pin, boardConfiguration->fsioPins[i], &d); - } else { - startSimplePwmExt(&fsioPwm[i], "FSIO", brainPin, pin, frequency, 0.5f, applyPinState); - } - } - } - - addConsoleActionSSP("set_fsio", (VoidCharPtrCharPtrVoidPtr) setUserOutput, engine); - addConsoleActionSS("set_fsio_pin", (VoidCharPtrCharPtr) setFsioPin); - addConsoleActionII("set_fsio_frequency", (VoidIntInt) setFsioFrequency); - addConsoleActionFF("set_fsio_setting", setFsioSetting); - addConsoleAction("fsioinfo", showFsioInfo); -#endif - addConsoleActionSS("set_float", (VoidCharPtrCharPtr) setFloat); addConsoleActionII("set_int", (VoidIntInt) setInt); addConsoleActionI("get_float", getFloat); addConsoleActionI("get_int", getInt); - initEval(engine); + initFsioImpl(engine); } diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 8414715366..3a9f414b4c 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -265,5 +265,5 @@ int getRusEfiVersion(void) { return 1; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE == 0) return 1; // this is here to make the compiler happy about the unused array - return 20141226; + return 20141227; } diff --git a/unit_tests/test_logic_expression.cpp b/unit_tests/test_logic_expression.cpp index cd3661924f..9e23d09a04 100644 --- a/unit_tests/test_logic_expression.cpp +++ b/unit_tests/test_logic_expression.cpp @@ -9,10 +9,8 @@ #include "main.h" #include "test_logic_expression.h" -#include "logic_expression.h" -#include "le_functions.h" +#include "fsio_impl.h" #include "cli_registry.h" -#include "engine.h" #define TEST_POOL_SIZE 256