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 ()
 
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 708 of file engine_controller.cpp.

708 {
709 // Start this early - it will start LED blinking and such
711
712#if EFI_SHAFT_POSITION_INPUT
713 // todo: figure out better startup logic
715#endif /* EFI_SHAFT_POSITION_INPUT */
716
717 /**
718 * Initialize hardware drivers
719 */
720 initHardware();
721
723
724#if EFI_FILE_LOGGING
725 initMmcCard();
726#endif /* EFI_FILE_LOGGING */
727
728#if EFI_ENGINE_EMULATOR
730#endif
731
732#if EFI_LUA
733 startLua();
734#endif // EFI_LUA
735
736#if EFI_CAN_SERIAL
737 // needs to be called after initCan() inside initHardware()
739#endif /* EFI_CAN_SERIAL */
740
741}
void initQcBenchControls()
void initEngineEmulator()
void initHardware()
Definition hardware.cpp:538
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 388 of file engine_controller.cpp.

388 {
389#if EFI_PROD_CODE
390 addConsoleAction("sensorinfo", printSensorInfo);
391 addConsoleAction("reset_accel", resetAccel);
392#endif /* EFI_PROD_CODE */
393
394#if EFI_SIMULATOR || EFI_UNIT_TEST
395 printf("commonInitEngineController\n");
396#endif
397
398#if !EFI_UNIT_TEST
400#endif /* EFI_UNIT_TEST */
401
402#if EFI_ENGINE_CONTROL
403 /**
404 * This has to go after 'enginePins.startPins()' in order to
405 * properly detect un-assigned output pins
406 */
408
410#endif // EFI_ENGINE_CONTROL
411
412
413#if EFI_PROD_CODE || EFI_SIMULATOR
414 initSettings();
415
416 if (hasFirmwareError()) {
417 return;
418 }
419#endif
420
421#if ! EFI_UNIT_TEST && EFI_ENGINE_CONTROL
423#endif /* ! EFI_UNIT_TEST && EFI_ENGINE_CONTROL */
424
425#if EFI_ALTERNATOR_CONTROL
427#endif /* EFI_ALTERNATOR_CONTROL */
428
429#if EFI_VVT_PID
431#endif /* EFI_VVT_PID */
432
433#if EFI_MALFUNCTION_INDICATOR
435#endif /* EFI_MALFUNCTION_INDICATOR */
436
437#if !EFI_UNIT_TEST
438 // This is tested independently - don't configure sensors for tests.
439 // This lets us selectively mock them for each test.
441#endif /* EFI_UNIT_TEST */
442
443 initSensors();
444
446
448
449 initGpPwm();
450
451#if EFI_IDLE_CONTROL
453#endif /* EFI_IDLE_CONTROL */
454
455#if EFI_TCU
457#endif
458
460
461#if EFI_ELECTRONIC_THROTTLE_BODY
463#endif /* EFI_ELECTRONIC_THROTTLE_BODY */
464
465#if EFI_MAP_AVERAGING && defined (MODULE_MAP_AVERAGING)
466 engine->module<MapAveragingModule>()->init();
467#else
468 efiPrintf("No MapAveraging support!");
469#endif /* EFI_MAP_AVERAGING */
470
471#if EFI_BOOST_CONTROL
473#endif /* EFI_BOOST_CONTROL */
474
475#if EFI_LAUNCH_CONTROL
477#endif
478
480
481#if EFI_UNIT_TEST
483#endif /* EFI_UNIT_TEST */
484
485#if EFI_AUX_VALVES
487#endif /* EFI_AUX_VALVES */
488
489#ifdef MODULE_TACHOMETER
490 engine->module<TachometerModule>()->init();
491#endif
492
494
495 initStft();
496#if EFI_LTFT_CONTROL
497 initLtft();
498#endif
499}
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:633
void initSpeedometer()
printf("\n")
void initVvtActuators()
Definition vvt.cpp:192

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

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

104 {
105#if EFI_ENGINE_CONTROL
106 initFuelMap();
109 for (size_t i=0;i<efi::size(events.elements);i++) {
110 // above-zero value helps distinguish events
112 }
113 // above-zero value helps distinguish events
115#endif // EFI_ENGINE_CONTROL
116}
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 209 of file engine_controller.cpp.

209 {
210 slowController.start();
211 fastController.start();
212}
static PeriodicFastController fastController
static PeriodicSlowController slowController

Referenced by runRusEfi().

Here is the caller graph for this function:

◆ initRealHardwareEngineController()

void initRealHardwareEngineController ( )

Definition at line 744 of file engine_controller.cpp.

744 {
747
748#if EFI_LOGIC_ANALYZER
751 }
752#endif /* EFI_LOGIC_ANALYZER */
753
754 if (hasFirmwareError()) {
755 return;
756 }
757
759
761}
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, 1372, 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()

bool validateConfigOnStartUpOrBurn ( )

Definition at line 521 of file engine_controller.cpp.

