rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Data Fields | Private Member Functions | Private Attributes
Engine Class Referencefinal

#include <engine.h>

Inheritance diagram for Engine:
Inheritance graph
[legend]
Collaboration diagram for Engine:
Collaboration graph
[legend]

Public Member Functions

 Engine ()
 
template<typename get_t >
constexpr auto & module ()
 
template<typename get_t >
constexpr auto const & module () const
 
void resetLua ()
 
void OnTriggerStateProperState (efitick_t nowNt, size_t triggerStateIndex) override
 
void OnTriggerSynchronization (bool wasSynchronized, bool isDecodingError) override
 
void OnTriggerSynchronizationLost () override
 
TriggerStateListenernextListener () override
 
void setConfig ()
 
int getBailedOnDwellCount () const
 
void incrementBailedOnDwellCount ()
 
int getGlobalConfigurationVersion () const
 
void periodicFastCallback ()
 
void periodicSlowCallback ()
 
void onEngineStopped ()
 
void updateSlowSensors ()
 
void updateSwitchInputs ()
 
void updateTriggerConfiguration ()
 
void resetEngineSnifferIfInTestMode ()
 
void preCalculate ()
 
void efiWatchdog ()
 
void onEngineHasStopped ()
 
void checkShutdown ()
 
bool isInShutdownMode () const
 
bool isMainRelayEnabled () const
 
void onSparkFireKnockSense (uint8_t cylinderIndex, efitick_t nowNt)
 

Data Fields

StartStopState startStopState {}
 
TunerStudioOutputChannels outputChannels {}
 
bool allowCanTx = true
 
bool isPwmEnabled = true
 
bool pauseCANdueToSerial = false
 
IEtbControlleretbControllers [ETB_COUNT] = {nullptr}
 
DynoView dynoInstance {}
 
LongTermIdleTrim m_ltit
 
FuelComputer fuelComputer {}
 
type_list< Mockable< InjectorModelPrimary >, Mockable< InjectorModelSecondary >,#if EFI_IDLE_CONTROL Mockable< IdleController >,#endif TriggerScheduler,#if EFI_HPFP &&EFI_ENGINE_CONTROL Mockable< HpfpController >,#endif #if EFI_ENGINE_CONTROL Mockable< ThrottleModel >,#endif #if EFI_ALTERNATOR_CONTROL AlternatorController,#endif MainRelayController, Mockable< IgnitionController >, Mockable< AcController >, PrimeController, DfcoController,#if EFI_HD_ACR HarleyAcr,#endif Mockable< WallFuelController >, KnockController, SensorChecker,#if EFI_ENGINE_CONTROL Mockable< LimpManager >,#endif #if EFI_VVT_PID VvtController1, VvtController2, VvtController3, VvtController4,#endif #if EFI_BOOST_CONTROL BoostController,#endif TpsAccelEnrichment,#if EFI_LAUNCH_CONTROL NitrousController,#endif #if EFI_LTFT_CONTROL LongTermFuelTrim,#endif ShortTermFuelTrim,#include "modules_list_generated.h" EngineModuleengineModules {}
 
GearControllerBasegearController = nullptr
 
SwitchedState clutchUpSwitchedState {&engineState.clutchUpState}
 
SwitchedState brakePedalSwitchedState {&engineState.brakePedalState}
 
SwitchedState acButtonSwitchedState {&engineModules.get<AcController>().unmock().acButtonState}
 
SimpleSwitchedState luaDigitalInputState [LUA_DIGITAL_INPUT_COUNT] {}
 
LaunchControlBase launchController {}
 
ShiftTorqueReductionController shiftTorqueReductionController {}
 
SoftSparkLimiter softSparkLimiter {false}
 
SoftSparkLimiter hardSparkLimiter {true}
 
AntilagSystemBase antilagController {}
 
LambdaMonitor lambdaMonitor {}
 
IgnitionState ignitionState {}
 
TriggerStateListenersecondListener = nullptr
 
AuxActor auxValves [AUX_DIGITAL_VALVE_COUNT][2] {}
 
bool needTdcCallback = true
 
SingleTimerExecutor scheduler {}
 
SleepExecutor scheduler {}
 
TestExecutor scheduler {}
 
std::function< void(IgnitionEvent *, bool)> onIgnitionEvent
 
std::function< void(const IgnitionEvent &, efitick_t, angle_t, efitick_t)> onScheduleTurnSparkPinHighStartCharging = [](const IgnitionEvent&, efitick_t, angle_t, efitick_t) -> void {}
 
std::function< void(const IgnitionEvent &, efitick_t)> onScheduleOverFireSparkAndPrepareNextSchedule = [](const IgnitionEvent&, efitick_t) -> void {}
 
FuelSchedule injectionEvents {}
 
IgnitionEventList ignitionEvents {}
 
scheduling_s tdcScheduler [2] {}
 
OneCylinder cylinders [MAX_CYLINDER_COUNT] {}
 
bool etbAutoTune = false
 
bool etbIgnoreJamProtection = false
 
bool tdcMarkEnabled = true
 
bool slowCallBackWasInvoked = false
 
RpmCalculator rpmCalculator {}
 
Timer configBurnTimer {}
 
Timer engineTypeChangeTimer {}
 
int globalConfigurationVersion = 0
 
TriggerCentral triggerCentral {}
 
bool isRunningPwmTest = false
 
bool isFunctionalTestMode = false
 
EngineState engineState {}
 
dc_motors_s dc_motors {}
 
sent_state_s sent_state {}
 
efitimeus_t timeToStopIdleTest {}
 
SensorsState sensors {}
 
AirmassModelBasemockAirmassModel {}
 

Private Member Functions

void reset ()
 
void injectEngineReferences ()
 

Private Attributes

int bailedOnDwellCount = 0
 

Detailed Description

Definition at line 102 of file engine.h.

Constructor & Destructor Documentation

◆ Engine()

Engine::Engine ( )

Definition at line 283 of file engine.cpp.

