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 293 of file engine.cpp.

293 {
294 // Everything else has default initializers setup in generated file
297}
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 479 of file engine.cpp.

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

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 437 of file engine.cpp.

437 {
439 if (isRunningPwmTest) {
440 return;
441 }
442
443#if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
444 if (module<PrimeController>()->isPriming() || triggerCentral.engineMovedRecently()) {
445 // do not invoke check in priming or if engine moved recently, no need to assert safe pin state.
446 return;
447 }
448
451 // todo: make this a firmwareError assuming functional tests would run
452 warning(ObdCode::CUSTOM_ERR_2ND_WATCHDOG, "Some pins were turned off by 2nd pass watchdog");
453 }
454 return;
455 }
456
457 /**
458 * todo: better watch dog implementation should be implemented - see
459 * http://sourceforge.net/p/rusefi/tickets/96/
460 */
463#endif // EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
464}
bool isRunningBenchTest()
TriggerCentral triggerCentral
Definition engine.h:318
void onEngineHasStopped()
Definition engine.cpp:466
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:419
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 299 of file engine.cpp.

299 {
301}
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 398 of file engine.cpp.

398 {
399#if EFI_SHAFT_POSITION_INPUT
401 for (int camIndex = 0;camIndex < CAMS_PER_BANK;camIndex++) {
403 }
404#endif // EFI_SHAFT_POSITION_INPUT
405}
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 513 of file engine.cpp.

513 {
514 // TODO: this logic is currently broken
515#if 0 && EFI_MAIN_RELAY_CONTROL && EFI_PROD_CODE
516 // if we are in "ignition_on" mode and not in shutdown mode
517 if (stopEngineRequestTimeNt == 0 && ignitionOnTimeNt > 0) {
518 const float vBattThresholdOff = 5.0f;
519 // start the shutdown process if the ignition voltage dropped low
520 if (Sensor::get(SensorType::BatteryVoltage).value_or(VBAT_FALLBACK_VALUE) <= vBattThresholdOff) {
522 }
523 }
524
525 // we are not in the shutdown mode?
526 if (stopEngineRequestTimeNt == 0) {
527 return false;
528 }
529
530 const efitick_t turnOffWaitTimeoutNt = NT_PER_SECOND;
531 // We don't want any transients to step in, so we wait at least 1 second whatever happens.
532 // Also it's good to give the stepper motor some time to start moving to the initial position (or parking)
533 if ((getTimeNowNt() - stopEngineRequestTimeNt) < turnOffWaitTimeoutNt)
534 return true;
535
536 const efitick_t engineSpinningWaitTimeoutNt = 5 * NT_PER_SECOND;
537 // The engine is still spinning! Give it some time to stop (but wait no more than 5 secs)
538 if (isSpinning && (getTimeNowNt() - stopEngineRequestTimeNt) < engineSpinningWaitTimeoutNt)
539 return true;
540
541 // The idle motor valve is still moving! Give it some time to park (but wait no more than 10 secs)
542 // Usually it can move to the initial 'cranking' position or zero 'parking' position.
543 const efitick_t idleMotorWaitTimeoutNt = 10 * NT_PER_SECOND;
544 if (isIdleMotorBusy() && (getTimeNowNt() - stopEngineRequestTimeNt) < idleMotorWaitTimeoutNt)
545 return true;
546#endif /* EFI_MAIN_RELAY_CONTROL */
547 return false;
548}
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 550 of file engine.cpp.

550 {
551#if EFI_MAIN_RELAY_CONTROL
553#else
554 // if no main relay control, we assume it's always turned on
555 return true;
556#endif /* EFI_MAIN_RELAY_CONTROL */
557}
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(), IdleController::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(), overFireSparkAndPrepareNextSchedule(), 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 351 of file engine.cpp.

351 {
352 return secondListener;
353}
TriggerStateListener * secondListener
Definition engine.h:247

◆ onEngineHasStopped()

void Engine::onEngineHasStopped ( )

Definition at line 466 of file engine.cpp.

466 {
467#if EFI_ENGINE_CONTROL
468 ignitionEvents.isReady = false;
469#endif // EFI_ENGINE_CONTROL
470
471#if EFI_PROD_CODE || EFI_SIMULATOR
472 efiPrintf("Engine has stopped spinning.");
473#endif
474
475 // this invocation should be the last layer of defence in terms of making sure injectors/coils are not active
477}
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 581 of file engine.cpp.

581 {
582 engineModules.apply_all([](auto& m) { m.onEngineStop(); });
583}

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 345 of file engine.cpp.

