rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
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 ()
 
bool validateConfigOnStartUpOrBurn (bool isRunningOnBurn)
 
chargetPinNameByAdcChannel (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 719 of file engine_controller.cpp.

719 {
720 // Start this early - it will start LED blinking and such
722
723#if EFI_SHAFT_POSITION_INPUT
724 // todo: figure out better startup logic
726#endif /* EFI_SHAFT_POSITION_INPUT */
727
728 /**
729 * Initialize hardware drivers
730 */
731 initHardware();
732
734
735#if EFI_FILE_LOGGING
736 initMmcCard();
737#endif /* EFI_FILE_LOGGING */
738
739#if EFI_ENGINE_EMULATOR
741#endif
742
743#if EFI_LUA
744 startLua();
745#endif // EFI_LUA
746
747#if EFI_CAN_SERIAL
748 // needs to be called after initCan() inside initHardware()
750#endif /* EFI_CAN_SERIAL */
751
752}
void initQcBenchControls()
void initEngineEmulator()
void initHardware()
Definition hardware.cpp:540
void startLua()
Definition lua.cpp:281
void initMmcCard()
void startStatusThreads()
void initTriggerCentral()
void startCanConsole()

Referenced by initEfiWithConfig().

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 386 of file engine_controller.cpp.

386 {
387#if EFI_PROD_CODE
388 addConsoleAction("sensorinfo", printSensorInfo);
389 addConsoleAction("reset_accel", resetAccel);
390#endif /* EFI_PROD_CODE */
391
392#if EFI_SIMULATOR || EFI_UNIT_TEST
393 printf("commonInitEngineController\n");
394#endif
395
396#if !EFI_UNIT_TEST
398#endif /* EFI_UNIT_TEST */
399
400#if EFI_ENGINE_CONTROL
401 /**
402 * This has to go after 'enginePins.startPins()' in order to
403 * properly detect un-assigned output pins
404 */
406
408#endif // EFI_ENGINE_CONTROL
409
410
411#if EFI_PROD_CODE || EFI_SIMULATOR
412 initSettings();
413
414 if (hasFirmwareError()) {
415 return;
416 }
417#endif
418
419#if ! EFI_UNIT_TEST && EFI_ENGINE_CONTROL
421#endif /* ! EFI_UNIT_TEST && EFI_ENGINE_CONTROL */
422
423#if EFI_ALTERNATOR_CONTROL
425#endif /* EFI_ALTERNATOR_CONTROL */
426
427#if EFI_VVT_PID
429#endif /* EFI_VVT_PID */
430
431#if EFI_MALFUNCTION_INDICATOR
433#endif /* EFI_MALFUNCTION_INDICATOR */
434
435#if !EFI_UNIT_TEST
436 // This is tested independently - don't configure sensors for tests.
437 // This lets us selectively mock them for each test.
439#endif /* EFI_UNIT_TEST */
440
441 initSensors();
442
444
446
447 initGpPwm();
448
449#if EFI_IDLE_CONTROL
451#endif /* EFI_IDLE_CONTROL */
452
453#if EFI_TCU
455#endif
456
458
459#if EFI_ELECTRONIC_THROTTLE_BODY
461#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
462
463#if EFI_MAP_AVERAGING && defined (MODULE_MAP_AVERAGING)
464 engine->module<MapAveragingModule>()->init();
465#else
466 efiPrintf("No MapAveraging support!");
467#endif /* EFI_MAP_AVERAGING */
468
469#if EFI_BOOST_CONTROL
471#endif /* EFI_BOOST_CONTROL */
472
473#if EFI_LAUNCH_CONTROL
475#endif
476
478
479#if EFI_UNIT_TEST
481#endif /* EFI_UNIT_TEST */
482
483#if EFI_AUX_VALVES
485#endif /* EFI_AUX_VALVES */
486
487#ifdef MODULE_TACHOMETER
488 engine->module<TachometerModule>()->init();
489#endif
490
492
493 initStft();
494#if EFI_LTFT_CONTROL
495 initLtft();
496#endif
497}
void initAccelEnrichment()
void initIgnitionAdvanceControl()
void initSensors()
void initAlternatorCtrl()
void initAuxValves()
void initBenchTest()
void initBoostCtrl()
FuelSchedule injectionEvents
Definition engine.h:288
RpmCalculator rpmCalculator
Definition engine.h:306
constexpr auto & module()
Definition engine.h:200
bool Register()
Definition sensor.cpp:131
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void initStft(void)
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 initLtft()
void initMalfunctionIndicator(void)
void initScriptImpl()
void initSettings()
Definition settings.cpp:637
void initSpeedometer()
printf("\n")
void initVvtActuators()
Definition vvt.cpp:190

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 212 of file engine_controller.cpp.

212 {
213#if HAL_USE_ADC
214 if (!isAdcChannelValid(hwChannel)) {
215 snprintf(buffer, bufferSize, "NONE");
216 } else {
217 const char *name = portname(getAdcChannelPort(msg, hwChannel));
218 snprintf(buffer, bufferSize, "%s%d", name ? name : "null", getAdcChannelPin(hwChannel));
219 }
220#else
221 snprintf(buffer, bufferSize, "NONE");
222#endif /* HAL_USE_ADC */
223 return buffer;
224}
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition adc_inputs.h:23
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 102 of file engine_controller.cpp.

102 {
103#if EFI_ENGINE_CONTROL
104 initFuelMap();
107 for (size_t i=0;i<efi::size(events.elements);i++) {
108 // above-zero value helps distinguish events
110 }
111 // above-zero value helps distinguish events
113#endif // EFI_ENGINE_CONTROL
114}
IgnitionEventList ignitionEvents
Definition engine.h:289
EngineState engineState
Definition engine.h:344
uint32_t sparkCounter
IgnitionEvent elements[MAX_CYLINDER_COUNT]
void initFuelMap()
Initialize fuel map data structure.
void initSpeedDensity()
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 207 of file engine_controller.cpp.

207 {
208 slowController.start();
209 fastController.start();
210}
static PeriodicFastController fastController
static PeriodicSlowController slowController

Referenced by runRusEfi().

Here is the caller graph for this function:

◆ initRealHardwareEngineController()

void initRealHardwareEngineController ( )

Definition at line 755 of file engine_controller.cpp.

755 {
758
759#if EFI_LOGIC_ANALYZER
762 }
763#endif /* EFI_LOGIC_ANALYZER */
764
765 if (hasFirmwareError()) {
766 return;
767 }
768
770
772}
static constexpr engine_configuration_s * engineConfiguration
static EngineStateBlinkingTask engineStateBlinkingTask
void commonInitEngineController()
void initWaveAnalyzer()
void initWarningRunningPins()
void initVrThresholdPwm()
Definition vr_pwm.cpp:39