283 {
284 // Everything else has default initializers setup in generated file
287}
IgnitionState ignitionState
Definition engine.h:239
EngineState engineState
Definition engine.h:344

Member Function Documentation

◆ checkShutdown()

void Engine::checkShutdown ( )

Needed by EFI_MAIN_RELAY_CONTROL to shut down the engine correctly. This method cancels shutdown if the ignition voltage is detected.

Definition at line 468 of file engine.cpp.

468 {
469#if EFI_MAIN_RELAY_CONTROL
470 // if we are already in the "ignition_on" mode, then do nothing
471/* this logic is not alive
472 if (ignitionOnTimeNt > 0) {
473 return;
474 }
475todo: move to shutdown_controller.cpp
476*/
477
478 // here we are in the shutdown (the ignition is off) or initial mode (after the firmware fresh start)
479/* this needs work or tests
480 const efitick_t engineStopWaitTimeoutUs = 500000LL; // 0.5 sec
481 // in shutdown mode, we need a small cooldown time between the ignition off and on
482todo: move to shutdown_controller.cpp
483 if (stopEngineRequestTimeNt == 0 || (getTimeNowNt() - stopEngineRequestTimeNt) > US2NT(engineStopWaitTimeoutUs)) {
484 // if the ignition key is turned on again,
485 // we cancel the shutdown mode, but only if all shutdown procedures are complete
486 const float vBattThresholdOn = 8.0f;
487 // we fallback into zero instead of VBAT_FALLBACK_VALUE because it's not safe to false-trigger the "ignition on" event,
488 // and we want to turn on the main relay only when 100% sure.
489 if ((Sensor::getOrZero(SensorType::BatteryVoltage) > vBattThresholdOn) && !isInShutdownMode()) {
490 ignitionOnTimeNt = getTimeNowNt();
491 efiPrintf("Ignition voltage detected!");
492 if (stopEngineRequestTimeNt != 0) {
493 efiPrintf("Cancel the engine shutdown!");
494 stopEngineRequestTimeNt = 0;
495 }
496 }
497 }
498*/
499#endif /* EFI_MAIN_RELAY_CONTROL */
500}

Referenced by periodicSlowCallback().

Here is the caller graph for this function:

◆ efiWatchdog()

void Engine::efiWatchdog ( )

todo: better watch dog implementation should be implemented - see http://sourceforge.net/p/rusefi/tickets/96/

Definition at line 427 of file engine.cpp.

427 {
430 return;
431
432#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
433 if (module<PrimeController>()->isPriming() || triggerCentral.engineMovedRecently()) {
434 // do not invoke check in priming or if engine moved recently, no need to assert safe pin state.
435 return;
436 }
437
440 // todo: make this a firmwareError assuming functional tests would run
441 warning(ObdCode::CUSTOM_ERR_2ND_WATCHDOG, "Some pins were turned off by 2nd pass watchdog");
442 }
443 return;
444 }
445
446 /**
447 * todo: better watch dog implementation should be implemented - see
448 * http://sourceforge.net/p/rusefi/tickets/96/
449 */
452#endif // EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
453}
bool isRunningBenchTest()
TriggerCentral triggerCentral
Definition engine.h:318
void onEngineHasStopped()
Definition engine.cpp:455
bool isRunningPwmTest
Definition engine.h:334
bool stopPins()
Definition efi_gpio.cpp:214
bool engineMovedRecently(efitick_t nowNt) const
EnginePins enginePins
Definition efi_gpio.cpp:24
static void assertTimeIsLinear()
Definition engine.cpp:409
bool warning(ObdCode code, const char *fmt,...)
@ CUSTOM_ERR_2ND_WATCHDOG

Referenced by periodicSlowCallback().

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

◆ getBailedOnDwellCount()

int Engine::getBailedOnDwellCount ( ) const
inline

Definition at line 261 of file engine.h.

261{ return bailedOnDwellCount; }
int bailedOnDwellCount
Definition engine.h:259

◆ getGlobalConfigurationVersion()

int Engine::getGlobalConfigurationVersion ( ) const

Definition at line 289 of file engine.cpp.

289 {
291}
int globalConfigurationVersion
Definition engine.h:315

Referenced by TriggerCentral::checkIfTriggerConfigChanged(), configureRusefiLuaHooks(), printConfiguration(), and updateTriggerWaveformIfNeeded().

Here is the caller graph for this function:

◆ incrementBailedOnDwellCount()

void Engine::incrementBailedOnDwellCount ( )
inline

Definition at line 262 of file engine.h.

Referenced by turnSparkPinHighStartCharging().

Here is the caller graph for this function:

◆ injectEngineReferences()

void Engine::injectEngineReferences ( )
private

Definition at line 388 of file engine.cpp.

388 {
389#if EFI_SHAFT_POSITION_INPUT
391 for (int camIndex = 0;camIndex < CAMS_PER_BANK;camIndex++) {
393 }
394#endif // EFI_SHAFT_POSITION_INPUT
395}
VvtTriggerConfiguration vvtTriggerConfiguration[CAMS_PER_BANK]
PrimaryTriggerConfiguration primaryTriggerConfiguration

Referenced by setConfig().

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

◆ isInShutdownMode()

bool Engine::isInShutdownMode ( ) const

Allows to finish some long-term shutdown procedures (stepper motor parking etc.) Called when the ignition switch is turned off (vBatt is too low). Returns true if some operations are in progress on background.

Definition at line 502 of file engine.cpp.