345 {
347
349}
RpmCalculator rpmCalculator
Definition engine.h:306
void setSpinningUp(efitick_t nowNt)
triggerStateIndex("triggerStateIndex", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1592, 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 369 of file engine.cpp.

369 {
370 // TODO: this logic probably shouldn't be part of engine.cpp
371
372 // We only care about trigger shape once we have synchronized trigger. Anything could happen
373 // during first revolution and it's fine
374 if (wasSynchronized) {
376
377 // 'triggerStateListener is not null' means we are running a real engine and now just preparing trigger shape
378 // that's a bit of a hack, a sweet OOP solution would be a real callback or at least 'needDecodingErrorLogic' method?
379 if (isDecodingError) {
380#if EFI_PROD_CODE
382 efiPrintf("error: synchronizationPoint @ index %lu expected %d/%d got %d/%d",
388 }
389#endif /* EFI_PROD_CODE */
390 }
391
392 engine->triggerCentral.triggerErrorDetection.add(isDecodingError);
393 }
394
395}
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 355 of file engine.cpp.

355 {
356 // Needed for early instant-RPM detection
358
361
362 for (size_t i = 0; i < efi::size(triggerCentral.vvtState); i++) {
363 for (size_t j = 0; j < efi::size(triggerCentral.vvtState[0]); j++) {
365 }
366 }
367}
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 567 of file engine.cpp.

567 {
569
572
573
575
576 speedoUpdate();
577
578 engineModules.apply_all([](auto & m) { m.onFastCallback(); });
579}
static bool call_board_override(std::optional< FuncType > board_override, Args &&... args)
void periodicFastCallback()
Definition engine2.cpp:154
void boardPeriodicFastCallback()
Definition engine.cpp:155
std::optional< setup_custom_board_overrides_type > custom_board_periodicFastCallback
Definition engine.cpp:149
@ 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 159 of file engine.cpp.

159 {
161
162#if EFI_SHAFT_POSITION_INPUT
163 // Re-read config in case it's changed
165 for (int camIndex = 0;camIndex < CAMS_PER_BANK;camIndex++) {
167 }
168
170 enginePins.o2heater.setValue(getEngineState()->heaterControlEnabled);
172#endif // EFI_SHAFT_POSITION_INPUT
173
174 efiWatchdog();
177
178 module<TpsAccelEnrichment>()->onNewValue(Sensor::getOrZero(SensorType::Tps1));
179
181
182 updateGppwm();
183
184 engine->engineModules.apply_all([](auto & m) { m.onSlowCallback(); });
185
186#if (BOARD_TLE8888_COUNT > 0)
188#endif
189
190#if EFI_DYNO_VIEW
192#endif
193
194 // TODO: move to sensor_checker.cpp?
196 // undervoltage crancking!
197 if (getEngineState()->undervoltageCrankingTimer.getElapsedSeconds() > 1) {
198 warningTsReport(ObdCode::OBD_System_Voltage_Low, "Cranking on low battery!");
199 }
200 } else {
202 }
203
205
206#if EFI_PROD_CODE
207 void baroLps25Update();
209#endif // EFI_PROD_CODE
212}
void updateSlowSensors()
Definition engine.cpp:218
void checkShutdown()
Definition engine.cpp:479
bool slowCallBackWasInvoked
Definition engine.h:304
void efiWatchdog()
Definition engine.cpp:437
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
std::optional< setup_custom_board_overrides_type > custom_board_periodicSlowCallback
Definition engine.cpp:148
EngineState * getEngineState()
Definition engine.cpp:589
void boardPeriodicSlowCallback()
Definition engine.cpp:151
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 334 of file engine.cpp.

334 {
335#if EFI_TUNER_STUDIO
336 // we take 2 bytes of crc32, no idea if it's right to call it crc16 or not
337 // we have a hack here - we rely on the fact that engineMake is the first of three relevant fields
339
341#endif /* EFI_TUNER_STUDIO */
342}
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 303 of file engine.cpp.

303 {
304 /**
305 * it's important for wrapAngle() that engineCycle field never has zero
306 */
308 resetLua();
309}
void resetLua()
Definition engine.cpp:311
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 311 of file engine.cpp.

311 {
312 // todo: https://github.com/rusefi/rusefi/issues/4308
313 engineState.lua = {};
317 engineState.lua.luaIgnCut = false;
318 engineState.lua.luaFuelCut = false;
320#if EFI_BOOST_CONTROL
321 module<BoostController>().unmock().resetLua();
322#endif // EFI_BOOST_CONTROL
325#if EFI_IDLE_CONTROL
326 module<IdleController>().unmock().luaAdd = 0;
327#endif // EFI_IDLE_CONTROL
328}

Referenced by reset().

Here is the caller graph for this function:

◆ setConfig()

void Engine::setConfig ( )

Definition at line 407 of file engine.cpp.

407 {
408#if !EFI_UNIT_TEST
409// huh should this be happy? static_assert(config != nullptr);
410#endif
411 efi::clear(config);
412
414}
void injectEngineReferences()
Definition engine.cpp:398

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 218 of file engine.cpp.

218 {
220
221#if EFI_PROD_CODE
222 // todo: extract method? do better? see https://github.com/rusefi/rusefi/issues/7511 for details
223 engine->module<InjectorModelSecondary>()->updateState();
224 engine->module<InjectorModelPrimary>()->updateState();
225#endif // EFI_PROD_CODE
226
227#if EFI_SHAFT_POSITION_INPUT
230#endif // EFI_SHAFT_POSITION_INPUT
231}
void updateSwitchInputs()
Definition engine.cpp:264
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 264 of file engine.cpp.

264 {
265 // this value is not used yet
269#if EFI_GPIO_HARDWARE
270 {
271 bool currentState;
272 if (hasAcToggle()) {
273 currentState = getAcToggle();
274#ifdef EFI_KLINE
275 } else if (engineConfiguration->hondaK) {
276extern bool kAcRequestState;
277 currentState = kAcRequestState;
278#endif // EFI_KLINE
279 } else {
280 currentState = engine->engineState.lua.acRequestState;
281 }
282 AcController & acController = engine->module<AcController>().unmock();
283 if (engine->acButtonSwitchedState.update(currentState)) {
284 acController.timeSinceStateChange.reset();
285 }
286 }
287
289
290#endif // EFI_GPIO_HARDWARE
291}
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:253
static bool getClutchUpState()
Definition engine.cpp:243
bool getClutchDownState()
Definition engine.cpp:233
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(), FlexSensor::callback(), canInfo(), checkIfTuningVeNow(), EtbController::checkStatus(), TunerStudio::cmdOutputChannels(), completionCallback(), configureRusefiLuaHooks(), deattachMsdSdCard(), TriggerCentral::decodeMapCam(), deinitMmc(), endAveraging(), executorStatistics(), fastAdcDoneCB(), fastAdcErrorCB(), 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: