rusEFI
The most advanced open source ECU
Functions
engine_controller.h File Reference

Detailed Description

Controllers package entry point header.

Date
Feb 7, 2013
Author
Andrey Belomutskiy, (c) 2012-2020

Definition in file engine_controller.h.

Functions

bool validateConfigOnStartUpOrBurn ()
 
char * getPinNameByAdcChannel (const char *msg, adc_channel_e hwChannel, char *buffer, size_t bufferSize)
 
void initPeriodicEvents ()
 
void initRealHardwareEngineController ()
 
void commonEarlyInit ()
 
void commonInitEngineController ()
 
void initStartStopButton ()
 
void initWarningRunningPins ()
 
void initDataStructures ()
 
void slowStartStopButtonCallback ()
 

Function Documentation

◆ commonEarlyInit()

void commonEarlyInit ( )

Initialize hardware drivers

Definition at line 675 of file engine_controller.cpp.

675  {
676  // Start this early - it will start LED blinking and such
678 
679 #if EFI_SHAFT_POSITION_INPUT
680  // todo: figure out better startup logic
682 #endif /* EFI_SHAFT_POSITION_INPUT */
683 
684  /**
685  * Initialize hardware drivers
686  */
687  initHardware();
688 
690 
691 #if EFI_FILE_LOGGING
692  initMmcCard();
693 #endif /* EFI_FILE_LOGGING */
694 
695 #if EFI_ENGINE_EMULATOR
697 #endif
698 
699 #if EFI_LUA
700  startLua();
701 #endif // EFI_LUA
702 
703 #if EFI_CAN_SERIAL
704  // needs to be called after initCan() inside initHardware()
705  startCanConsole();
706 #endif /* EFI_CAN_SERIAL */
707 
708 #if HW_CHECK_ALWAYS_STIMULATE
709  // we need a special binary for final assembly check. We cannot afford to require too much software or too many steps
710  // to be executed at the place of assembly
711  enableTriggerStimulator(/*incGlobalConfiguration*/false);
712 #endif // HW_CHECK_ALWAYS_STIMULATE
713 }
void initQcBenchControls()
void initEngineEmulator()
void initHardware()
Definition: hardware.cpp:550
void startLua()
Definition: lua.cpp:386
void initMmcCard()
Definition: mmc_card.cpp:636
void startStatusThreads()
void initTriggerCentral()
void enableTriggerStimulator(bool incGlobalConfiguration)
void startCanConsole()

Referenced by runRusEfiWithConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ commonInitEngineController()

void commonInitEngineController ( )

This has to go after 'enginePins.startPins()' in order to properly detect un-assigned output pins

Definition at line 407 of file engine_controller.cpp.