502 {
503 // TODO: this logic is currently broken
504#if 0 && EFI_MAIN_RELAY_CONTROL && EFI_PROD_CODE
505 // if we are in "ignition_on" mode and not in shutdown mode
506 if (stopEngineRequestTimeNt == 0 && ignitionOnTimeNt > 0) {
507 const float vBattThresholdOff = 5.0f;
508 // start the shutdown process if the ignition voltage dropped low
509 if (Sensor::get(SensorType::BatteryVoltage).value_or(VBAT_FALLBACK_VALUE) <= vBattThresholdOff) {
511 }
512 }
513
514 // we are not in the shutdown mode?
515 if (stopEngineRequestTimeNt == 0) {
516 return false;
517 }
518
519 const efitick_t turnOffWaitTimeoutNt = NT_PER_SECOND;
520 // We don't want any transients to step in, so we wait at least 1 second whatever happens.
521 // Also it's good to give the stepper motor some time to start moving to the initial position (or parking)
522 if ((getTimeNowNt() - stopEngineRequestTimeNt) < turnOffWaitTimeoutNt)
523 return true;
524
525 const efitick_t engineSpinningWaitTimeoutNt = 5 * NT_PER_SECOND;
526 // The engine is still spinning! Give it some time to stop (but wait no more than 5 secs)
527 if (isSpinning && (getTimeNowNt() - stopEngineRequestTimeNt) < engineSpinningWaitTimeoutNt)
528 return true;
529
530 // The idle motor valve is still moving! Give it some time to park (but wait no more than 10 secs)
531 // Usually it can move to the initial 'cranking' position or zero 'parking' position.
532 const efitick_t idleMotorWaitTimeoutNt = 10 * NT_PER_SECOND;
533 if (isIdleMotorBusy() && (getTimeNowNt() - stopEngineRequestTimeNt) < idleMotorWaitTimeoutNt)
534 return true;
535#endif /* EFI_MAIN_RELAY_CONTROL */
536 return false;
537}
virtual SensorResult get() const =0
efitick_t getTimeNowNt()
Definition efitime.cpp:19
bool isIdleMotorBusy()
void doScheduleStopEngine(StopRequestedReason reason)
Here is the call graph for this function:

◆ isMainRelayEnabled()

bool Engine::isMainRelayEnabled ( ) const

The stepper does not work if the main relay is turned off (it requires +12V). Needed by the stepper motor code to detect if it works.

Definition at line 539 of file engine.cpp.

539 {
540#if EFI_MAIN_RELAY_CONTROL
542#else
543 // if no main relay control, we assume it's always turned on
544 return true;
545#endif /* EFI_MAIN_RELAY_CONTROL */
546}
RegisteredOutputPin mainRelay
Definition efi_gpio.h:76
bool getLogicValue() const
Definition efi_gpio.cpp:667

Referenced by StepDirectionStepper::pulse(), and LimpManager::updateState().

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

◆ module() [1/2]

template<typename get_t >
constexpr auto & Engine::module ( )
inlineconstexpr

Slightly shorter helper function to keep the code looking clean.

Definition at line 200 of file engine.h.

200 {
201 return engineModules.get<get_t>();
202 }
type_list< Mockable< InjectorModelPrimary >, Mockable< InjectorModelSecondary >,#if EFI_IDLE_CONTROL Mockable< IdleController >,#endif TriggerScheduler,#if EFI_HPFP &&EFI_ENGINE_CONTROL Mockable< HpfpController >,#endif #if EFI_ENGINE_CONTROL Mockable< ThrottleModel >,#endif #if EFI_ALTERNATOR_CONTROL AlternatorController,#endif MainRelayController, Mockable< IgnitionController >, Mockable< AcController >, PrimeController, DfcoController,#if EFI_HD_ACR HarleyAcr,#endif Mockable< WallFuelController >, KnockController, SensorChecker,#if EFI_ENGINE_CONTROL Mockable< LimpManager >,#endif #if EFI_VVT_PID VvtController1, VvtController2, VvtController3, VvtController4,#endif #if EFI_BOOST_CONTROL BoostController,#endif TpsAccelEnrichment,#if EFI_LAUNCH_CONTROL NitrousController,#endif #if EFI_LTFT_CONTROL LongTermFuelTrim,#endif ShortTermFuelTrim,#include "modules_list_generated.h" EngineModule > engineModules
Definition engine.h:194

Referenced by WallFuel::adjust(), applyPidSettings(), auxPlainPinTurnOn(), canDashboardHaltech(), EtbController::checkJam(), EtbController::checkStatus(), commonInitEngineController(), configureRusefiLuaHooks(), getAdvanceCorrections(), IdleController::getClosedLoop(), getIdlePosition(), IdleController::getIdlePosition(), getInjectionMass(), ShortTermFuelTrim::getLearningState(), getLimpManager(), getLiveData(), getLiveData(), AlternatorController::getOpenLoop(), getOutputValueByHash(), SpeedDensityAirmass::getPredictiveMap(), PrimeController::getPrimeDuration(), getRunningAdvance(), getRunningFuel(), IdleController::getRunningOpenLoop(), IdleController::getTargetRpm(), AirmassVeModelBase::getVe(), handleGetDataRequest(), TriggerCentral::handleShaftSignal(), initAccelEnrichment(), initBoostCtrl(), initSoftwareKnock(), initStft(), initVvtActuators(), LambdaMonitorBase::isCurrentlyGood(), LtftState::load(), lua_getDigital(), mainTriggerCallback(), FanController::onSlowCallback(), InjectionEvent::onTriggerTooth(), EngineState::periodicFastCallback(), populateFrame(), populateFrame(), populateFrame(), populateFrame(), populateFrame(), populateFrame(), processLastKnockEvent(), resetAccel(), resetLua(), HpfpController::scheduleNextCycle(), scheduleOpen(), scheduleSparkEvent(), startIdleThread(), storageReadID(), storageWriteID(), updateFlags(), updateFuelResults(), updateSlowSensors(), updateSwitchInputs(), and updateVehicleSpeed().

◆ module() [2/2]

template<typename get_t >
constexpr auto const & Engine::module ( ) const
inlineconstexpr

Definition at line 205 of file engine.h.

205 {
206 return engineModules.get<get_t>();
207 }

◆ nextListener()

TriggerStateListener * Engine::nextListener ( )
overridevirtual

Implements TriggerStateListener.

Definition at line 341 of file engine.cpp.