521 {
522 if (!validateBoardConfig()) {
523 return false;
524 }
525 if (!validateGdi()) {
526 return false;
527 }
529 criticalError("Broken ETB min/max %d %d",
532 return false;
533 }
534
536 if (engineConfiguration->cylindersCount > MAX_CYLINDER_COUNT) {
537 criticalError("Invalid cylinder count: %d", engineConfiguration->cylindersCount);
538 return false;
539 }
540#if EFI_PROD_CODE && (BOARD_MC33810_COUNT > 0)
541 float maxConfiguredCorr = config->dwellVoltageCorrValues[0];
542 for (size_t i = 0;i<efi::size(config->dwellVoltageCorrValues);i++) {
543 maxConfiguredCorr = std::max(maxConfiguredCorr, (float)config->dwellVoltageCorrValues[i]);
544 }
545 float maxConfiguredDwell = config->sparkDwellValues[0];
546 for (size_t i = 0;i<efi::size(config->sparkDwellValues);i++) {
547 maxConfiguredDwell = std::max(maxConfiguredDwell, (float)config->sparkDwellValues[i]);
548 }
550 if (maxConfiguredCorr * maxConfiguredDwell > maxAllowedDwell) {
551 criticalError("Dwell=%.2f/corr=%.2f while 33810 limit %d", maxConfiguredDwell, maxConfiguredCorr, maxAllowedDwell);
552 }
553
554#endif // EFI_PROD_CODE && (BOARD_MC33810_COUNT > 0)
555 if (engineConfiguration->adcVcc > 5.0f || engineConfiguration->adcVcc < 1.0f) {
556 criticalError("Invalid adcVcc: %f", engineConfiguration->adcVcc);
557 return false;
558 }
559
562
563#if EFI_ENGINE_CONTROL
564 // Fueling
565 {
568
569 ensureArrayIsAscending("Lambda/AFR load", config->lambdaLoadBins);
570 ensureArrayIsAscending("Lambda/AFR RPM", config->lambdaRpmBins);
571
574
577
578 ensureArrayIsAscending("Injection phase load", config->injPhaseLoadBins);
579 ensureArrayIsAscending("Injection phase RPM", config->injPhaseRpmBins);
580
582
585
588
591
593
596 }
597
598 // Ignition
599 {
601
606
607 ensureArrayIsAscending("Ignition CLT corr CLT", config->ignitionCltCorrTempBins);
608 ensureArrayIsAscending("Ignition CLT corr Load", config->ignitionCltCorrLoadBins);
609
610 ensureArrayIsAscending("Ignition IAT corr IAT", config->ignitionIatCorrTempBins);
611 ensureArrayIsAscending("Ignition IAT corr Load", config->ignitionIatCorrLoadBins);
612 }
613
616#endif // EFI_ENGINE_CONTROL
617
624
625// todo: huh? why does this not work on CI? ensureArrayIsAscendingOrDefault("Dwell Correction Voltage", engineConfiguration->dwellVoltageCorrVoltBins);
626
627 ensureArrayIsAscending("MAF transfer function", config->mafDecodingBins);
628
629 // Cranking tables
630 ensureArrayIsAscending("Cranking fuel mult", config->crankingFuelBins);
631 ensureArrayIsAscending("Cranking duration", config->crankingCycleBins);
634
635 // Idle tables
636 ensureArrayIsAscending("Idle target RPM", config->cltIdleRpmBins);
637 ensureArrayIsAscending("Idle warmup mult CLT", config->cltIdleCorrBins);
638 ensureArrayIsAscending("Idle warmup mult RPM", config->rpmIdleCorrBins);
643
644 for (size_t index = 0; index < efi::size(engineConfiguration->vrThreshold); index++) {
645 auto& cfg = engineConfiguration->vrThreshold[index];
646
647 if (cfg.pin == Gpio::Unassigned) {
648 continue;
649 }
650 ensureArrayIsAscending("VR threshold", cfg.rpmBins);
651 }
652
653#if EFI_BOOST_CONTROL
654 // Boost
655 ensureArrayIsAscending("Boost control Load [open loop]", config->boostOpenLoopLoadBins);
656 ensureArrayIsAscending("Boost control Load [closed loop]", config->boostClosedLoopLoadBins);
657 ensureArrayIsAscending("Boost control RPM [open+closed loop]", config->boostRpmBins);
658#endif // EFI_BOOST_CONTROL
659
660#if EFI_ANTILAG_SYSTEM
661 // ALS
666#endif // EFI_ANTILAG_SYSTEM
667
668#if EFI_ELECTRONIC_THROTTLE_BODY
669 // ETB
672#endif // EFI_ELECTRONIC_THROTTLE_BODY
673
674 if (isGdiEngine()) {
680
681 ensureArrayIsAscending("HPFP fuel mass compensation fuel pressure", config->hpfpFuelMassCompensationFuelPressure);
682 ensureArrayIsAscending("HPFP fuel mass compensation fuel mass", config->hpfpFuelMassCompensationFuelMass);
683
684 }
685
686 // VVT
690 }
691
692#if CAM_INPUTS_COUNT != 1
694 ensureArrayIsAscending("VVT exhaust load", config->vvtTable2LoadBins);
696 }
697#endif
698
700 ensureArrayIsAscending("Oil pressure protection", config->minimumOilPressureBins);
701 }
702
703 return true;
704}
@ Unassigned
void defaultsOrFixOnBurn()
void ensureArrayIsAscendingOrDefault(const char *msg, const TValue(&values)[TSize])
void ensureArrayIsAscending(const char *msg, const TValue(&values)[TSize])
static constexpr persistent_config_s * config
PUBLIC_API_WEAK bool validateBoardConfig()
static bool validateGdi()
bool isGdiEngine()
int getMc33810maxDwellTimer(mc33810maxDwellTimer_e value)
Definition mc33810.cpp:1003
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, 10 > idleVeRpmBins[IDLE_VE_SIZE]
scaled_channel< uint16_t, 1000, 1 > fuelLevelBins[FUEL_LEVEL_TABLE_COUNT]
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, 100 > boostRpmBins[BOOST_RPM_COUNT]
scaled_channel< int16_t, 1, 1 > ignitionCltCorrTempBins[CLT_TIMING_CURVE_SIZE]
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, 50 > hpfpCompensationRpmBins[HPFP_COMPENSATION_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]
scaled_channel< uint8_t, 1, 5 > ignitionCltCorrLoadBins[CLT_TIMING_CURVE_SIZE]

Referenced by handleBurnCommand(), and initEfiWithConfig().

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

Go to the source code of this file.