407  {
408 #if EFI_PROD_CODE
409  addConsoleAction("sensorinfo", printSensorInfo);
410  addConsoleAction("reset_accel", resetAccel);
411 #endif /* EFI_PROD_CODE */
412 
413 #if EFI_SIMULATOR || EFI_UNIT_TEST
414  printf("commonInitEngineController\n");
415 #endif
416 
417 #if !EFI_UNIT_TEST
419 #endif /* EFI_UNIT_TEST */
420 
421 #if EFI_ENGINE_CONTROL
422  /**
423  * This has to go after 'enginePins.startPins()' in order to
424  * properly detect un-assigned output pins
425  */
427 
429 #endif // EFI_ENGINE_CONTROL
430 
431 #if EFI_SENSOR_CHART
432  initSensorChart();
433 #endif /* EFI_SENSOR_CHART */
434 
435 #if EFI_PROD_CODE || EFI_SIMULATOR
436  initSettings();
437 
438  if (hasFirmwareError()) {
439  return;
440  }
441 #endif
442 
443 #if ! EFI_UNIT_TEST && EFI_ENGINE_CONTROL
444  initBenchTest();
445 #endif /* ! EFI_UNIT_TEST && EFI_ENGINE_CONTROL */
446 
447 #if EFI_ALTERNATOR_CONTROL
449 #endif /* EFI_ALTERNATOR_CONTROL */
450 
451 #if EFI_VVT_PID
453 #endif /* EFI_VVT_PID */
454 
455 #if EFI_MALFUNCTION_INDICATOR
457 #endif /* EFI_MALFUNCTION_INDICATOR */
458 
459 #if !EFI_UNIT_TEST
460  // This is tested independently - don't configure sensors for tests.
461  // This lets us selectively mock them for each test.
462  initNewSensors();
463 #endif /* EFI_UNIT_TEST */
464 
465  initSensors();
466 
468 
469  initScriptImpl();
470 
471  initGpPwm();
472 
473 #if EFI_IDLE_CONTROL
474  startIdleThread();
475 #endif /* EFI_IDLE_CONTROL */
476 
477 #if EFI_TCU
479 #endif
480 
482 
483 #if EFI_ELECTRONIC_THROTTLE_BODY
485 #endif /* EFI_ELECTRONIC_THROTTLE_BODY */
486 
487 #if EFI_MAP_AVERAGING
490  }
491 #endif /* EFI_MAP_AVERAGING */
492 
493 #if EFI_BOOST_CONTROL
494  initBoostCtrl();
495 #endif /* EFI_BOOST_CONTROL */
496 
497 #if EFI_LAUNCH_CONTROL
499 #endif
500 
502 
503 #if EFI_UNIT_TEST
505 #endif /* EFI_UNIT_TEST */
506 
507 #if EFI_AUX_VALVES
508  initAuxValves();
509 #endif /* EFI_AUX_VALVES */
510 
511  initTachometer();
512  initSpeedometer();
513 }
void initAccelEnrichment()
void initIgnitionAdvanceControl()
void initSensors()
Definition: allsensors.cpp:14
void initAlternatorCtrl()
void initAuxValves()
Definition: aux_valves.cpp:56
void initBenchTest()
Definition: bench_test.cpp:640
void initBoostCtrl()
FuelSchedule injectionEvents
Definition: engine.h:263
RpmCalculator rpmCalculator
Definition: engine.h:280
void addFuelEvents()
bool Register()
Definition: sensor.cpp:131
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void initButtonDebounce()
void initElectronicThrottle()
void prepareOutputSignals()
Engine * engine
static void printSensorInfo()
static void initConfigActions()
static void resetAccel()
void initGearController()
void initGpPwm()
Definition: gppwm.cpp:31
void startIdleThread()
void initNewSensors()
void initLaunchControl()
void initMalfunctionIndicator(void)
void initMapAveraging()
engine_configuration_s * engineConfiguration
void initScriptImpl()
Definition: script_impl.cpp:82
void initSensorChart(void)
void initSettings()
Definition: settings.cpp:629
void initSpeedometer()
Definition: speedometer.cpp:25
void initTachometer()
Definition: tachometer.cpp:67
printf("\n")
void initVvtActuators()
Definition: vvt.cpp:183

Referenced by initRealHardwareEngineController().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getPinNameByAdcChannel()

char* getPinNameByAdcChannel ( const char *  msg,
adc_channel_e  hwChannel,
char *  buffer,
size_t  bufferSize 
)

Definition at line 233 of file engine_controller.cpp.

233  {
234 #if HAL_USE_ADC
235  if (!isAdcChannelValid(hwChannel)) {
236  snprintf(buffer, bufferSize, "NONE");
237  } else {
238  const char *name = portname(getAdcChannelPort(msg, hwChannel));
239  snprintf(buffer, bufferSize, "%s%d", name ? name : "null", getAdcChannelPin(hwChannel));
240  }
241 #else
242  snprintf(buffer, bufferSize, "NONE");
243 #endif /* HAL_USE_ADC */
244  return buffer;
245 }
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition: adc_inputs.h:20
int getAdcChannelPin(adc_channel_e hwChannel)
ioportid_t getAdcChannelPort(const char *msg, adc_channel_e hwChannel)
const char * portname(ioportid_t GPIOx)
static BigBufferHandle buffer

Referenced by AdcSubscription::PrintInfo(), and printMAPInfo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initDataStructures()