341 {
342 return secondListener;
343}
TriggerStateListener * secondListener
Definition engine.h:247

◆ onEngineHasStopped()

void Engine::onEngineHasStopped ( )

Definition at line 455 of file engine.cpp.

455 {
456#if EFI_ENGINE_CONTROL
457 ignitionEvents.isReady = false;
458#endif // EFI_ENGINE_CONTROL
459
460#if EFI_PROD_CODE || EFI_SIMULATOR
461 efiPrintf("Engine has stopped spinning.");
462#endif
463
464 // this invocation should be the last layer of defence in terms of making sure injectors/coils are not active
466}
IgnitionEventList ignitionEvents
Definition engine.h:289

Referenced by efiWatchdog().

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

◆ onEngineStopped()

void Engine::onEngineStopped ( )

Definition at line 569 of file engine.cpp.

569 {
570 engineModules.apply_all([](auto& m) { m.onEngineStop(); });
571}

Referenced by RpmCalculator::setStopSpinning().

Here is the caller graph for this function:

◆ onSparkFireKnockSense()

void Engine::onSparkFireKnockSense ( uint8_t  cylinderIndex,
efitick_t  nowNt 
)

Definition at line 190 of file knock_controller.cpp.

190 {
191#if EFI_SOFTWARE_KNOCK
192 cylinderNumberCopy = cylinderNumber;
193 scheduleByAngle(nullptr, nowNt,
194 /*angle*/engineConfiguration->knockDetectionWindowStart, action_s::make<startKnockSampling>(static_cast<Engine*>(engine)));
195#else
196 UNUSED(cylinderNumber);
197 UNUSED(nowNt);
198#endif
199}
static EngineAccessor engine
Definition engine.h:413
static constexpr engine_configuration_s * engineConfiguration
UNUSED(samplingTimeSeconds)
static uint8_t cylinderNumberCopy
efitick_t scheduleByAngle(scheduling_s *timer, efitick_t nowNt, angle_t angle, action_s const &action)

Referenced by fireSparkAndPrepareNextSchedule().

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

◆ OnTriggerStateProperState()

void Engine::OnTriggerStateProperState ( efitick_t  nowNt,
size_t  triggerStateIndex 
)
overridevirtual

Implements TriggerStateListener.

Definition at line 335 of file engine.cpp.

335 {
337
339}
RpmCalculator rpmCalculator
Definition engine.h:306
void setSpinningUp(efitick_t nowNt)
triggerStateIndex("triggerStateIndex", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1584, 1.0, -1.0, -1.0, "")
Here is the call graph for this function:

◆ OnTriggerSynchronization()

void Engine::OnTriggerSynchronization ( bool  wasSynchronized,
bool  isDecodingError 
)
overridevirtual

Implements TriggerStateListener.

Definition at line 359 of file engine.cpp.

359 {
360 // TODO: this logic probably shouldn't be part of engine.cpp
361
362 // We only care about trigger shape once we have synchronized trigger. Anything could happen
363 // during first revolution and it's fine
364 if (wasSynchronized) {
366
367 // 'triggerStateListener is not null' means we are running a real engine and now just preparing trigger shape
368 // that's a bit of a hack, a sweet OOP solution would be a real callback or at least 'needDecodingErrorLogic' method?
369 if (isDecodingError) {
370#if EFI_PROD_CODE
372 efiPrintf("error: synchronizationPoint @ index %lu expected %d/%d got %d/%d",
378 }
379#endif /* EFI_PROD_CODE */
380 }
381
382 engine->triggerCentral.triggerErrorDetection.add(isDecodingError);
383 }
384
385}
RegisteredOutputPin triggerDecoderErrorPin
Definition efi_gpio.h:121
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition efi_gpio.cpp:604
PrimaryTriggerDecoder triggerState
TriggerWaveform triggerShape
cyclic_buffer< int > triggerErrorDetection
current_cycle_state_s currentCycle
bool someSortOfTriggerError() const
size_t getExpectedEventCount(TriggerWheel channelIndex) const
size_t eventCount[PWM_PHASE_MAX_WAVE_PER_PWM]
Here is the call graph for this function:

◆ OnTriggerSynchronizationLost()

void Engine::OnTriggerSynchronizationLost ( )
overridevirtual

Implements TriggerStateListener.

Definition at line 345 of file engine.cpp.

345 {
346 // Needed for early instant-RPM detection
348
351
352 for (size_t i = 0; i < efi::size(triggerCentral.vvtState); i++) {
353 for (size_t j = 0; j < efi::size(triggerCentral.vvtState[0]); j++) {
355 }
356 }
357}
VvtTriggerDecoder vvtState[BANKS_COUNT][CAMS_PER_BANK]
InstantRpmCalculator instantRpm
virtual void resetState()
Here is the call graph for this function:

◆ periodicFastCallback()

void Engine::periodicFastCallback ( )

See FAST_CALLBACK_PERIOD_MS

The idea of this method is to execute all heavy calculations in a lower-priority thread, so that trigger event handler/IO scheduler tasks are faster.

Definition at line 556 of file engine.cpp.

556 {
558
560
561
563
564 speedoUpdate();
565
566 engineModules.apply_all([](auto & m) { m.onFastCallback(); });
567}
void periodicFastCallback()
Definition engine2.cpp:154
PUBLIC_API_WEAK void boardPeriodicFastCallback()
Definition engine.cpp:148
@ EnginePeriodicFastCallback
void speedoUpdate()

Referenced by RpmCalculator::assignRpmValue(), and mainTriggerCallback().

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

◆ periodicSlowCallback()

void Engine::periodicSlowCallback ( )

See SLOW_CALLBACK_PERIOD_MS

Definition at line 150 of file engine.cpp.

