rusefi/firmware/controllers/engine_controller.cpp

561 lines
17 KiB
C++
Raw Normal View History

2014-08-29 07:52:33 -07:00
/**
* @file engine_controller.cpp
* @brief Controllers package entry point code
*
*
*
* @date Feb 7, 2013
* @author Andrey Belomutskiy, (c) 2012-2014
*
* This file is part of rusEfi - see http://rusefi.com
*
* rusEfi is free software; you can redistribute it and/or modify it under the terms of
* the GNU General Public License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* rusEfi is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include "main.h"
#include "trigger_central.h"
#include "engine_controller.h"
#include "idle_thread.h"
#include "rpm_calculator.h"
#include "signal_executor.h"
#include "main_trigger_callback.h"
#include "map_multiplier_thread.h"
#include "io_pins.h"
#include "flash_main.h"
#include "tunerstudio.h"
#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"
#include "analog_chart.h"
#include "electronic_throttle.h"
#include "malfunction_indicator.h"
#include "map_averaging.h"
#include "malfunction_central.h"
#include "pin_repository.h"
#include "pwm_generator.h"
#include "adc_inputs.h"
#include "algo.h"
#include "efilib2.h"
#include "ec2.h"
#include "PwmTester.h"
#include "engine.h"
2014-10-06 02:03:01 -07:00
#include "logic_expression.h"
2014-10-09 00:02:51 -07:00
#include "le_functions.h"
2014-12-04 19:03:19 -08:00
#include "pin_repository.h"
#include "pwm_generator.h"
2014-10-06 02:03:01 -07:00
2014-11-29 08:03:49 -08:00
static LEElement * acRelayLogic;
2014-11-18 11:03:28 -08:00
static LEElement * fuelPumpLogic;
static LEElement * radiatorFanLogic;
2014-11-30 08:04:02 -08:00
static LEElement * alternatorLogic;
2014-08-29 07:52:33 -07:00
2014-11-23 20:03:16 -08:00
extern OutputPin outputs[IO_PIN_COUNT];
extern pin_output_mode_e *pinDefaultState[IO_PIN_COUNT];
2014-11-24 09:03:09 -08:00
extern bool hasFirmwareErrorFlag;
2014-11-23 20:03:16 -08:00
2014-12-06 12:04:01 -08:00
extern LEElementPool sysPool;
extern LEElementPool userPool;
2014-12-05 09:03:16 -08:00
static SimplePwm fsioPwm[LE_COMMAND_COUNT] CCM_OPTIONAL;
2014-12-04 19:03:19 -08:00
2014-11-22 09:03:10 -08:00
persistent_config_container_s persistentState CCM_OPTIONAL;
2014-08-29 07:52:33 -07:00
2014-09-08 15:02:52 -07:00
/**
* todo: it really looks like these fields should become 'static', i.e. private
* the whole 'extern ...' pattern is less then perfect, I guess the 'God object' Engine
* would be a smaller evil. Whatever is needed should be passed into methods/modules/files as an explicit parameter.
*/
2014-08-29 07:52:33 -07:00
engine_configuration_s *engineConfiguration = &persistentState.persistentConfiguration.engineConfiguration;
board_configuration_s *boardConfiguration = &persistentState.persistentConfiguration.engineConfiguration.bc;
/**
* CH_FREQUENCY is the number of system ticks in a second
*/
static VirtualTimer everyMsTimer;
static Logging logger;
2014-11-22 09:03:10 -08:00
static engine_configuration2_s ec2 CCM_OPTIONAL;
2014-08-29 07:52:33 -07:00
engine_configuration2_s * engineConfiguration2 = &ec2;
2014-11-07 19:04:45 -08:00
#if (EFI_PROD_CODE || EFI_SIMULATOR) || defined(__DOXYGEN__)
2014-09-08 15:02:52 -07:00
/**
* todo: this should probably become 'static', i.e. private, and propagated around explicitly?
*/
2014-11-25 09:05:03 -08:00
Engine _engine;
2014-11-07 19:04:45 -08:00
Engine * engine = &_engine;
#endif
2014-08-29 07:52:33 -07:00
2014-10-21 08:04:12 -07:00
/**
* I am not sure if this needs to be configurable.
*
* Also technically the whole feature might be implemented as cranking fuel coefficient curve by TPS.
*/
#define CLEANUP_MODE_TPS 95
2014-08-29 07:52:33 -07:00
static msg_t csThread(void) {
chRegSetThreadName("status");
#if EFI_SHAFT_POSITION_INPUT
2014-12-04 19:03:19 -08:00
while (true) {
2014-10-02 20:03:25 -07:00
int rpm = getRpm();
int is_cranking = isCrankingR(rpm);
int is_running = rpm > 0 && !is_cranking;
2014-08-29 07:52:33 -07:00
if (is_running) {
// blinking while running
setOutputPinValue(LED_RUNNING, 0);
chThdSleepMilliseconds(50);
setOutputPinValue(LED_RUNNING, 1);
chThdSleepMilliseconds(50);
} else {
// constant on while cranking and off if engine is stopped
setOutputPinValue(LED_RUNNING, is_cranking);
chThdSleepMilliseconds(100);
}
}
#endif /* EFI_SHAFT_POSITION_INPUT */
return -1;
}
static void updateErrorCodes(void) {
/**
* technically we can set error codes right inside the getMethods, but I a bit on a fence about it
*/
2014-11-07 19:04:45 -08:00
setError(isValidIntakeAirTemperature(getIntakeAirTemperature(engine)),
2014-10-07 08:04:35 -07:00
OBD_Intake_Air_Temperature_Circuit_Malfunction);
2014-11-07 19:04:45 -08:00
setError(isValidCoolantTemperature(getCoolantTemperature(engine)),
2014-10-07 08:04:35 -07:00
OBD_Engine_Coolant_Temperature_Circuit_Malfunction);
2014-08-29 07:52:33 -07:00
}
static void fanRelayControl(void) {
2014-11-10 07:03:20 -08:00
if (boardConfiguration->fanPin == GPIO_UNASSIGNED)
2014-08-29 07:52:33 -07:00
return;
int isCurrentlyOn = getOutputPinValue(FAN_RELAY);
int newValue;
if (isCurrentlyOn) {
// if the fan is already on, we keep it on till the 'fanOff' temperature
2014-11-07 19:04:45 -08:00
newValue = getCoolantTemperature(engine) > engineConfiguration->fanOffTemperature;
2014-08-29 07:52:33 -07:00
} else {
2014-11-07 19:04:45 -08:00
newValue = getCoolantTemperature(engine) > engineConfiguration->fanOnTemperature;
2014-08-29 07:52:33 -07:00
}
if (isCurrentlyOn != newValue) {
2014-11-29 21:03:06 -08:00
if (isRunningBenchTest())
return; // let's not mess with bench testing
2014-08-29 07:52:33 -07:00
scheduleMsg(&logger, "FAN relay: %s", newValue ? "ON" : "OFF");
setOutputPinValue(FAN_RELAY, newValue);
}
}
Overflow64Counter halTime;
uint64_t getTimeNowUs(void) {
2014-09-12 20:04:25 -07:00
return getTimeNowNt() / (CORE_CLOCK / 1000000);
}
uint64_t getTimeNowNt(void) {
2014-11-16 21:03:45 -08:00
return halTime.get();
2014-08-29 07:52:33 -07:00
}
efitimems_t currentTimeMillis(void) {
// todo: migrate to getTimeNowUs? or not?
return chTimeNow() / TICKS_IN_MS;
}
int getTimeNowSeconds(void) {
return chTimeNow() / CH_FREQUENCY;
}
2014-10-15 14:02:58 -07:00
static void cylinderCleanupControl(Engine *engine) {
bool newValue;
if (engineConfiguration->isCylinderCleanupEnabled) {
2014-11-24 19:03:19 -08:00
newValue = isCrankingE(engine) && getTPS(PASS_ENGINE_PARAMETER_F) > CLEANUP_MODE_TPS;
2014-10-15 14:02:58 -07:00
} else {
newValue = false;
}
2014-10-31 12:03:00 -07:00
if (newValue != engine->isCylinderCleanupMode) {
engine->isCylinderCleanupMode = newValue;
2014-10-15 14:02:58 -07:00
scheduleMsg(&logger, "isCylinderCleanupMode %s", boolToString(newValue));
}
2014-10-18 04:03:25 -07:00
}
2014-12-06 12:04:01 -08:00
static LECalculator calc;
extern LEElement * fsioLogics[LE_COMMAND_COUNT];
static void handleFsio(Engine *engine, int index) {
2014-12-05 18:04:42 -08:00
if (boardConfiguration->fsioPins[index] == GPIO_UNASSIGNED)
2014-10-25 05:03:11 -07:00
return;
2014-12-04 19:03:19 -08:00
bool_t isPwmMode = boardConfiguration->fsioFrequency[index] != 0;
2014-10-31 11:05:18 -07:00
io_pin_e pin = (io_pin_e) ((int) GPIO_0 + index);
2014-10-18 04:03:25 -07:00
2014-12-04 19:03:19 -08:00
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);
}
2014-10-25 05:03:11 -07:00
}
2014-10-15 14:02:58 -07:00
}
2014-11-05 20:03:20 -08:00
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)) {
2014-11-29 21:03:06 -08:00
if (isRunningBenchTest())
return; // let's not mess with bench testing
2014-11-05 20:03:20 -08:00
scheduleMsg(&logger, "setting %s %s", getIo_pin_e(ioPin), boolToString(value));
setOutputPinValue(ioPin, value);
}
}
}
2014-10-21 12:02:57 -07:00
static void onEvenyGeneralMilliseconds(Engine *engine) {
2014-08-29 07:52:33 -07:00
/**
* We need to push current value into the 64 bit counter often enough so that we do not miss an overflow
*/
2014-11-16 21:03:45 -08:00
bool alreadyLocked = lockAnyContext();
updateAndSet(&halTime.state, hal_lld_get_counter_value());
if (!alreadyLocked) {
unlockAnyContext();
}
2014-08-29 07:52:33 -07:00
2014-11-11 13:05:09 -08:00
if (!engine->rpmCalculator.isRunning())
2014-08-29 07:52:33 -07:00
writeToFlashIfPending();
2014-10-21 12:02:57 -07:00
engine->watchdog();
engine->updateSlowSensors();
2014-08-29 07:52:33 -07:00
2014-10-14 13:03:06 -07:00
for (int i = 0; i < LE_COMMAND_COUNT; i++) {
2014-12-06 12:04:01 -08:00
handleFsio(engine, i);
2014-10-14 13:03:06 -07:00
}
2014-10-07 08:04:35 -07:00
#if EFI_FUEL_PUMP
2014-11-10 07:03:20 -08:00
if (boardConfiguration->fuelPumpPin != GPIO_UNASSIGNED && engineConfiguration->isFuelPumpEnabled) {
2014-11-05 20:03:20 -08:00
setPinState(FUEL_PUMP_RELAY, fuelPumpLogic, engine);
2014-10-06 05:03:03 -07:00
}
2014-10-07 08:04:35 -07:00
#endif
2014-10-06 05:03:03 -07:00
2014-11-29 08:03:49 -08:00
if (boardConfiguration->acRelayPin != GPIO_UNASSIGNED) {
setPinState(AC_RELAY, acRelayLogic, engine);
}
2014-11-30 08:04:02 -08:00
if (boardConfiguration->alternatorControlPin != GPIO_UNASSIGNED) {
setPinState(ALTERNATOR_SWITCH, alternatorLogic, engine);
}
2014-08-29 07:52:33 -07:00
updateErrorCodes();
2014-11-05 20:03:20 -08:00
// todo: migrate this to flex logic
2014-08-29 07:52:33 -07:00
fanRelayControl();
2014-10-21 12:02:57 -07:00
cylinderCleanupControl(engine);
2014-10-15 14:02:58 -07:00
2014-11-11 13:05:09 -08:00
setOutputPinValue(O2_HEATER, engine->rpmCalculator.isRunning());
2014-08-29 07:52:33 -07:00
// schedule next invocation
chVTSetAny(&everyMsTimer, boardConfiguration->generalPeriodicThreadPeriod * TICKS_IN_MS,
2014-10-31 11:05:18 -07:00
(vtfunc_t) &onEvenyGeneralMilliseconds, engine);
2014-08-29 07:52:33 -07:00
}
2014-10-21 12:02:57 -07:00
static void initPeriodicEvents(Engine *engine) {
2014-08-29 07:52:33 -07:00
// schedule first invocation
chVTSetAny(&everyMsTimer, boardConfiguration->generalPeriodicThreadPeriod * TICKS_IN_MS,
2014-10-31 11:05:18 -07:00
(vtfunc_t) &onEvenyGeneralMilliseconds, engine);
2014-08-29 07:52:33 -07:00
}
char * getPinNameByAdcChannel(adc_channel_e hwChannel, char *buffer) {
strcpy((char*) buffer, portname(getAdcChannelPort(hwChannel)));
itoa10(&buffer[2], getAdcChannelPin(hwChannel));
return (char*) buffer;
}
static char pinNameBuffer[16];
static void printAnalogChannelInfoExt(const char *name, adc_channel_e hwChannel, float adcVoltage) {
float voltage = adcVoltage * engineConfiguration->analogInputDividerCoefficient;
2014-09-11 18:02:50 -07:00
scheduleMsg(&logger, "%s ADC%d %s %s rawValue=%f/divided=%fv", name, hwChannel, getAdcMode(hwChannel),
2014-08-29 07:52:33 -07:00
getPinNameByAdcChannel(hwChannel, pinNameBuffer), adcVoltage, voltage);
}
static void printAnalogChannelInfo(const char *name, adc_channel_e hwChannel) {
2014-11-26 20:03:05 -08:00
if (hwChannel != EFI_ADC_NONE) {
printAnalogChannelInfoExt(name, hwChannel, getVoltage(hwChannel));
}
2014-08-29 07:52:33 -07:00
}
static void printAnalogInfo(void) {
printAnalogChannelInfo("TPS", engineConfiguration->tpsAdcChannel);
printAnalogChannelInfo("CLT", engineConfiguration->cltAdcChannel);
2014-10-31 11:05:18 -07:00
if (engineConfiguration->hasIatSensor) {
printAnalogChannelInfo("IAT", engineConfiguration->iatAdcChannel);
}
2014-08-29 07:52:33 -07:00
printAnalogChannelInfo("MAF", engineConfiguration->mafAdcChannel);
printAnalogChannelInfo("AFR", engineConfiguration->afrSensor.afrAdcChannel);
printAnalogChannelInfo("MAP", engineConfiguration->map.sensor.hwChannel);
2014-10-31 11:05:18 -07:00
if (engineConfiguration->hasBaroSensor) {
printAnalogChannelInfo("BARO", engineConfiguration->baroSensor.hwChannel);
}
2014-11-26 20:03:05 -08:00
printAnalogChannelInfo("A/C sw", engineConfiguration->acSwitchAdc);
2014-11-06 10:04:30 -08:00
printAnalogChannelInfoExt("Vbatt", engineConfiguration->vbattAdcChannel, getVBatt(engineConfiguration));
2014-08-29 07:52:33 -07:00
}
static THD_WORKING_AREA(csThreadStack, UTILITY_THREAD_STACK_SIZE); // declare thread stack
2014-12-06 12:04:01 -08:00
static void showFsio(const char *msg, LEElement *element) {
2014-12-07 08:04:19 -08:00
if(msg!=NULL)
2014-12-06 12:04:01 -08:00
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, "<end>");
}
static void showFsioInfo(void) {
scheduleMsg(&logger, "sys used %d/user used %d", sysPool.getSize(), userPool.getSize());
showFsio("ac", acRelayLogic);
showFsio("fuel", fuelPumpLogic);
2014-12-06 13:03:17 -08:00
for (int i = 0; i < LE_COMMAND_COUNT; i++) {
char * exp = boardConfiguration->le_formulas[i];
if (exp[0] != 0) {
scheduleMsg(&logger, "FSIO #%d [%s] at %s@%dHz = %f", (i + 1), exp, hwPortname(boardConfiguration->fsioPins[i]),
boardConfiguration->fsioFrequency[i],
engineConfiguration2->fsioLastValue[i]);
2014-12-07 08:04:19 -08:00
scheduleMsg(&logger, "user-defined #%d value=%f", (i + 1), engine->engineConfiguration2->fsioLastValue[i]);
showFsio(NULL, fsioLogics[i]);
2014-12-06 13:03:17 -08:00
}
}
2014-12-06 12:04:01 -08:00
}
2014-12-04 19:03:19 -08:00
static void setFsioFrequency(int index, int frequency) {
index--;
2014-12-08 08:04:12 -08:00
if (index < 0 || index >= LE_COMMAND_COUNT) {
2014-12-04 19:03:19 -08:00
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;
2014-12-08 08:04:12 -08:00
if (index < 0 || index >= LE_COMMAND_COUNT) {
2014-12-04 19:03:19 -08:00
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;
}
2014-12-05 18:04:42 -08:00
boardConfiguration->fsioPins[index] = pin;
2014-12-04 19:03:19 -08:00
scheduleMsg(&logger, "FSIO pin #%d [%s]", (index + 1), hwPortname(pin));
}
2014-10-13 10:03:07 -07:00
static void setUserOutput(const char *indexStr, const char *quotedLine, Engine *engine) {
2014-12-04 19:03:19 -08:00
int index = atoi(indexStr) - 1;
2014-12-08 08:04:12 -08:00
if (index < 0 || index >= LE_COMMAND_COUNT) {
2014-10-13 10:03:07 -07:00
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;
}
2014-12-04 19:03:19 -08:00
scheduleMsg(&logger, "setting user out #%d to [%s]", index + 1, l);
2014-10-13 10:03:07 -07:00
strcpy(engine->engineConfiguration->bc.le_formulas[index], l);
2014-12-07 15:03:08 -08:00
// this would apply the changes
parseUserFsio(PASS_ENGINE_PARAMETER_F);
showFsioInfo();
2014-10-13 10:03:07 -07:00
}
2014-12-03 08:03:52 -08:00
static void setInt(const char *offsetStr, const char *valueStr) {
}
2014-12-04 05:03:27 -08:00
static void getInt(int offset) {
2014-12-04 19:03:19 -08:00
int *ptr = (int *) (&((char *) engine->engineConfiguration)[offset]);
2014-12-04 05:03:27 -08:00
int value = *ptr;
scheduleMsg(&logger, "int @%d is %d", offset, value);
}
2014-12-03 08:03:52 -08:00
static void getFloat(int offset) {
2014-12-04 19:03:19 -08:00
float *ptr = (float *) (&((char *) engine->engineConfiguration)[offset]);
2014-12-03 08:03:52 -08:00
float value = *ptr;
scheduleMsg(&logger, "float @%d is %f", offset, value);
}
2014-12-03 05:04:17 -08:00
2014-12-03 08:03:52 -08:00
static void setFloat(const char *offsetStr, const char *valueStr) {
int offset = atoi(offsetStr);
if (absI(offset) == absI(ERROR_CODE)) {
scheduleMsg(&logger, "invalid offset [%s]", offsetStr);
return;
}
float value = atoff(valueStr);
if (cisnan(value)) {
scheduleMsg(&logger, "invalid value [%s]", valueStr);
return;
}
2014-12-04 19:03:19 -08:00
float *ptr = (float *) (&((char *) engine->engineConfiguration)[offset]);
2014-12-03 08:03:52 -08:00
*ptr = value;
scheduleMsg(&logger, "setting float @%d to %f", offset, value);
2014-12-03 05:04:17 -08:00
}
2014-10-25 05:03:11 -07:00
static pin_output_mode_e d = OM_DEFAULT;
2014-10-21 12:02:57 -07:00
void initEngineContoller(Engine *engine) {
2014-09-11 18:02:50 -07:00
if (hasFirmwareError()) {
2014-08-29 07:52:33 -07:00
return;
2014-09-11 18:02:50 -07:00
}
2014-08-29 07:52:33 -07:00
initLogging(&logger, "Engine Controller");
2014-11-07 08:08:15 -08:00
initSensors(engine);
2014-08-29 07:52:33 -07:00
initPwmGenerator();
#if EFI_ANALOG_CHART
initAnalogChart();
#endif /* EFI_ANALOG_CHART */
initAlgo(engineConfiguration);
#if EFI_WAVE_ANALYZER
2014-09-11 20:02:56 -07:00
if (engineConfiguration->isWaveAnalyzerEnabled) {
initWaveAnalyzer();
}
2014-08-29 07:52:33 -07:00
#endif /* EFI_WAVE_ANALYZER */
#if EFI_SHAFT_POSITION_INPUT
/**
* there is an implicit dependency on the fact that 'tachometer' listener is the 1st listener - this case
* other listeners can access current RPM value
*/
2014-11-08 09:03:07 -08:00
initRpmCalculator(engine);
2014-08-29 07:52:33 -07:00
#endif /* EFI_SHAFT_POSITION_INPUT */
#if EFI_TUNER_STUDIO
2014-09-11 20:02:56 -07:00
if (engineConfiguration->isTunerStudioEnabled) {
startTunerStudioConnectivity();
}
2014-08-29 07:52:33 -07:00
#endif
// multiple issues with this initMapAdjusterThread();
2014-10-21 12:02:57 -07:00
initPeriodicEvents(engine);
2014-08-29 07:52:33 -07:00
chThdCreateStatic(csThreadStack, sizeof(csThreadStack), LOWPRIO, (tfunc_t) csThread, NULL);
2014-11-05 20:03:20 -08:00
initInjectorCentral(engine);
2014-08-29 07:52:33 -07:00
initPwmTester();
initIgnitionCentral();
2014-11-10 08:04:09 -08:00
/**
* This has to go after 'initInjectorCentral' and 'initInjectorCentral' in order to
* properly detect un-assigned output pins
*/
prepareShapes(engine);
2014-08-29 07:52:33 -07:00
initMalfunctionCentral();
#if EFI_ELECTRONIC_THROTTLE_BODY
initElectronicThrottle();
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
#if EFI_MALFUNCTION_INDICATOR
2014-09-11 20:02:56 -07:00
if (engineConfiguration->isMilEnabled) {
initMalfunctionIndicator();
}
2014-08-29 07:52:33 -07:00
#endif /* EFI_MALFUNCTION_INDICATOR */
#if EFI_MAP_AVERAGING
2014-09-11 20:02:56 -07:00
if (engineConfiguration->isMapAveragingEnabled) {
initMapAveraging();
}
2014-08-29 07:52:33 -07:00
#endif /* EFI_MAP_AVERAGING */
#if EFI_ENGINE_CONTROL
2014-09-11 18:02:50 -07:00
if (boardConfiguration->isEngineControlEnabled) {
/**
* This method initialized the main listener which actually runs injectors & ignition
*/
2014-10-21 12:02:57 -07:00
initMainEventListener(engine, engineConfiguration2);
2014-09-11 18:02:50 -07:00
}
2014-08-29 07:52:33 -07:00
#endif /* EFI_ENGINE_CONTROL */
#if EFI_IDLE_CONTROL
2014-09-11 20:02:56 -07:00
if (engineConfiguration->isIdleThreadEnabled) {
2014-10-22 14:03:06 -07:00
startIdleThread(engine);
2014-09-11 20:02:56 -07:00
}
2014-08-29 07:52:33 -07:00
#else
scheduleMsg(&logger, "no idle control");
#endif
#if EFI_FUEL_PUMP
2014-12-06 12:04:01 -08:00
fuelPumpLogic = sysPool.parseExpression(FUEL_PUMP_LOGIC);
2014-10-07 08:04:35 -07:00
#endif
2014-10-06 02:03:01 -07:00
2014-12-06 12:04:01 -08:00
acRelayLogic = sysPool.parseExpression(AC_RELAY_LOGIC);
2014-11-29 08:03:49 -08:00
2014-12-06 12:04:01 -08:00
alternatorLogic = sysPool.parseExpression(ALTERNATOR_LOGIC);
2014-11-30 08:04:02 -08:00
2014-08-29 07:52:33 -07:00
addConsoleAction("analoginfo", printAnalogInfo);
2014-10-13 10:03:07 -07:00
2014-10-13 11:03:07 -07:00
for (int i = 0; i < LE_COMMAND_COUNT; i++) {
2014-12-05 18:04:42 -08:00
brain_pin_e brainPin = boardConfiguration->fsioPins[i];
2014-12-04 19:03:19 -08:00
if (brainPin != GPIO_UNASSIGNED) {
2014-10-25 05:03:11 -07:00
//mySetPadMode2("user-defined", boardConfiguration->gpioPins[i], PAL_STM32_MODE_OUTPUT);
2014-10-13 11:03:07 -07:00
2014-10-31 11:05:18 -07:00
io_pin_e pin = (io_pin_e) ((int) GPIO_0 + i);
2014-12-04 19:03:19 -08:00
int frequency = boardConfiguration->fsioFrequency[i];
if (frequency == 0) {
2014-12-05 18:04:42 -08:00
outputPinRegisterExt2(getPinName(pin), pin, boardConfiguration->fsioPins[i], &d);
2014-12-04 19:03:19 -08:00
} else {
startSimplePwmExt(&fsioPwm[i], "FSIO", brainPin, pin, frequency, 0.5f, applyPinState);
}
2014-10-13 11:03:07 -07:00
}
}
2014-12-04 17:03:09 -08:00
addConsoleActionSSP("set_fsio", (VoidCharPtrCharPtrVoidPtr) setUserOutput, engine);
2014-12-04 19:03:19 -08:00
addConsoleActionSS("set_fsio_pin", (VoidCharPtrCharPtr) setFsioPin);
addConsoleActionII("set_fsio_frequency", (VoidIntInt) setFsioFrequency);
2014-12-03 08:03:52 -08:00
addConsoleActionSS("set_float", (VoidCharPtrCharPtr) setFloat);
addConsoleActionSS("set_int", (VoidCharPtrCharPtr) setInt);
addConsoleActionI("get_float", getFloat);
2014-12-04 05:03:27 -08:00
addConsoleActionI("get_int", getInt);
2014-12-06 12:04:01 -08:00
addConsoleAction("fsioinfo", showFsioInfo);
2014-11-18 18:05:41 -08:00
initEval(engine);
2014-08-29 07:52:33 -07:00
}