void initDataStructures ( )

Definition at line 105 of file engine_controller.cpp.

105  {
106 #if EFI_ENGINE_CONTROL
107  initFuelMap();
110  for (size_t i=0;i<efi::size(events.elements);i++) {
111  // above-zero value helps distinguish events
112  events.elements[i].sparkCounter = 1;
113  }
114  // above-zero value helps distinguish events
116 #endif // EFI_ENGINE_CONTROL
117 }
IgnitionEventList ignitionEvents
Definition: engine.h:264
EngineState engineState
Definition: engine.h:317
void initFuelMap()
Initialize fuel map data structure.
Definition: fuel_math.cpp:352
void initSpeedDensity()
composite packet size
static std::vector< CompositeEvent > events

Referenced by runRusEfi().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initPeriodicEvents()

void initPeriodicEvents ( )

Definition at line 228 of file engine_controller.cpp.

228  {
229  slowController.start();
230  fastController.start();
231 }
static PeriodicFastController fastController
static PeriodicSlowController slowController

Referenced by runRusEfi().

Here is the caller graph for this function:

◆ initRealHardwareEngineController()

void initRealHardwareEngineController ( )

Definition at line 716 of file engine_controller.cpp.

716  {
719 
720 #if EFI_LOGIC_ANALYZER
723  }
724 #endif /* EFI_LOGIC_ANALYZER */
725 
726  if (hasFirmwareError()) {
727  return;
728  }
729 
730  engineStateBlinkingTask.start();
731 
733 }
static EngineStateBlinkingTask engineStateBlinkingTask
void commonInitEngineController()
void initWaveAnalyzer()
void initWarningRunningPins()
void initVrThresholdPwm()
Definition: vr_pwm.cpp:39

Referenced by runRusEfiWithConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initStartStopButton()

void initStartStopButton ( )

See test_start_stop.cpp

Definition at line 11 of file start_stop.cpp.

11  {
12  /* startCrankingDuration is efitimesec_t, so we need to multiply it by 1000 to get milliseconds*/
17 }
void init(efitimems_t threshold, brain_pin_e &pin, pin_input_mode_e &mode, bool inverted=false)
Definition: debounce.cpp:23
StartStopState startStopState
Definition: engine.h:95
ButtonDebounce startStopButtonDebounce
Definition: start_stop.h:6

Referenced by startHardware().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initWarningRunningPins()

void initWarningRunningPins ( )

Definition at line 230 of file status_loop.cpp.

230  {
231 #if EFI_PROD_CODE
232  // open question if we need warningLedPin and runningLedPin at all!
233  enginePins.warningLedPin.initPin("led: warning status", getWarningLedPin(), LED_PIN_MODE, true);
234  enginePins.runningLedPin.initPin("led: running status", getRunningLedPin(), LED_PIN_MODE, true);
235 #endif /* EFI_PROD_CODE */
236 }
Gpio getWarningLedPin()
Gpio getRunningLedPin()
OutputPin runningLedPin
Definition: efi_gpio.h:106
OutputPin warningLedPin
Definition: efi_gpio.h:105
void initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e outputMode, bool forceInitWithFatalError=false)
Definition: efi_gpio.cpp:695
EnginePins enginePins
Definition: efi_gpio.cpp:24

Referenced by initRealHardwareEngineController().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ slowStartStopButtonCallback()

void slowStartStopButtonCallback ( )

Definition at line 56 of file start_stop.cpp.