150 {
152
153#if EFI_SHAFT_POSITION_INPUT
154 // Re-read config in case it's changed
156 for (int camIndex = 0;camIndex < CAMS_PER_BANK;camIndex++) {
158 }
159
161 enginePins.o2heater.setValue(getEngineState()->heaterControlEnabled);
163#endif // EFI_SHAFT_POSITION_INPUT
164
165 efiWatchdog();
168
169 module<TpsAccelEnrichment>()->onNewValue(Sensor::getOrZero(SensorType::Tps1));
170
172
173 updateGppwm();
174
175 engine->engineModules.apply_all([](auto & m) { m.onSlowCallback(); });
176
177#if (BOARD_TLE8888_COUNT > 0)
179#endif
180
181#if EFI_DYNO_VIEW
183#endif
184
185 // TODO: move to sensor_checker.cpp?
187 // undervoltage crancking!
188 if (getEngineState()->undervoltageCrankingTimer.getElapsedSeconds() > 1) {
189 warningTsReport(ObdCode::OBD_System_Voltage_Low, "Cranking on low battery!");
190 }
191 } else {
193 }
194
196
197#if EFI_PROD_CODE
198 void baroLps25Update();
200#endif // EFI_PROD_CODE
202}
void updateSlowSensors()
Definition engine.cpp:208
void checkShutdown()
Definition engine.cpp:468
bool slowCallBackWasInvoked
Definition engine.h:304
void efiWatchdog()
Definition engine.cpp:427
OutputPin o2heater
Definition efi_gpio.h:99
RegisteredOutputPin starterRelayDisable
Definition efi_gpio.h:84
Timer undervoltageCrankingTimer
bool isRunning() const
bool isCranking() const override
static float getOrZero(SensorType type)
Definition sensor.h:83
void updateDynoView()
Definition dynoview.cpp:175
PUBLIC_API_WEAK void boardPeriodicSlowCallback()
Definition engine.cpp:146
EngineState * getEngineState()
Definition engine.cpp:577
bool warningTsReport(ObdCode code, const char *fmt,...)
void updateGppwm()
Definition gppwm.cpp:58
void baroLps25Update()
Definition init_baro.cpp:19
@ OBD_System_Voltage_Low
@ EnginePeriodicSlowCallback
void tle8888startup()
void updateVrThresholdPwm()
Definition vr_pwm.cpp:31

Referenced by doPeriodicSlowCallback().

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

◆ preCalculate()

void Engine::preCalculate ( )

Here we have a bunch of stuff which should invoked after configuration change so that we can prepare some helper structures

Definition at line 324 of file engine.cpp.

324 {
325#if EFI_TUNER_STUDIO
326 // we take 2 bytes of crc32, no idea if it's right to call it crc16 or not
327 // we have a hack here - we rely on the fact that engineMake is the first of three relevant fields
329
331#endif /* EFI_TUNER_STUDIO */
332}
TunerStudioOutputChannels outputChannels
Definition engine.h:109
static constexpr persistent_config_s * config

Referenced by incrementGlobalConfigurationVersion(), and readFromFlash().

Here is the caller graph for this function:

◆ reset()

void Engine::reset ( )
private

it's important for wrapAngle() that engineCycle field never has zero

Definition at line 293 of file engine.cpp.

293 {
294 /**
295 * it's important for wrapAngle() that engineCycle field never has zero
296 */
298 resetLua();
299}
void resetLua()
Definition engine.cpp:301
angle_t engineCycle
@ FOUR_STROKE_CRANK_SENSOR
angle_t getEngineCycle(operation_mode_e operationMode)
Here is the call graph for this function:

◆ resetEngineSnifferIfInTestMode()

void Engine::resetEngineSnifferIfInTestMode ( )

Definition at line 53 of file engine.cpp.

53 {
54#if EFI_ENGINE_SNIFFER
56 // TODO: what is the exact reasoning for the exact engine sniffer pause time I wonder
59 }
60#endif /* EFI_ENGINE_SNIFFER */
61}
bool isFunctionalTestMode
Definition engine.h:340
efitick_t pauseEngineSnifferUntilNt
WaveChart waveChart

Referenced by setEngineType(), setTriggerEmulatorRPM(), setTriggerType(), setValue(), and setWholeTimingMapCmd().

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

◆ resetLua()

void Engine::resetLua ( )

Definition at line 301 of file engine.cpp.

301 {
302 // todo: https://github.com/rusefi/rusefi/issues/4308
303 engineState.lua = {};
307 engineState.lua.luaIgnCut = false;
308 engineState.lua.luaFuelCut = false;
310#if EFI_BOOST_CONTROL
311 module<BoostController>().unmock().resetLua();
312#endif // EFI_BOOST_CONTROL
315#if EFI_IDLE_CONTROL
316 module<IdleController>().unmock().luaAdd = 0;
317#endif // EFI_IDLE_CONTROL
318}

Referenced by reset().

Here is the caller graph for this function:

◆ setConfig()

void Engine::setConfig ( )

Definition at line 397 of file engine.cpp.

397 {
398#if !EFI_UNIT_TEST
399// huh should this be happy? static_assert(config != nullptr);
400#endif
401 efi::clear(config);
402
404}
void injectEngineReferences()
Definition engine.cpp:388

Referenced by runRusEfi().

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

◆ updateSlowSensors()

void Engine::updateSlowSensors ( )

We are executing these heavy (logarithm) methods from outside the trigger callbacks for performance reasons. See also periodicFastCallback

Definition at line 208 of file engine.cpp.

208 {
210
211#if EFI_PROD_CODE
212 // todo: extract method? do better? see https://github.com/rusefi/rusefi/issues/7511 for details
213 engine->module<InjectorModelSecondary>()->updateState();
214 engine->module<InjectorModelPrimary>()->updateState();
215#endif // EFI_PROD_CODE
216
217#if EFI_SHAFT_POSITION_INPUT
220#endif // EFI_SHAFT_POSITION_INPUT
221}
void updateSwitchInputs()
Definition engine.cpp:254
constexpr auto & module()
Definition engine.h:200

Referenced by periodicSlowCallback(), and testRusefiMethods().

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

◆ updateSwitchInputs()

