2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file fsio_impl.cpp
|
|
|
|
* @brief FSIO as it's used for GPIO
|
|
|
|
*
|
2017-12-17 09:02:35 -08:00
|
|
|
* set debug_mode 23
|
|
|
|
* https://rusefi.com/wiki/index.php?title=Manual:Flexible_Logic
|
|
|
|
*
|
2015-07-10 06:01:56 -07:00
|
|
|
* @date Oct 5, 2014
|
2018-01-20 17:55:31 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2018
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
|
|
|
|
2018-09-16 19:26:57 -07:00
|
|
|
#include "global.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#if EFI_FSIO || defined(__DOXYGEN__)
|
|
|
|
|
|
|
|
#include "fsio_impl.h"
|
|
|
|
#include "allsensors.h"
|
|
|
|
#include "rpm_calculator.h"
|
|
|
|
#include "efiGpio.h"
|
2018-12-24 05:37:25 -08:00
|
|
|
#include "pwm_generator_logic.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-07-14 18:35:38 -07:00
|
|
|
/**
|
|
|
|
* in case of zero frequency pin is operating as simple on/off. '1' for ON and '0' for OFF
|
|
|
|
*
|
|
|
|
*/
|
2015-07-10 06:01:56 -07:00
|
|
|
#define NO_PWM 0
|
|
|
|
|
2017-08-03 18:21:02 -07:00
|
|
|
|
2018-07-29 15:02:37 -07:00
|
|
|
// see useFSIO15ForIdleRpmAdjustment
|
|
|
|
#define MAGIC_OFFSET_FOR_IDLE_TARGET_RPM 14
|
2017-08-03 18:21:02 -07:00
|
|
|
// see useFSIO16ForTimingAdjustment
|
|
|
|
#define MAGIC_OFFSET_FOR_TIMING_FSIO 15
|
|
|
|
|
2016-06-29 22:01:38 -07:00
|
|
|
fsio8_Map3D_f32t fsioTable1("fsio#1");
|
2016-07-01 20:01:22 -07:00
|
|
|
fsio8_Map3D_u8t fsioTable2("fsio#2");
|
|
|
|
fsio8_Map3D_u8t fsioTable3("fsio#3");
|
|
|
|
fsio8_Map3D_u8t fsioTable4("fsio#4");
|
2016-04-04 07:01:43 -07:00
|
|
|
|
2017-08-03 18:28:44 -07:00
|
|
|
extern pin_output_mode_e DEFAULT_OUTPUT;
|
2016-04-04 07:01:43 -07:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* 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");
|
2016-07-07 20:01:43 -07:00
|
|
|
static LENameOrdinalPair leMap(LE_METHOD_MAP, "map");
|
2015-07-10 06:01:56 -07:00
|
|
|
static LENameOrdinalPair leVBatt(LE_METHOD_VBATT, "vbatt");
|
|
|
|
static LENameOrdinalPair leFan(LE_METHOD_FAN, "fan");
|
|
|
|
static LENameOrdinalPair leCoolant(LE_METHOD_COOLANT, "coolant");
|
2017-06-04 12:00:19 -07:00
|
|
|
static LENameOrdinalPair leIsCoolantBroken(LE_METHOD_IS_COOLANT_BROKEN, "is_clt_broken");
|
2015-07-10 06:01:56 -07:00
|
|
|
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 leFsioSetting(LE_METHOD_FSIO_SETTING, "fsio_setting");
|
2016-03-22 11:03:44 -07:00
|
|
|
static LENameOrdinalPair leFsioTable(LE_METHOD_FSIO_TABLE, "fsio_table");
|
2018-08-01 20:02:19 -07:00
|
|
|
static LENameOrdinalPair leFsioAnalogInput(LE_METHOD_FSIO_ANALOG_INPUT, "fsio_analog_input");
|
|
|
|
static LENameOrdinalPair leFsioDigitalInput(LE_METHOD_FSIO_DIGITAL_INPUT, "fsio_digital_input");
|
2015-07-10 06:01:56 -07:00
|
|
|
static LENameOrdinalPair leKnock(LE_METHOD_KNOCK, "knock");
|
2016-12-17 09:03:02 -08:00
|
|
|
static LENameOrdinalPair leIntakeVVT(LE_METHOD_INTAKE_VVT, "ivvt");
|
|
|
|
static LENameOrdinalPair leExhaustVVT(LE_METHOD_EXHAUST_VVT, "evvt");
|
2017-06-14 02:39:00 -07:00
|
|
|
static LENameOrdinalPair leCrankingRpm(LE_METHOD_CRANKING_RPM, "cranking_rpm");
|
2017-06-24 22:35:46 -07:00
|
|
|
static LENameOrdinalPair leStartupFuelPumpDuration(LE_METHOD_STARTUP_FUEL_PUMP_DURATION, "startup_fuel_pump_duration");
|
|
|
|
static LENameOrdinalPair leInShutdown(LE_METHOD_IN_SHUTDOWN, "in_shutdown");
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#define LE_EVAL_POOL_SIZE 32
|
|
|
|
|
2016-11-03 20:02:58 -07:00
|
|
|
extern EnginePins enginePins;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
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
|
|
|
|
|
2017-01-06 08:02:49 -08:00
|
|
|
static LEElement sysElements[SYS_ELEMENT_POOL_SIZE] CCM_OPTIONAL;
|
2015-07-10 06:01:56 -07:00
|
|
|
LEElementPool sysPool(sysElements, SYS_ELEMENT_POOL_SIZE);
|
|
|
|
|
2017-01-06 08:02:49 -08:00
|
|
|
static LEElement userElements[UD_ELEMENT_POOL_SIZE] CCM_OPTIONAL;
|
2015-07-10 06:01:56 -07:00
|
|
|
LEElementPool userPool(userElements, UD_ELEMENT_POOL_SIZE);
|
2017-06-25 23:14:31 -07:00
|
|
|
static LEElement * fsioLogics[FSIO_COMMAND_COUNT] CCM_OPTIONAL;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
static LEElement * acRelayLogic;
|
|
|
|
static LEElement * fuelPumpLogic;
|
|
|
|
static LEElement * radiatorFanLogic;
|
|
|
|
static LEElement * alternatorLogic;
|
|
|
|
|
2017-06-12 15:14:39 -07:00
|
|
|
#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__)
|
|
|
|
static LEElement * mainRelayLogic;
|
|
|
|
#endif /* EFI_MAIN_RELAY_CONTROL */
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
EXTERN_ENGINE
|
|
|
|
;
|
|
|
|
|
|
|
|
static Logging *logger;
|
2018-12-24 05:37:25 -08:00
|
|
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-06-04 12:25:37 -07:00
|
|
|
float getEngineValue(le_action_e action DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
2018-07-25 20:30:00 -07:00
|
|
|
efiAssert(CUSTOM_ERR_ASSERT, engine!=NULL, "getLEValue", NAN);
|
2015-07-10 06:01:56 -07:00
|
|
|
switch (action) {
|
|
|
|
case LE_METHOD_FAN:
|
|
|
|
return enginePins.fanRelay.getLogicValue();
|
|
|
|
case LE_METHOD_AC_TOGGLE:
|
2017-05-15 20:28:49 -07:00
|
|
|
return getAcToggle(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2015-07-10 06:01:56 -07:00
|
|
|
case LE_METHOD_COOLANT:
|
2017-05-15 20:28:49 -07:00
|
|
|
return getCoolantTemperature(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2017-06-04 12:00:19 -07:00
|
|
|
case LE_METHOD_IS_COOLANT_BROKEN:
|
|
|
|
return engine->isCltBroken;
|
2015-07-10 06:01:56 -07:00
|
|
|
case LE_METHOD_INTAKE_AIR:
|
2017-05-15 20:28:49 -07:00
|
|
|
return getIntakeAirTemperature(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2015-07-10 06:01:56 -07:00
|
|
|
case LE_METHOD_RPM:
|
2016-01-18 09:03:32 -08:00
|
|
|
return engine->rpmCalculator.getRpm();
|
2016-07-07 20:01:43 -07:00
|
|
|
case LE_METHOD_MAF:
|
2017-05-15 20:28:49 -07:00
|
|
|
return getMaf(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2016-07-07 20:01:43 -07:00
|
|
|
case LE_METHOD_MAP:
|
|
|
|
return getMap();
|
2016-12-17 09:03:02 -08:00
|
|
|
case LE_METHOD_INTAKE_VVT:
|
|
|
|
case LE_METHOD_EXHAUST_VVT:
|
|
|
|
return engine->triggerCentral.vvtPosition;
|
2015-07-10 06:01:56 -07:00
|
|
|
case LE_METHOD_TIME_SINCE_BOOT:
|
|
|
|
return getTimeNowSeconds();
|
|
|
|
case LE_METHOD_FAN_OFF_SETTING:
|
|
|
|
return engineConfiguration->fanOffTemperature;
|
|
|
|
case LE_METHOD_FAN_ON_SETTING:
|
|
|
|
return engineConfiguration->fanOnTemperature;
|
2017-06-14 02:39:00 -07:00
|
|
|
case LE_METHOD_CRANKING_RPM:
|
|
|
|
return engineConfiguration->cranking.rpm;
|
2017-06-24 22:35:46 -07:00
|
|
|
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();
|
2015-07-10 06:01:56 -07:00
|
|
|
case LE_METHOD_VBATT:
|
2017-05-15 20:28:49 -07:00
|
|
|
return getVBatt(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2015-07-10 06:01:56 -07:00
|
|
|
default:
|
2017-04-19 19:03:14 -07:00
|
|
|
warning(CUSTOM_FSIO_UNEXPECTED, "FSIO unexpected %d", action);
|
2015-07-10 06:01:56 -07:00
|
|
|
return NAN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
|
|
|
|
|
|
|
#include "pin_repository.h"
|
|
|
|
#include "pwm_generator.h"
|
|
|
|
// todo: that's about bench test mode, wrong header for sure!
|
|
|
|
#include "injector_central.h"
|
|
|
|
|
2018-08-01 20:27:22 -07:00
|
|
|
static void setFsioAnalogInputPin(const char *indexStr, const char *pinName) {
|
|
|
|
// todo: reduce code duplication between all "set pin methods"
|
|
|
|
int index = atoi(indexStr) - 1;
|
|
|
|
if (index < 0 || index >= FSIO_COMMAND_COUNT) {
|
|
|
|
scheduleMsg(logger, "invalid FSIO 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;
|
|
|
|
}
|
2018-08-01 20:33:13 -07:00
|
|
|
engineConfiguration->fsioAdc[index] = (adc_channel_e) pin;
|
2018-08-01 20:27:22 -07:00
|
|
|
scheduleMsg(logger, "FSIO analog input pin #%d [%s]", (index + 1), hwPortname(pin));
|
|
|
|
}
|
|
|
|
|
2018-08-01 20:02:19 -07:00
|
|
|
static void setFsioDigitalInputPin(const char *indexStr, const char *pinName) {
|
2018-08-01 20:27:22 -07:00
|
|
|
// todo: reduce code duplication between all "set pin methods"
|
2015-07-10 06:01:56 -07:00
|
|
|
int index = atoi(indexStr) - 1;
|
2017-06-25 23:14:31 -07:00
|
|
|
if (index < 0 || index >= FSIO_COMMAND_COUNT) {
|
2016-01-12 19:01:53 -08:00
|
|
|
scheduleMsg(logger, "invalid FSIO index: %d", index);
|
2015-07-10 06:01:56 -07:00
|
|
|
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->fsioDigitalInputs[index] = pin;
|
2018-08-01 20:27:22 -07:00
|
|
|
scheduleMsg(logger, "FSIO digital input pin #%d [%s]", (index + 1), hwPortname(pin));
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2016-12-27 21:02:03 -08:00
|
|
|
static void setFsioPidOutputPin(const char *indexStr, const char *pinName) {
|
|
|
|
int index = atoi(indexStr) - 1;
|
|
|
|
if (index < 0 || index >= AUX_PID_COUNT) {
|
|
|
|
scheduleMsg(logger, "invalid AUX 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;
|
|
|
|
}
|
|
|
|
engineConfiguration->auxPidPins[index] = pin;
|
|
|
|
scheduleMsg(logger, "FSIO aux pin #%d [%s]", (index + 1), hwPortname(pin));
|
|
|
|
}
|
|
|
|
|
2017-12-17 09:02:35 -08:00
|
|
|
static void showFsioInfo(void);
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
static void setFsioOutputPin(const char *indexStr, const char *pinName) {
|
|
|
|
int index = atoi(indexStr) - 1;
|
2017-06-25 23:14:31 -07:00
|
|
|
if (index < 0 || index >= FSIO_COMMAND_COUNT) {
|
2016-01-12 19:01:53 -08:00
|
|
|
scheduleMsg(logger, "invalid FSIO index: %d", index);
|
2015-07-10 06:01:56 -07:00
|
|
|
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;
|
|
|
|
}
|
2017-11-19 07:23:47 -08:00
|
|
|
boardConfiguration->fsioOutputPins[index] = pin;
|
2015-07-10 06:01:56 -07:00
|
|
|
scheduleMsg(logger, "FSIO output pin #%d [%s]", (index + 1), hwPortname(pin));
|
2018-08-01 05:00:02 -07:00
|
|
|
scheduleMsg(logger, "please writeconfig and reboot for pin to take effect");
|
2017-12-17 09:02:35 -08:00
|
|
|
showFsioInfo();
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2016-01-12 07:04:06 -08:00
|
|
|
#endif /* EFI_PROD_CODE */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-01-12 09:01:43 -08:00
|
|
|
#endif
|
|
|
|
|
2016-01-12 19:01:53 -08:00
|
|
|
/**
|
|
|
|
* index is between zero and LE_COMMAND_LENGTH-1
|
|
|
|
*/
|
2017-12-17 09:02:35 -08:00
|
|
|
void setFsioExt(int index, brain_pin_e pin, const char * formula, int pwmFrequency DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
2017-11-19 07:23:47 -08:00
|
|
|
boardConfiguration->fsioOutputPins[index] = pin;
|
2017-12-17 09:02:35 -08:00
|
|
|
int len = strlen(formula);
|
2015-07-10 06:01:56 -07:00
|
|
|
if (len >= LE_COMMAND_LENGTH) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-17 09:02:35 -08:00
|
|
|
strcpy(config->fsioFormulas[index], formula);
|
2017-07-14 18:42:25 -07:00
|
|
|
boardConfiguration->fsioFrequency[index] = pwmFrequency;
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
void setFsio(int index, brain_pin_e pin, const char * exp DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|
|
|
setFsioExt(index, pin, exp, NO_PWM PASS_ENGINE_PARAMETER_SUFFIX);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
void applyFsioConfiguration(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
2016-06-26 17:03:27 -07:00
|
|
|
userPool.reset();
|
2017-06-25 23:14:31 -07:00
|
|
|
for (int i = 0; i < FSIO_COMMAND_COUNT; i++) {
|
2017-11-19 07:23:47 -08:00
|
|
|
brain_pin_e brainPin = boardConfiguration->fsioOutputPins[i];
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
if (brainPin != GPIO_UNASSIGNED) {
|
2017-06-25 23:23:26 -07:00
|
|
|
const char *formula = config->fsioFormulas[i];
|
2015-07-10 06:01:56 -07:00
|
|
|
LEElement *logic = userPool.parseExpression(formula);
|
|
|
|
if (logic == NULL) {
|
2017-04-19 19:03:14 -07:00
|
|
|
warning(CUSTOM_FSIO_PARSING, "parsing [%s]", formula);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
fsioLogics[i] = logic;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-03 08:42:50 -08:00
|
|
|
void onConfigurationChangeFsioCallback(engine_configuration_s *previousConfiguration DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|
|
|
#if EFI_FSIO || defined(__DOXYGEN__)
|
|
|
|
applyFsioConfiguration(PASS_ENGINE_PARAMETER_SIGNATURE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
static LECalculator calc;
|
2017-06-25 23:14:31 -07:00
|
|
|
extern LEElement * fsioLogics[FSIO_COMMAND_COUNT];
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2018-12-24 05:37:25 -08:00
|
|
|
static SimplePwm fsioPwm[FSIO_COMMAND_COUNT] CCM_OPTIONAL;
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
// that's crazy, but what's an alternative? we need const char *, a shared buffer would not work for pin repository
|
|
|
|
static const char *getGpioPinName(int index) {
|
|
|
|
switch (index) {
|
|
|
|
case 0:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_0";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 1:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_1";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 10:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_10";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 11:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_11";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 12:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_12";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 13:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_13";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 14:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_14";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 15:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_15";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 2:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_2";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 3:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_3";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 4:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_4";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 5:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_5";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 6:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_6";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 7:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_7";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 8:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_8";
|
2015-07-10 06:01:56 -07:00
|
|
|
case 9:
|
2017-05-12 11:37:07 -07:00
|
|
|
return "FSIO_OUT_9";
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2017-12-16 21:03:26 -08:00
|
|
|
float getFsioOutputValue(int index DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|
|
|
if (fsioLogics[index] == NULL) {
|
|
|
|
warning(CUSTOM_NO_FSIO, "no FSIO for #%d %s", index + 1, hwPortname(boardConfiguration->fsioOutputPins[index]));
|
|
|
|
return NAN;
|
|
|
|
} else {
|
|
|
|
return calc.getValue2(engine->fsioLastValue[index], fsioLogics[index] PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-01 06:02:04 -07:00
|
|
|
/**
|
2017-06-25 23:14:31 -07:00
|
|
|
* @param index from zero for (FSIO_COMMAND_COUNT - 1)
|
2016-10-01 06:02:04 -07:00
|
|
|
*/
|
2017-12-16 21:03:26 -08:00
|
|
|
static void handleFsio(int index DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
2017-12-17 09:02:35 -08:00
|
|
|
if (boardConfiguration->fsioOutputPins[index] == GPIO_UNASSIGNED) {
|
|
|
|
engine->fsioLastValue[index] = NAN;
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
2017-12-17 09:02:35 -08:00
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-01-11 14:01:33 -08:00
|
|
|
bool isPwmMode = boardConfiguration->fsioFrequency[index] != NO_PWM;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-12-16 21:07:43 -08:00
|
|
|
float fvalue = getFsioOutputValue(index PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
engine->fsioLastValue[index] = fvalue;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
if (isPwmMode) {
|
|
|
|
fsioPwm[index].setSimplePwmDutyCycle(fvalue);
|
|
|
|
} else {
|
|
|
|
int value = (int) fvalue;
|
2016-09-14 16:03:00 -07:00
|
|
|
if (value != enginePins.fsioOutputs[index].getLogicValue()) {
|
2015-07-10 06:01:56 -07:00
|
|
|
// scheduleMsg(logger, "setting %s %s", getIo_pin_e(pin), boolToString(value));
|
2016-09-14 16:03:00 -07:00
|
|
|
enginePins.fsioOutputs[index].setValue(value);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char * action2String(le_action_e action) {
|
2016-08-09 21:04:24 -07:00
|
|
|
static char buffer[_MAX_FILLER];
|
2015-07-10 06:01:56 -07:00
|
|
|
switch(action) {
|
|
|
|
case LE_METHOD_RPM:
|
|
|
|
return "RPM";
|
2017-06-14 02:39:00 -07:00
|
|
|
case LE_METHOD_CRANKING_RPM:
|
|
|
|
return "cranking_rpm";
|
2015-07-10 06:01:56 -07:00
|
|
|
case LE_METHOD_COOLANT:
|
|
|
|
return "CLT";
|
|
|
|
case LE_METHOD_FAN_ON_SETTING:
|
|
|
|
return "fan_on";
|
|
|
|
case LE_METHOD_FAN_OFF_SETTING:
|
|
|
|
return "fan_off";
|
|
|
|
case LE_METHOD_FAN:
|
|
|
|
return "fan";
|
2017-06-24 22:35:46 -07:00
|
|
|
case LE_METHOD_STARTUP_FUEL_PUMP_DURATION:
|
|
|
|
return "startup_fuel_pump_duration";
|
|
|
|
case LE_METHOD_IN_SHUTDOWN:
|
|
|
|
return "in_shutdown";
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
default: {
|
|
|
|
// this is here to make compiler happy
|
|
|
|
}
|
|
|
|
}
|
|
|
|
itoa10(buffer, (int)action);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2018-12-24 05:37:25 -08:00
|
|
|
static void setPinState(const char * msg, OutputPin *pin, LEElement *element DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|
|
|
#if EFI_PROD_CODE
|
2017-07-24 17:34:40 -07:00
|
|
|
if (isRunningBenchTest()) {
|
|
|
|
return; // let's not mess with bench testing
|
|
|
|
}
|
2018-12-24 05:37:25 -08:00
|
|
|
#endif /* EFI_PROD_CODE */
|
2017-07-24 17:34:40 -07:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
if (element == NULL) {
|
2017-07-24 16:38:22 -07:00
|
|
|
warning(CUSTOM_FSIO_INVALID_EXPRESSION, "invalid expression for %s", msg);
|
2015-07-10 06:01:56 -07:00
|
|
|
} else {
|
2017-06-04 12:25:37 -07:00
|
|
|
int value = (int)calc.getValue2(pin->getLogicValue(), element PASS_ENGINE_PARAMETER_SUFFIX);
|
2015-07-10 06:01:56 -07:00
|
|
|
if (pin->isInitialized() && value != pin->getLogicValue()) {
|
|
|
|
|
|
|
|
for (int i = 0;i < calc.currentCalculationLogPosition;i++) {
|
2018-01-23 09:05:14 -08:00
|
|
|
scheduleMsg(logger, "calc %d: action %s value %.2f", i, action2String(calc.calcLogAction[i]), calc.calcLogValue[i]);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
scheduleMsg(logger, "setPin %s %s", msg, value ? "on" : "off");
|
|
|
|
pin->setValue(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-24 05:37:25 -08:00
|
|
|
|
|
|
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
2016-01-12 07:04:06 -08:00
|
|
|
static void setFsioFrequency(int index, int frequency) {
|
|
|
|
index--;
|
2017-06-25 23:14:31 -07:00
|
|
|
if (index < 0 || index >= FSIO_COMMAND_COUNT) {
|
2016-01-12 19:01:53 -08:00
|
|
|
scheduleMsg(logger, "invalid FSIO index: %d", index);
|
2016-01-12 07:04:06 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
boardConfiguration->fsioFrequency[index] = frequency;
|
2017-03-12 11:47:21 -07:00
|
|
|
if (frequency == 0) {
|
2017-11-19 07:23:47 -08:00
|
|
|
scheduleMsg(logger, "FSIO output #%d@%s set to on/off mode", index + 1, hwPortname(boardConfiguration->fsioOutputPins[index]));
|
2017-03-12 11:47:21 -07:00
|
|
|
} else {
|
2017-11-19 07:23:47 -08:00
|
|
|
scheduleMsg(logger, "Setting FSIO frequency %dHz on #%d@%s", frequency, index + 1, hwPortname(boardConfiguration->fsioOutputPins[index]));
|
2017-03-12 11:47:21 -07:00
|
|
|
}
|
2016-01-12 07:04:06 -08:00
|
|
|
}
|
2018-12-24 05:37:25 -08:00
|
|
|
#endif /* EFI_PROD_CODE */
|
2016-01-12 07:04:06 -08:00
|
|
|
|
2018-03-18 09:15:51 -07:00
|
|
|
static void useFsioForServo(int servoIndex DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
|
|
|
LEElement * element = fsioLogics[8 - 1 + servoIndex];
|
|
|
|
|
|
|
|
if (element == NULL) {
|
|
|
|
warning(CUSTOM_FSIO_INVALID_EXPRESSION, "invalid expression for %s", "servo");
|
|
|
|
} else {
|
|
|
|
engine->servoValues[servoIndex] = calc.getValue2(engine->servoValues[servoIndex], element PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-16 21:03:26 -08:00
|
|
|
/**
|
|
|
|
* this method should be invoked periodically to calculate FSIO and toggle corresponding FSIO outputs
|
|
|
|
*/
|
|
|
|
void runFsio(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
|
|
|
for (int index = 0; index < FSIO_COMMAND_COUNT; index++) {
|
|
|
|
handleFsio(index PASS_ENGINE_PARAMETER_SUFFIX);
|
2016-01-12 07:04:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
#if EFI_FUEL_PUMP || defined(__DOXYGEN__)
|
2016-12-27 21:02:03 -08:00
|
|
|
if (boardConfiguration->fuelPumpPin != GPIO_UNASSIGNED) {
|
2018-12-24 05:37:25 -08:00
|
|
|
setPinState("pump", &enginePins.fuelPumpRelay, fuelPumpLogic PASS_ENGINE_PARAMETER_SUFFIX);
|
2016-01-12 07:04:06 -08:00
|
|
|
}
|
|
|
|
#endif /* EFI_FUEL_PUMP */
|
|
|
|
|
2017-06-12 15:14:39 -07:00
|
|
|
#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__)
|
|
|
|
if (boardConfiguration->mainRelayPin != GPIO_UNASSIGNED)
|
2018-12-24 05:37:25 -08:00
|
|
|
setPinState("main_relay", &enginePins.mainRelay, mainRelayLogic PASS_ENGINE_PARAMETER_SUFFIX);
|
2017-06-12 15:14:39 -07:00
|
|
|
#else /* EFI_MAIN_RELAY_CONTROL */
|
2016-01-12 07:04:06 -08:00
|
|
|
/**
|
|
|
|
* 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);
|
2017-06-12 15:14:39 -07:00
|
|
|
#endif /* EFI_MAIN_RELAY_CONTROL */
|
2016-01-12 07:04:06 -08:00
|
|
|
|
2017-07-06 18:26:35 -07:00
|
|
|
/**
|
|
|
|
* o2 heater is off during cranking
|
2017-07-08 12:46:34 -07:00
|
|
|
* todo: convert to FSIO?
|
|
|
|
* open question if heater should be ON during cranking
|
2017-07-06 18:26:35 -07:00
|
|
|
*/
|
2018-12-24 05:37:25 -08:00
|
|
|
enginePins.o2heater.setValue(engine->rpmCalculator.isRunning(PASS_ENGINE_PARAMETER_SIGNATURE));
|
2016-01-12 07:04:06 -08:00
|
|
|
|
|
|
|
if (boardConfiguration->acRelayPin != GPIO_UNASSIGNED) {
|
2018-12-24 05:37:25 -08:00
|
|
|
setPinState("A/C", &enginePins.acRelay, acRelayLogic PASS_ENGINE_PARAMETER_SUFFIX);
|
2016-01-12 07:04:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// if (boardConfiguration->alternatorControlPin != GPIO_UNASSIGNED) {
|
2018-12-24 05:37:25 -08:00
|
|
|
// setPinState("alternator", &enginePins.alternatorField, alternatorLogic, engine PASS_ENGINE_PARAMETER_SUFFIX);
|
2016-01-12 07:04:06 -08:00
|
|
|
// }
|
|
|
|
|
|
|
|
if (boardConfiguration->fanPin != GPIO_UNASSIGNED) {
|
2018-12-24 05:37:25 -08:00
|
|
|
setPinState("fan", &enginePins.fanRelay, radiatorFanLogic PASS_ENGINE_PARAMETER_SUFFIX);
|
2016-01-12 07:04:06 -08:00
|
|
|
}
|
2018-07-29 15:02:37 -07:00
|
|
|
|
|
|
|
if (engineConfiguration->useFSIO15ForIdleRpmAdjustment) {
|
|
|
|
LEElement * element = fsioLogics[MAGIC_OFFSET_FOR_IDLE_TARGET_RPM];
|
|
|
|
if (element == NULL) {
|
|
|
|
warning(CUSTOM_FSIO_INVALID_EXPRESSION, "invalid expression for %s", "RPM targer");
|
|
|
|
} else {
|
|
|
|
engine->fsioIdleTargetRPMAdjustment = calc.getValue2(engine->fsioIdleTargetRPMAdjustment, element PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2017-07-25 17:37:46 -07:00
|
|
|
if (engineConfiguration->useFSIO16ForTimingAdjustment) {
|
2017-08-03 18:21:02 -07:00
|
|
|
LEElement * element = fsioLogics[MAGIC_OFFSET_FOR_TIMING_FSIO];
|
2017-07-25 17:37:46 -07:00
|
|
|
|
2017-08-03 18:21:02 -07:00
|
|
|
if (element == NULL) {
|
|
|
|
warning(CUSTOM_FSIO_INVALID_EXPRESSION, "invalid expression for %s", "timing");
|
|
|
|
} else {
|
|
|
|
engine->fsioTimingAdjustment = calc.getValue2(engine->fsioTimingAdjustment, element PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
}
|
2017-07-25 17:37:46 -07:00
|
|
|
}
|
2016-01-12 07:04:06 -08:00
|
|
|
|
2018-03-18 09:15:51 -07:00
|
|
|
|
|
|
|
if (engineConfiguration->useFSIO8ForServo1) {
|
|
|
|
useFsioForServo(0 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
}
|
|
|
|
if (engineConfiguration->useFSIO9ForServo2) {
|
|
|
|
useFsioForServo(1 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
}
|
|
|
|
if (engineConfiguration->useFSIO10ForServo3) {
|
|
|
|
useFsioForServo(2 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
}
|
|
|
|
if (engineConfiguration->useFSIO11ForServo4) {
|
|
|
|
useFsioForServo(3 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
}
|
|
|
|
if (engineConfiguration->useFSIO12ForServo5) {
|
|
|
|
useFsioForServo(4 PASS_ENGINE_PARAMETER_SUFFIX);
|
|
|
|
}
|
|
|
|
|
2016-01-12 07:04:06 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
static void showFsio(const char *msg, LEElement *element) {
|
2016-01-12 09:01:43 -08:00
|
|
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
if (msg != NULL)
|
|
|
|
scheduleMsg(logger, "%s:", msg);
|
|
|
|
while (element != NULL) {
|
2018-01-23 09:05:14 -08:00
|
|
|
scheduleMsg(logger, "action %d: fValue=%.2f iValue=%d", element->action, element->fValue, element->iValue);
|
2015-07-10 06:01:56 -07:00
|
|
|
element = element->next;
|
|
|
|
}
|
|
|
|
scheduleMsg(logger, "<end>");
|
2016-01-12 09:01:43 -08:00
|
|
|
#endif
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static void showFsioInfo(void) {
|
2016-01-12 09:01:43 -08:00
|
|
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
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);
|
|
|
|
|
2016-12-27 21:02:03 -08:00
|
|
|
for (int i = 0; i < AUX_PID_COUNT ; i++) {
|
|
|
|
brain_pin_e pin = engineConfiguration->auxPidPins[i];
|
|
|
|
if (pin != GPIO_UNASSIGNED) {
|
|
|
|
scheduleMsg(logger, "FSIO aux #%d [%s]", (i + 1),
|
|
|
|
hwPortname(pin));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-06-25 23:14:31 -07:00
|
|
|
for (int i = 0; i < FSIO_COMMAND_COUNT; i++) {
|
2017-06-25 23:23:26 -07:00
|
|
|
char * exp = config->fsioFormulas[i];
|
2015-07-10 06:01:56 -07:00
|
|
|
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
|
|
|
|
*/
|
2018-01-23 09:05:14 -08:00
|
|
|
scheduleMsg(logger, "FSIO #%d [%s] at %s@%dHz value=%.2f", (i + 1), exp,
|
2017-11-19 07:23:47 -08:00
|
|
|
hwPortname(boardConfiguration->fsioOutputPins[i]), boardConfiguration->fsioFrequency[i],
|
2016-12-18 09:03:48 -08:00
|
|
|
engine->fsioLastValue[i]);
|
2018-01-23 09:05:14 -08:00
|
|
|
// scheduleMsg(logger, "user-defined #%d value=%.2f", i, engine->engineConfiguration2->fsioLastValue[i]);
|
2015-07-10 06:01:56 -07:00
|
|
|
showFsio(NULL, fsioLogics[i]);
|
|
|
|
}
|
|
|
|
}
|
2017-06-25 23:14:31 -07:00
|
|
|
for (int i = 0; i < FSIO_COMMAND_COUNT; i++) {
|
2015-07-10 06:01:56 -07:00
|
|
|
float v = boardConfiguration->fsio_setting[i];
|
|
|
|
if (!cisnan(v)) {
|
2018-01-23 09:05:14 -08:00
|
|
|
scheduleMsg(logger, "user property #%d: %.2f", i + 1, v);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
2017-06-25 23:14:31 -07:00
|
|
|
for (int i = 0; i < FSIO_COMMAND_COUNT; i++) {
|
2015-07-10 06:01:56 -07:00
|
|
|
brain_pin_e inputPin = boardConfiguration->fsioDigitalInputs[i];
|
|
|
|
if (inputPin != GPIO_UNASSIGNED) {
|
|
|
|
scheduleMsg(logger, "FSIO digital input #%d: %s", i, hwPortname(inputPin));
|
|
|
|
}
|
|
|
|
}
|
2016-01-12 09:01:43 -08:00
|
|
|
#endif
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2017-03-12 11:47:21 -07:00
|
|
|
* set_fsio_setting 1 0.11
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2017-03-12 12:22:07 -07:00
|
|
|
static void setFsioSetting(float humanIndexF, float value) {
|
2016-01-12 09:01:43 -08:00
|
|
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
2017-03-12 12:22:07 -07:00
|
|
|
int index = (int)humanIndexF - 1;
|
2017-06-25 23:14:31 -07:00
|
|
|
if (index < 0 || index >= FSIO_COMMAND_COUNT) {
|
2017-03-12 12:22:07 -07:00
|
|
|
scheduleMsg(logger, "invalid FSIO index: %d", (int)humanIndexF);
|
2015-07-10 06:01:56 -07:00
|
|
|
return;
|
|
|
|
}
|
2017-03-12 12:22:07 -07:00
|
|
|
engineConfiguration->bc.fsio_setting[index] = value;
|
2015-07-10 06:01:56 -07:00
|
|
|
showFsioInfo();
|
2016-01-12 09:01:43 -08:00
|
|
|
#endif
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2017-11-26 16:35:08 -08:00
|
|
|
static void setFsioExpression(const char *indexStr, const char *quotedLine) {
|
2016-01-12 09:01:43 -08:00
|
|
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
int index = atoi(indexStr) - 1;
|
2017-06-25 23:14:31 -07:00
|
|
|
if (index < 0 || index >= FSIO_COMMAND_COUNT) {
|
2016-01-12 19:01:53 -08:00
|
|
|
scheduleMsg(logger, "invalid FSIO index: %d", index);
|
2015-07-10 06:01:56 -07:00
|
|
|
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);
|
2017-11-26 16:35:08 -08:00
|
|
|
strcpy(config->fsioFormulas[index], l);
|
2015-07-10 06:01:56 -07:00
|
|
|
// this would apply the changes
|
2017-05-15 20:28:49 -07:00
|
|
|
applyFsioConfiguration(PASS_ENGINE_PARAMETER_SIGNATURE);
|
2015-07-10 06:01:56 -07:00
|
|
|
showFsioInfo();
|
2016-01-12 09:01:43 -08:00
|
|
|
#endif
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2017-06-04 12:25:37 -07:00
|
|
|
static void rpnEval(char *line) {
|
2016-01-12 09:01:43 -08:00
|
|
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
line = unquote(line);
|
|
|
|
scheduleMsg(logger, "Parsing [%s]", line);
|
|
|
|
evalPool.reset();
|
|
|
|
LEElement * e = evalPool.parseExpression(line);
|
|
|
|
if (e == NULL) {
|
|
|
|
scheduleMsg(logger, "parsing failed");
|
|
|
|
} else {
|
2017-06-04 12:25:37 -07:00
|
|
|
float result = evalCalc.getValue2(0, e PASS_ENGINE_PARAMETER_SUFFIX);
|
2018-01-23 09:05:14 -08:00
|
|
|
scheduleMsg(logger, "Evaluate result: %.2f", result);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
2016-01-12 09:01:43 -08:00
|
|
|
#endif
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2017-05-15 20:28:49 -07:00
|
|
|
void initFsioImpl(Logging *sharedLogger DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
2016-01-12 09:01:43 -08:00
|
|
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
2015-07-10 06:01:56 -07:00
|
|
|
logger = sharedLogger;
|
2016-01-12 09:01:43 -08:00
|
|
|
#endif
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2016-01-12 07:04:06 -08:00
|
|
|
#if EFI_FUEL_PUMP || defined(__DOXYGEN__)
|
2015-07-10 06:01:56 -07:00
|
|
|
fuelPumpLogic = sysPool.parseExpression(FUEL_PUMP_LOGIC);
|
2016-01-12 07:04:06 -08:00
|
|
|
#endif /* EFI_FUEL_PUMP */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
acRelayLogic = sysPool.parseExpression(AC_RELAY_LOGIC);
|
|
|
|
radiatorFanLogic = sysPool.parseExpression(FAN_CONTROL_LOGIC);
|
|
|
|
|
|
|
|
alternatorLogic = sysPool.parseExpression(ALTERNATOR_LOGIC);
|
2017-06-12 15:14:39 -07:00
|
|
|
|
|
|
|
#if EFI_MAIN_RELAY_CONTROL || defined(__DOXYGEN__)
|
|
|
|
if (boardConfiguration->mainRelayPin != GPIO_UNASSIGNED)
|
|
|
|
mainRelayLogic = sysPool.parseExpression(MAIN_RELAY_LOGIC);
|
|
|
|
#endif /* EFI_MAIN_RELAY_CONTROL */
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
2017-06-25 23:14:31 -07:00
|
|
|
for (int i = 0; i < FSIO_COMMAND_COUNT; i++) {
|
2017-11-19 07:23:47 -08:00
|
|
|
brain_pin_e brainPin = boardConfiguration->fsioOutputPins[i];
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
if (brainPin != GPIO_UNASSIGNED) {
|
|
|
|
int frequency = boardConfiguration->fsioFrequency[i];
|
|
|
|
if (frequency == 0) {
|
2017-11-19 07:23:47 -08:00
|
|
|
enginePins.fsioOutputs[i].initPin(getGpioPinName(i), boardConfiguration->fsioOutputPins[i], &DEFAULT_OUTPUT);
|
2015-07-10 06:01:56 -07:00
|
|
|
} else {
|
2016-09-14 16:03:00 -07:00
|
|
|
startSimplePwmExt(&fsioPwm[i], "FSIOpwm", brainPin, &enginePins.fsioOutputs[i], frequency, 0.5f, applyPinState);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-25 23:14:31 -07:00
|
|
|
for (int i = 0; i < FSIO_COMMAND_COUNT; i++) {
|
2015-07-10 06:01:56 -07:00
|
|
|
brain_pin_e inputPin = boardConfiguration->fsioDigitalInputs[i];
|
|
|
|
|
|
|
|
if (inputPin != GPIO_UNASSIGNED) {
|
2017-05-15 05:40:54 -07:00
|
|
|
efiSetPadMode("FSIO input", inputPin, getInputMode(engineConfiguration->fsioInputModes[i]));
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-27 21:02:03 -08:00
|
|
|
addConsoleActionSS("set_fsio_pid_output_pin", (VoidCharPtrCharPtr) setFsioPidOutputPin);
|
2016-01-12 07:04:06 -08:00
|
|
|
addConsoleActionSS("set_fsio_output_pin", (VoidCharPtrCharPtr) setFsioOutputPin);
|
2018-12-24 05:37:25 -08:00
|
|
|
#if EFI_PROD_CODE || defined(__DOXYGEN__)
|
2016-01-12 07:04:06 -08:00
|
|
|
addConsoleActionII("set_fsio_output_frequency", (VoidIntInt) setFsioFrequency);
|
2018-12-24 05:37:25 -08:00
|
|
|
#endif
|
2018-08-01 20:02:19 -07:00
|
|
|
addConsoleActionSS("set_fsio_digital_input_pin", (VoidCharPtrCharPtr) setFsioDigitalInputPin);
|
2018-08-01 20:27:22 -07:00
|
|
|
addConsoleActionSS("set_fsio_analog_input_pin", (VoidCharPtrCharPtr) setFsioAnalogInputPin);
|
2016-01-12 07:04:06 -08:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif /* EFI_PROD_CODE */
|
|
|
|
|
2016-01-12 09:01:43 -08:00
|
|
|
#if EFI_PROD_CODE || EFI_SIMULATOR
|
2017-11-26 16:35:08 -08:00
|
|
|
addConsoleActionSS("set_rpn_expression", setFsioExpression);
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleActionFF("set_fsio_setting", setFsioSetting);
|
|
|
|
addConsoleAction("fsioinfo", showFsioInfo);
|
2017-06-04 12:25:37 -07:00
|
|
|
addConsoleActionS("rpn_eval", (VoidCharPtr) rpnEval);
|
|
|
|
#endif /* EFI_PROD_CODE || EFI_SIMULATOR */
|
2016-04-04 07:01:43 -07:00
|
|
|
|
|
|
|
fsioTable1.init(config->fsioTable1, config->fsioTable1LoadBins,
|
|
|
|
config->fsioTable1RpmBins);
|
|
|
|
fsioTable2.init(config->fsioTable2, config->fsioTable2LoadBins,
|
|
|
|
config->fsioTable2RpmBins);
|
2016-07-01 20:01:22 -07:00
|
|
|
fsioTable3.init(config->fsioTable3, config->fsioTable3LoadBins,
|
|
|
|
config->fsioTable3RpmBins);
|
|
|
|
fsioTable4.init(config->fsioTable4, config->fsioTable4LoadBins,
|
|
|
|
config->fsioTable4RpmBins);
|
2016-04-04 07:01:43 -07:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2017-07-01 14:29:56 -07:00
|
|
|
void prepareFsio(void) {
|
|
|
|
for (int i = 0; i < FSIO_COMMAND_COUNT; i++) {
|
|
|
|
fsioLogics[i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#endif /* EFI_FSIO */
|