Referenced by initEfiWithConfig().

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:106
static EngineAccessor engine
Definition engine.h:413
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 226 of file status_loop.cpp.

226 {
227#if EFI_PROD_CODE
228 // open question if we need warningLedPin and runningLedPin at all!
229 enginePins.warningLedPin.initPin("led: warning status", getWarningLedPin(), LED_PIN_MODE, true);
230 enginePins.runningLedPin.initPin("led: running status", getRunningLedPin(), LED_PIN_MODE, true);
231#endif /* EFI_PROD_CODE */
232}
Gpio getWarningLedPin()
Gpio getRunningLedPin()
OutputPin runningLedPin
Definition efi_gpio.h:108
OutputPin warningLedPin
Definition efi_gpio.h:107
void initPin(const char *msg, brain_pin_e brainPin, pin_output_mode_e outputMode, bool forceInitWithFatalError=false)
Definition efi_gpio.cpp:711
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 60 of file start_stop.cpp.

60 {
61 if (!isIgnVoltage()) {
62 // nothing to crank if we are powered only via USB
64 return;
65 } else if (engine->startStopState.isFirstTime) {
66 // initialize when first time with proper power
69 }
70
72 // where are odd cases of start button combined with ECU power source button we do not want to crank right on start
73 return;
74 }
75
78 return;
79 }
81 return;
82 }
83
85 return;
86 }
87 }
88
90
92 // we are here on transition from 0 to 1
94 }
95 // todo: we shall extract start_stop.txt from engine_state.txt
98
99 bool isStarterEngaged = enginePins.starterControl.getLogicValue();
100
101 if (isStarterEngaged) {
103 }
104}
bool readPinEvent()
bool getPhysicalState()
SwitchedState brakePedalSwitchedState
Definition engine.h:215
SwitchedState clutchUpSwitchedState
Definition engine.h:214
RegisteredOutputPin starterControl
Definition efi_gpio.h:82
bool getLogicValue() const
Definition efi_gpio.cpp:667
bool isStopped() const override
bool isIgnVoltage()
startStopState("startStopState", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1380, 1.0, -1.0, -1.0, "")
PUBLIC_API_WEAK bool isCrankingSuppressed()
static void disengageStarterIfNeeded()
void startStopButtonToggle()
Timer timeSinceIgnitionPower
Definition start_stop.h:7