void Engine::updateSwitchInputs ( )

Definition at line 254 of file engine.cpp.

254 {
255 // this value is not used yet
259#if EFI_GPIO_HARDWARE
260 {
261 bool currentState;
262 if (hasAcToggle()) {
263 currentState = getAcToggle();
264#ifdef EFI_KLINE
265 } else if (engineConfiguration->hondaK) {
266extern bool kAcRequestState;
267 currentState = kAcRequestState;
268#endif // EFI_KLINE
269 } else {
270 currentState = engine->engineState.lua.acRequestState;
271 }
272 AcController & acController = engine->module<AcController>().unmock();
273 if (engine->acButtonSwitchedState.update(currentState)) {
274 acController.timeSinceStateChange.reset();
275 }
276 }
277
279
280#endif // EFI_GPIO_HARDWARE
281}
bool getAcToggle()
bool hasAcToggle()
Timer timeSinceStateChange
Definition ac_control.h:16
SwitchedState brakePedalSwitchedState
Definition engine.h:215
SwitchedState clutchUpSwitchedState
Definition engine.h:214
SwitchedState acButtonSwitchedState
Definition engine.h:216
bool update(bool newState)
Definition efi_output.cpp:9
bool getBrakePedalState()
Definition engine.cpp:243
static bool getClutchUpState()
Definition engine.cpp:233
bool getClutchDownState()
Definition engine.cpp:223
void pokeAuxDigital()
bool kAcRequestState
Definition kline.cpp:31

Referenced by updateSlowSensors().

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

◆ updateTriggerConfiguration()

void Engine::updateTriggerConfiguration ( )

Definition at line 133 of file engine.cpp.

133 {
134#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
135 // we have a confusing threading model so some synchronization would not hurt
136 chibios_rt::CriticalSectionLocker csl;
137
139
142 }
143#endif /* EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
144}
void prepareOutputSignals()

Referenced by applyNonPersistentConfiguration(), and onConfigurationChangeTriggerCallback().

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

Field Documentation

◆ acButtonSwitchedState

SwitchedState Engine::acButtonSwitchedState {&engineModules.get<AcController>().unmock().acButtonState}

Definition at line 216 of file engine.h.

Referenced by sendQcBenchButtonCounters(), and updateSwitchInputs().

◆ allowCanTx

bool Engine::allowCanTx = true

Sometimes for instance during shutdown we need to completely supress CAN TX

Definition at line 114 of file engine.h.

Referenced by configureRusefiLuaHooks(), and CanTxMessage::~CanTxMessage().

◆ antilagController

AntilagSystemBase Engine::antilagController {}

◆ auxValves

AuxActor Engine::auxValves[AUX_DIGITAL_VALVE_COUNT][2] {}

Definition at line 253 of file engine.h.

253{};

Referenced by initAuxValves().

◆ bailedOnDwellCount

int Engine::bailedOnDwellCount = 0
private

Definition at line 259 of file engine.h.

Referenced by getBailedOnDwellCount(), and incrementBailedOnDwellCount().

◆ brakePedalSwitchedState

SwitchedState Engine::brakePedalSwitchedState {&engineState.brakePedalState}

◆ clutchUpSwitchedState

SwitchedState Engine::clutchUpSwitchedState {&engineState.clutchUpState}

◆ configBurnTimer

Timer Engine::configBurnTimer {}

Definition at line 308 of file engine.h.

308{};

Referenced by assertTimeIsLinear(), and writeToFlashNowImpl().

◆ cylinders

OneCylinder Engine::cylinders[MAX_CYLINDER_COUNT] {}

Definition at line 291 of file engine.h.

291{};

Referenced by MapAveragingModule::onFastCallback(), and EngineCylinders::updateCylinders().

◆ dc_motors

dc_motors_s Engine::dc_motors {}

Definition at line 346 of file engine.h.

346{};

Referenced by getLiveData(), getOutputValueByHash(), and updateTunerStudioState().

◆ dynoInstance

DynoView Engine::dynoInstance {}

Definition at line 131 of file engine.h.

131{};

Referenced by getDynoviewHP(), getDynoviewTorque(), and updateDynoView().

◆ engineModules

type_list< Mockable<InjectorModelPrimary>, Mockable<InjectorModelSecondary>,#if EFI_IDLE_CONTROL Mockable<IdleController>,#endif TriggerScheduler,#if EFI_HPFP && EFI_ENGINE_CONTROL Mockable<HpfpController>,#endif #if EFI_ENGINE_CONTROL Mockable<ThrottleModel>,#endif #if EFI_ALTERNATOR_CONTROL AlternatorController,#endif MainRelayController, Mockable<IgnitionController>, Mockable<AcController>, PrimeController, DfcoController,#if EFI_HD_ACR HarleyAcr,#endif Mockable<WallFuelController>, KnockController, SensorChecker,#if EFI_ENGINE_CONTROL Mockable<LimpManager>,#endif #if EFI_VVT_PID VvtController1, VvtController2, VvtController3, VvtController4,#endif #if EFI_BOOST_CONTROL BoostController,#endif TpsAccelEnrichment,#if EFI_LAUNCH_CONTROL NitrousController,#endif #if EFI_LTFT_CONTROL LongTermFuelTrim,#endif ShortTermFuelTrim,#include "modules_list_generated.h" EngineModule > Engine::engineModules {}

◆ engineState

EngineState Engine::engineState {}

Definition at line 344 of file engine.h.

344{};