56  {
57  if (!isIgnVoltage()) {
58  // nothing to crank if we are powered only via USB
60  return;
61  } else if (engine->startStopState.isFirstTime) {
62  // initialize when first time with proper power
65  }
66 
68  // where are odd cases of start button combined with ECU power source button we do not want to crank right on start
69  return;
70  }
71 
74  return;
75  }
76 
77  if (isCrankingSuppressed()) {
78  return;
79  }
80  }
81 
83 
85  // we are here on transition from 0 to 1
87  }
88  // todo: we shall extract start_stop.txt from engine_state.txt
91 
92  bool isStarterEngaged = enginePins.starterControl.getLogicValue();
93 
94  if (isStarterEngaged) {
96  }
97 }
bool readPinEvent()
bool getPhysicalState()
SwitchedState brakePedalSwitchedState
Definition: engine.h:191
RegisteredOutputPin starterControl
Definition: efi_gpio.h:82
bool getLogicValue() const
Definition: efi_gpio.cpp:651
bool isStopped() const override
bool isIgnVoltage()
startStopState("startStopState", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1169, 1.0, -1.0, -1.0, "")
static void onStartStopButtonToggle()
Definition: start_stop.cpp:19
PUBLIC_API_WEAK bool isCrankingSuppressed()
Definition: start_stop.cpp:52
static void disengageStarterIfNeeded()
Definition: start_stop.cpp:35
Timer timeSinceIgnitionPower
Definition: start_stop.h:7
bool isFirstTime
Definition: start_stop.h:10

Referenced by doPeriodicSlowCallback().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ validateConfigOnStartUpOrBurn()

bool validateConfigOnStartUpOrBurn ( )

Definition at line 520 of file engine_controller.cpp.