Referenced by doPeriodicSlowCallback().

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

◆ validateConfigOnStartUpOrBurn() [1/2]

bool validateConfigOnStartUpOrBurn ( )

Definition at line 519 of file engine_controller.cpp.

519 {
520 if (!validateBoardConfig()) {
521 return false;
522 }
523#if defined(HW_HELLEN_UAEFI)
524 // todo: make this board-specific validation callback!
526#endif
527 if (!validateGdi()) {
528 return false;
529 }
531 criticalError("Broken ETB min/max %d %d",
534 return false;
535 }
536
538 if (engineConfiguration->cylindersCount > MAX_CYLINDER_COUNT) {
539 criticalError("Invalid cylinder count: %d", engineConfiguration->cylindersCount);
540 return false;
541 }
542#if EFI_PROD_CODE && (BOARD_MC33810_COUNT > 0)
543 float maxConfiguredCorr = config->dwellVoltageCorrValues[0];
544 for (size_t i = 0;i<efi::size(config->dwellVoltageCorrValues);i++) {
545 maxConfiguredCorr = std::max(maxConfiguredCorr, (float)config->dwellVoltageCorrValues[i]);
546 }
547 float maxConfiguredDwell = config->sparkDwellValues[0];
548 for (size_t i = 0;i<efi::size(config->sparkDwellValues);i++) {
549 maxConfiguredDwell = std::max(maxConfiguredDwell, (float)config->sparkDwellValues[i]);
550 }
552 if (maxConfiguredCorr * maxConfiguredDwell > maxAllowedDwell) {
553 criticalError("Dwell=%.2f/corr=%.2f while 33810 limit %d", maxConfiguredDwell, maxConfiguredCorr, maxAllowedDwell);
554 }
555
556#endif // EFI_PROD_CODE && (BOARD_MC33810_COUNT > 0)
557 if (engineConfiguration->adcVcc > 5.0f || engineConfiguration->adcVcc < 1.0f) {
558 criticalError("Invalid adcVcc: %f", engineConfiguration->adcVcc);
559 return false;
560 }
561
564
565#if EFI_ENGINE_CONTROL
566 // Fueling
567 {
570
571 ensureArrayIsAscending("Lambda/AFR load", config->lambdaLoadBins);
572 ensureArrayIsAscending("Lambda/AFR RPM", config->lambdaRpmBins);
573
576
579
580 ensureArrayIsAscending("Injection phase load", config->injPhaseLoadBins);
581 ensureArrayIsAscending("Injection phase RPM", config->injPhaseRpmBins);
582
584
587
590
593
596
598
601 }
602
603 // Ignition
604 {
606
611
612 ensureArrayIsAscending("Ignition CLT corr CLT", config->ignitionCltCorrTempBins);
613 ensureArrayIsAscending("Ignition CLT corr Load", config->ignitionCltCorrLoadBins);
614
615 ensureArrayIsAscending("Ignition IAT corr IAT", config->ignitionIatCorrTempBins);
616 ensureArrayIsAscending("Ignition IAT corr Load", config->ignitionIatCorrLoadBins);
617 }
618
621#endif // EFI_ENGINE_CONTROL
622
629
630// todo: huh? why does this not work on CI? ensureArrayIsAscendingOrDefault("Dwell Correction Voltage", engineConfiguration->dwellVoltageCorrVoltBins);
631
632 ensureArrayIsAscending("MAF transfer function", config->mafDecodingBins);
633
634 // Cranking tables
635 ensureArrayIsAscending("Cranking fuel mult", config->crankingFuelBins);
636 ensureArrayIsAscending("Cranking duration", config->crankingCycleBins);
639
640 // Idle tables
641 ensureArrayIsAscending("Idle target RPM", config->cltIdleRpmBins);
642 ensureArrayIsAscending("Idle warmup mult CLT", config->cltIdleCorrBins);
643 ensureArrayIsAscending("Idle warmup mult RPM", config->rpmIdleCorrBins);
648
649 for (size_t index = 0; index < efi::size(engineConfiguration->vrThreshold); index++) {
650 auto& cfg = engineConfiguration->vrThreshold[index];
651
652 if (cfg.pin == Gpio::Unassigned) {
653 continue;
654 }
655 ensureArrayIsAscending("VR threshold", cfg.rpmBins);
656 }
657
658#if EFI_BOOST_CONTROL
659 // Boost
660 ensureArrayIsAscending("Boost control Load [open loop]", config->boostOpenLoopLoadBins);
661 ensureArrayIsAscending("Boost control Load [closed loop]", config->boostClosedLoopLoadBins);
662 ensureArrayIsAscending("Boost control RPM [open+closed loop]", config->boostRpmBins);
663#endif // EFI_BOOST_CONTROL
664
665#if EFI_ANTILAG_SYSTEM
666 // ALS
671#endif // EFI_ANTILAG_SYSTEM
672
673#if EFI_ELECTRONIC_THROTTLE_BODY
674 // ETB
677#endif // EFI_ELECTRONIC_THROTTLE_BODY
678
679 if (isGdiEngine()) {
685
686 ensureArrayIsAscending("HPFP fuel mass compensation fuel pressure", config->hpfpFuelMassCompensationFuelPressure);
687 ensureArrayIsAscending("HPFP fuel mass compensation fuel mass", config->hpfpFuelMassCompensationFuelMass);
688
689 }
690
691 // VVT
695 }
696
697#if CAM_INPUTS_COUNT != 1
699 ensureArrayIsAscending("VVT exhaust load", config->vvtTable2LoadBins);
701 }
702#endif
703
705 ensureArrayIsAscending("Oil pressure protection", config->minimumOilPressureBins);
706 }
707
708
709 return true;
710}
@ Unassigned
void defaultsOrFixOnBurn()
void ensureArrayIsAscendingOrDefault(const char *msg, const TValue(&values)[TSize])
void ensureArrayIsAscending(const char *msg, const TValue(&values)[TSize])
void pickEtbOrStepper()
static constexpr persistent_config_s * config
PUBLIC_API_WEAK bool validateBoardConfig()
static bool validateGdi()
bool isGdiEngine()
int getMc33810maxDwellTimer(mc33810maxDwellTimer_e value)
Definition mc33810.cpp:1009
bool isBrainPinValid(brain_pin_e brainPin)
uint8_t tractionControlSpeedBins[TRACTION_CONTROL_ETB_DROP_SPEED_SIZE]
scaled_channel< uint16_t, 100, 1 > tractionControlSlipBins[TRACTION_CONTROL_ETB_DROP_SLIP_SIZE]
scaled_channel< int16_t, 100, 1 > battLagCorrBattBins[VBAT_INJECTOR_CURVE_SIZE]
scaled_channel< uint32_t, 10, 1 > battLagCorrPressBins[VBAT_INJECTOR_CURVE_PRESSURE_SIZE]
scaled_channel< uint8_t, 2, 1 > hpfpLobeProfileQuantityBins[HPFP_LOBE_PROFILE_SIZE]
scaled_channel< int16_t, 1, 1 > cltIdleRpmBins[CLT_CURVE_SIZE]
scaled_channel< uint8_t, 1, 100 > iacCoastingRpmBins[CLT_CURVE_SIZE]
scaled_channel< uint16_t, 10, 1 > hpfpFuelMassCompensationFuelPressure[HPFP_FUEL_MASS_COMPENSATION_SIZE]
scaled_channel< uint8_t, 1, 50 > hpfpCompensationRpmBins[HPFP_COMPENSATION_RPM_SIZE]
scaled_channel< uint16_t, 1000, 1 > fuelLevelBins[FUEL_LEVEL_TABLE_COUNT]
scaled_channel< uint8_t, 1, 10 > idleVeRpmBins[IDLE_VE_SIZE_RPM]
scaled_channel< uint8_t, 1, 50 > hpfpTargetRpmBins[HPFP_TARGET_SIZE]
scaled_channel< uint8_t, 50, 1 > dwellVoltageCorrValues[DWELL_CURVE_SIZE]
scaled_channel< uint8_t, 1, 50 > tpsTspCorrValuesBins[TPS_TPS_ACCEL_CLT_CORR_TABLE]
scaled_channel< uint16_t, 100, 1 > mapEstimateTpsBins[MAP_EST_LOAD_COUNT]
scaled_channel< uint8_t, 1, 5 > ignitionCltCorrLoadBins[CLT_TIMING_LOAD_AXIS_SIZE]
scaled_channel< int16_t, 1, 1 > ignitionCltCorrTempBins[CLT_TIMING_TEMP_AXIS_SIZE]
scaled_channel< uint8_t, 1, 100 > boostRpmBins[BOOST_RPM_COUNT]
scaled_channel< uint8_t, 1, 100 > rpmIdleCorrBins[CLT_IDLE_TABLE_RPM_SIZE]
scaled_channel< uint8_t, 1, 100 > pedalToTpsRpmBins[PEDAL_TO_TPS_RPM_SIZE]
scaled_channel< uint8_t, 1, 100 > maxKnockRetardRpmBins[KNOCK_TABLE_RPM_SIZE]
scaled_channel< uint8_t, 1, 50 > idleAdvanceBins[IDLE_ADVANCE_CURVE_SIZE]
scaled_channel< uint8_t, 1, 5 > ignitionIatCorrLoadBins[IAT_IGN_CORR_LOAD_COUNT]
scaled_channel< uint16_t, 100, 1 > hpfpFuelMassCompensationFuelMass[HPFP_FUEL_MASS_COMPENSATION_SIZE]
scaled_channel< uint16_t, 10, 1 > hpfpTargetLoadBins[HPFP_TARGET_SIZE]
scaled_channel< uint8_t, 1, 100 > minimumOilPressureBins[8]
scaled_channel< uint16_t, 100, 1 > sparkDwellValues[DWELL_CURVE_SIZE]

Referenced by handleBurnCommand(), initEfiWithConfig(), and validateConfigOnStartUpOrBurn().

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

◆ validateConfigOnStartUpOrBurn() [2/2]

bool validateConfigOnStartUpOrBurn ( bool  isRunningOnBurn)

Definition at line 712 of file engine_controller.cpp.

712 {
715}
static void onConfigOnStartUpOrBurn(bool isRunningOnBurn)
bool validateConfigOnStartUpOrBurn()
Here is the call graph for this function:

Go to the source code of this file.