Referenced by alphax_2chan_ConfigOverrides(), auxPlainPinTurnOn(), HpfpQuantity::calcFuelPercent(), canDashboardHaltech(), EtbController::checkStatus(), configureRusefiLuaHooks(), detectHellenBoardType(), Engine(), fireSparkAndPrepareNextSchedule(), firmwareErrorV(), getAcrState(), getAdvanceCorrections(), SpeedDensityAirmass::getAirmass(), AngleBasedEvent::getAngleFromNow(), getBaseFuelMass(), getBoardId(), getBrakePedalState(), getClutchDownState(), getClutchUpState(), getCrankingFuel3(), getEngineState(), getInjectionMass(), getInjectorDutyCycle(), getInjectorDutyCycleStage2(), getLiveData(), getMultiSparkCount(), getOutputValueByHash(), getPerCylinderFiringOrderOffset(), getRunningAdvance(), getRunningFuel(), DfcoController::getState(), AirmassVeModelBase::getVe(), handleGetConfigErorr(), handleGetDataRequest(), handleTestCommand(), hellen154_hyundai_boardConfigOverrides(), hellen_MiataNB2_boardConfigOverrides(), initDataStructures(), initializeIgnitionActions(), is_F_OrOlder(), AemXSeriesWideband::isHeaterAllowed(), isMegaModuleRevision(), lua_getDigital(), obdOnCanPacketRx(), MapAveragingModule::onEnginePhase(), MapAveragingModule::onFastCallback(), KnockControllerBase::onKnockSenseCompleted(), HarleyAcr::onSlowCallback(), onTriggerEventSparkLogic(), overFireSparkAndPrepareNextSchedule(), periodicFastCallback(), EngineState::periodicFastCallback(), populateFrame(), populateFrame(), populateFrame(), populateFrame(), populateFrame(), populateFrame(), prepareCylinderIgnitionSchedule(), recalculateAuxValveTiming(), WarningCodeState::refreshTs(), reset(), resetLua(), runOneLua(), sayHello(), scheduleOpen(), scheduleSparkEvent(), sendWidebandInfo(), Generic4TransmissionController::setPcState(), slowStartStopButtonCallback(), startAveraging(), startDwellByTurningSparkPinHigh(), startStopButtonToggle(), testRusefiMethods(), THD_FUNCTION(), OneCylinder::updateCylinderNumber(), updateFuelCorrections(), updateFuelInfo(), LimpManager::updateState(), updateSwitchInputs(), ShiftTorqueReductionController::updateTriggerPinState(), updateTunerStudioState(), and warningVA().

◆ engineTypeChangeTimer

Timer Engine::engineTypeChangeTimer {}

Definition at line 309 of file engine.h.

309{};

Referenced by needToTriggerTsRefresh(), and onApplyPreset().

◆ etbAutoTune

bool Engine::etbAutoTune = false

◆ etbControllers

IEtbController* Engine::etbControllers[ETB_COUNT] = {nullptr}

◆ etbIgnoreJamProtection

bool Engine::etbIgnoreJamProtection = false

Definition at line 297 of file engine.h.

Referenced by LimpManager::allowElectronicThrottle(), and handleCommandX14().

◆ fuelComputer

FuelComputer Engine::fuelComputer {}

◆ gearController

GearControllerBase* Engine::gearController = nullptr

Definition at line 210 of file engine.h.

Referenced by doPeriodicSlowCallback(), getLiveData(), and initGearController().

◆ globalConfigurationVersion

int Engine::globalConfigurationVersion = 0

This counter is incremented every time user adjusts ECU parameters online (either via rusEfi console or other tuning software)

Definition at line 315 of file engine.h.

Referenced by getGlobalConfigurationVersion(), and incrementGlobalConfigurationVersion().

◆ hardSparkLimiter

SoftSparkLimiter Engine::hardSparkLimiter {true}

Definition at line 224 of file engine.h.

224{true};

Referenced by onTriggerEventSparkLogic(), and EngineState::updateSparkSkip().

◆ ignitionEvents

IgnitionEventList Engine::ignitionEvents {}

◆ ignitionState

IgnitionState Engine::ignitionState {}

◆ injectionEvents

FuelSchedule Engine::injectionEvents {}

◆ isFunctionalTestMode

bool Engine::isFunctionalTestMode = false

are we running any kind of functional test? this affect some areas

Definition at line 340 of file engine.h.

Referenced by enableOrDisable(), and resetEngineSnifferIfInTestMode().

◆ isPwmEnabled

bool Engine::isPwmEnabled = true

Definition at line 117 of file engine.h.

Referenced by applyPinState(), and enableOrDisable().

◆ isRunningPwmTest

bool Engine::isRunningPwmTest = false

Definition at line 334 of file engine.h.

Referenced by efiWatchdog().

◆ lambdaMonitor

LambdaMonitor Engine::lambdaMonitor {}

◆ launchController

LaunchControlBase Engine::launchController {}

◆ luaDigitalInputState

SimpleSwitchedState Engine::luaDigitalInputState[LUA_DIGITAL_INPUT_COUNT] {}

Definition at line 217 of file engine.h.

217{};

Referenced by pokeAuxDigital(), and sendQcBenchAuxDigitalCounters().

◆ m_ltit

LongTermIdleTrim Engine::m_ltit

◆ mockAirmassModel

AirmassModelBase* Engine::mockAirmassModel {}

Definition at line 382 of file engine.h.

382{};

Referenced by getAirmassModel().

◆ needTdcCallback

bool Engine::needTdcCallback = true

Definition at line 257 of file engine.h.

Referenced by onTdcCallback().

◆ onIgnitionEvent

std::function<void(IgnitionEvent*, bool)> Engine::onIgnitionEvent

Definition at line 280 of file engine.h.

Referenced by fireSparkAndPrepareNextSchedule(), and turnSparkPinHighStartCharging().

◆ onScheduleOverFireSparkAndPrepareNextSchedule

std::function<void(const IgnitionEvent&, efitick_t)> Engine::onScheduleOverFireSparkAndPrepareNextSchedule = [](const IgnitionEvent&, efitick_t) -> void {}

Definition at line 283 of file engine.h.

284{};

Referenced by scheduleSparkEvent().

◆ onScheduleTurnSparkPinHighStartCharging

std::function<void(const IgnitionEvent&, efitick_t, angle_t, efitick_t)> Engine::onScheduleTurnSparkPinHighStartCharging = [](const IgnitionEvent&, efitick_t, angle_t, efitick_t) -> void {}