520  {
521  if (!validateBoardConfig()) {
522  return false;
523  }
524  if (engineConfiguration->cylindersCount > MAX_CYLINDER_COUNT) {
525  criticalError("Invalid cylinder count: %d", engineConfiguration->cylindersCount);
526  return false;
527  }
528  if (engineConfiguration->adcVcc > 5.0f || engineConfiguration->adcVcc < 1.0f) {
529  criticalError("Invalid adcVcc: %f", engineConfiguration->adcVcc);
530  return false;
531  }
534  }
535 
537 
538 #if EFI_ENGINE_CONTROL
539  // Fueling
540  {
543 
544  ensureArrayIsAscending("Lambda/AFR load", config->lambdaLoadBins);
545  ensureArrayIsAscending("Lambda/AFR RPM", config->lambdaRpmBins);
546 
547  ensureArrayIsAscending("Fuel CLT mult", config->cltFuelCorrBins);
548  ensureArrayIsAscending("Fuel IAT mult", config->iatFuelCorrBins);
549 
552 
553  ensureArrayIsAscending("Injection phase load", config->injPhaseLoadBins);
554  ensureArrayIsAscending("Injection phase RPM", config->injPhaseRpmBins);
555 
559 
562 
565 
566  ensureArrayIsAscendingOrDefault("TPS TPS RPM correction", config->tpsTspCorrValuesBins);
567 
570  }
571 
572  // Ignition
573  {
575 
580 
581  ensureArrayIsAscending("Ignition CLT corr", config->cltTimingBins);
582 
583  ensureArrayIsAscending("Ignition IAT corr IAT", config->ignitionIatCorrTempBins);
584  ensureArrayIsAscending("Ignition IAT corr Load", config->ignitionIatCorrLoadBins);
585  }
586 
589 #endif // EFI_ENGINE_CONTROL
590 
597 
598 // todo: huh? why does this not work on CI? ensureArrayIsAscendingOrDefault("Dwell Correction Voltage", engineConfiguration->dwellVoltageCorrVoltBins);
599 
600  ensureArrayIsAscending("MAF transfer function", config->mafDecodingBins);
601 
602  // Cranking tables
603  ensureArrayIsAscending("Cranking fuel mult", config->crankingFuelBins);
604  ensureArrayIsAscending("Cranking duration", config->crankingCycleBins);
607 
608  // Idle tables
609  ensureArrayIsAscending("Idle target RPM", config->cltIdleRpmBins);
610  ensureArrayIsAscending("Idle warmup mult", config->cltIdleCorrBins);
615 
616  for (size_t index = 0; index < efi::size(engineConfiguration->vrThreshold); index++) {
617  auto& cfg = engineConfiguration->vrThreshold[index];
618 
619  if (cfg.pin == Gpio::Unassigned) {
620  continue;
621  }
622  ensureArrayIsAscending("VR threshold", cfg.rpmBins);
623  }
624 
625 #if EFI_BOOST_CONTROL
626  // Boost
627  ensureArrayIsAscending("Boost control Load", config->boostLoadBins);
628  ensureArrayIsAscending("Boost control RPM", config->boostRpmBins);
629 #endif // EFI_BOOST_CONTROL
630 
631 #if EFI_ANTILAG_SYSTEM
632  // ALS
637 #endif // EFI_ANTILAG_SYSTEM
638 
639 #if EFI_ELECTRONIC_THROTTLE_BODY
640  // ETB
643 #endif // EFI_ELECTRONIC_THROTTLE_BODY
644 
645  if (isGdiEngine()) {
649  ensureArrayIsAscending("HPFP target rpm", config->hpfpTargetRpmBins);
650  ensureArrayIsAscending("HPFP target load", config->hpfpTargetLoadBins);
651  }
652 
653  // VVT
655  ensureArrayIsAscending("VVT intake load", config->vvtTable1LoadBins);
656  ensureArrayIsAscending("VVT intake RPM", config->vvtTable1RpmBins);
657  }
658 
659 #if CAM_INPUTS_COUNT != 1
661  ensureArrayIsAscending("VVT exhaust load", config->vvtTable2LoadBins);
662  ensureArrayIsAscending("VVT exhaust RPM", config->vvtTable2RpmBins);
663  }
664 #endif
665 
667  ensureArrayIsAscending("Oil pressure protection", config->minimumOilPressureBins);
668  }
669 
670  return true;
671 }
@ Unassigned
void ensureArrayIsAscendingOrDefault(const char *msg, const TValue(&values)[TSize])
void ensureArrayIsAscending(const char *msg, const TValue(&values)[TSize])
PUBLIC_API_WEAK bool validateBoardConfig()
bool isGdiEngine()
persistent_config_s * config
bool isBrainPinValid(brain_pin_e brainPin)
scaled_channel< uint16_t, 100, 1 > tractionControlSlipBins[TRACTION_CONTROL_ETB_DROP_SIZE]
uint8_t tractionControlSpeedBins[TRACTION_CONTROL_ETB_DROP_SIZE]
float battLagCorrBins[VBAT_INJECTOR_CURVE_SIZE]
scaled_channel< uint8_t, 2, 1 > hpfpLobeProfileQuantityBins[HPFP_LOBE_PROFILE_SIZE]
scaled_channel< uint8_t, 1, 100 > iacCoastingRpmBins[CLT_CURVE_SIZE]
scaled_channel< uint8_t, 1, 10 > idleVeRpmBins[IDLE_VE_SIZE]
scaled_channel< uint16_t, 1000, 1 > fuelLevelBins[FUEL_LEVEL_TABLE_COUNT]
scaled_channel< uint8_t, 1, 100 > pedalToTpsRpmBins[PEDAL_TO_TPS_SIZE]
scaled_channel< uint8_t, 1, 50 > hpfpTargetRpmBins[HPFP_TARGET_SIZE]
scaled_channel< uint8_t, 1, 50 > tpsTspCorrValuesBins[TPS_TPS_ACCEL_CLT_CORR_TABLE]
scaled_channel< int8_t, 1, 2 > cltIdleRpmBins[CLT_CURVE_SIZE]
scaled_channel< uint8_t, 1, 100 > boostRpmBins[BOOST_RPM_COUNT]
scaled_channel< uint16_t, 100, 1 > mapEstimateTpsBins[FUEL_LOAD_COUNT]
scaled_channel< uint8_t, 1, 50 > hpfpCompensationRpmBins[HPFP_COMPENSATION_SIZE]
scaled_channel< uint8_t, 1, 50 > idleAdvanceBins[IDLE_ADVANCE_CURVE_SIZE]
scaled_channel< uint16_t, 10, 1 > hpfpTargetLoadBins[HPFP_TARGET_SIZE]
scaled_channel< uint8_t, 1, 100 > minimumOilPressureBins[8]
scaled_channel< uint8_t, 1, 5 > ignitionIatCorrLoadBins[8]

Referenced by handleBurnCommand(), and runRusEfiWithConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

Go to the source code of this file.