Definition at line 281 of file engine.h.

282{};

Referenced by scheduleSparkEvent().

◆ outputChannels

TunerStudioOutputChannels Engine::outputChannels {}

Definition at line 109 of file engine.h.

109{};

Referenced by adcOnchipSlowUpdate(), attachMsdSdCard(), baseMCUInit(), canInfo(), checkIfTuningVeNow(), EtbController::checkStatus(), TunerStudio::cmdOutputChannels(), completionCallback(), configureRusefiLuaHooks(), deattachMsdSdCard(), TriggerCentral::decodeMapCam(), deinitMmc(), endAveraging(), executorStatistics(), fastAdcDoneCB(), fastAdcErrorCB(), fireSparkAndPrepareNextSchedule(), getAdvanceCorrections(), VvtController::getClosedLoop(), BoostController::getClosedLoop(), EtbController::getClosedLoopAutotune(), IdleController::getIdlePosition(), getLiveData(), BoostController::getOpenLoop(), getOutputValueByHash(), SpeedDensityAirmass::getPredictiveMap(), getRunningAdvance(), BoostController::getSetpoint(), VvtController::getSetpoint(), FuelComputer::getTargetLambda(), getTunerStudioOutputChannels(), AirmassVeModelBase::getVe(), handleFuel(), handleShaftSignal(), handleVvtCamSignal(), handleWidebandCan(), initElectronicThrottle(), initMmc(), TriggerCentral::isMapCamSync(), SpeedDensityAirmass::logAndGetFallback(), lua_setDebug(), luaHeapAlloc(), mapAveragingAdcCallback(), mountMmc(), onFastAdcComplete(), AlternatorController::onFastCallback(), PrimeController::onPrimeStart(), onTransitionEvent(), onTriggerEventSparkLogic(), InjectionEvent::onTriggerTooth(), pingWideband(), populateFrame(), populateFrame(), StepperMotorBase::postCurrentPosition(), GearControllerBase::postState(), preCalculate(), prepareCylinderIgnitionSchedule(), printErrorCounters(), printFullAdcReport(), printUid(), processLastKnockEvent(), readGppwmChannel(), WarningCodeState::refreshTs(), reportLogicAnalyzerToTS(), runBench(), runOneLua(), sdFormat(), sdLoggerCreateFile(), IgnitionOutputPin::setHigh(), IgnitionOutputPin::setLow(), EtbController::setOutput(), setStatus(), setToothLogReady(), slowAdcErrorCB(), startAveraging(), AdcDevice::startConversionI(), startLua(), MapAverager::stop(), ShutdownController::stopEngine(), tle8888PostState(), triggerScopeDisable(), triggerScopeGetBuffer(), tsCalibrationIsIdle(), tsCalibrationSetData(), tsCalibrationSetIdle(), unmountMmc(), InjectionEvent::update(), SimpleTransmissionController::update(), updateDevConsoleState(), updateEgtSensors(), updateFlags(), updateFuelCorrections(), updateFuelInfo(), updateFuelResults(), updateFuelSensors(), updateGppwm(), updateIgnition(), updateLambda(), updateMiscSensors(), updatePressures(), updateRawSensors(), updateSdCardLiveFlags(), updateTempSensors(), updateThrottles(), updateTunerStudioState(), updateVehicleSpeed(), updateVvtSensors(), and CanTxMessage::~CanTxMessage().

◆ pauseCANdueToSerial

bool Engine::pauseCANdueToSerial = false

ELM327 cannot handle both RX and TX at the same time, we have to stay quite once first ISO/TP packet was detected this is a pretty temporary hack only while we are trying ELM327, long term ISO/TP and rusEFI broadcast should find a way to coexists

Definition at line 123 of file engine.h.

Referenced by CanWrite::PeriodicTask(), and CanStreamerState::receiveFrame().

◆ rpmCalculator

RpmCalculator Engine::rpmCalculator {}

◆ scheduler [1/3]

SingleTimerExecutor Engine::scheduler {}

◆ scheduler [2/3]

SleepExecutor Engine::scheduler {}

Definition at line 275 of file engine.h.

275{};

◆ scheduler [3/3]

TestExecutor Engine::scheduler {}

Definition at line 278 of file engine.h.

278{};

◆ secondListener

TriggerStateListener* Engine::secondListener = nullptr

Definition at line 247 of file engine.h.

Referenced by nextListener().

◆ sensors

SensorsState Engine::sensors {}

◆ sent_state

sent_state_s Engine::sent_state {}

Definition at line 348 of file engine.h.

348{};

Referenced by getLiveData(), and SentDecoderThread().

◆ shiftTorqueReductionController

ShiftTorqueReductionController Engine::shiftTorqueReductionController {}

◆ slowCallBackWasInvoked

bool Engine::slowCallBackWasInvoked = false

Definition at line 304 of file engine.h.

Referenced by EngineState::periodicFastCallback(), and periodicSlowCallback().

◆ softSparkLimiter

SoftSparkLimiter Engine::softSparkLimiter {false}

Definition at line 222 of file engine.h.

222{false};

Referenced by onTriggerEventSparkLogic(), and EngineState::updateSparkSkip().

◆ startStopState

StartStopState Engine::startStopState {}

◆ tdcMarkEnabled

bool Engine::tdcMarkEnabled = true

Definition at line 301 of file engine.h.

Referenced by tdcMarkCallback().

◆ tdcScheduler

scheduling_s Engine::tdcScheduler[2] {}

Definition at line 290 of file engine.h.

290{};

Referenced by tdcMarkCallback().

◆ timeToStopIdleTest

efitimeus_t Engine::timeToStopIdleTest {}

Definition at line 351 of file engine.h.

351{};

Referenced by applyIACposition(), finishIdleTestIfNeeded(), and startIdleBench().

◆ triggerCentral

TriggerCentral Engine::triggerCentral {}

The documentation for this class was generated from the following files: