rusEFI
The most advanced open source ECU
Public Member Functions | Data Fields | Private Member Functions
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 ()
 
void resetLua ()
 
void OnTriggerStateProperState (efitick_t nowNt) override
 
void OnTriggerSynchronization (bool wasSynchronized, bool isDecodingError) override
 
void OnTriggerSynchronizationLost () override
 
void setConfig ()
 
int getGlobalConfigurationVersion (void) const
 
void periodicFastCallback ()
 
void periodicSlowCallback ()
 
void updateSlowSensors ()
 
void updateSwitchInputs ()
 
void updateTriggerWaveform ()
 
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

bool enableOverdwellProtection = true
 
TunerStudioOutputChannels outputChannels
 
bool allowCanTx = true
 
bool isPwmEnabled = true
 
const char * prevOutputName = nullptr
 
bool pauseCANdueToSerial = false
 
PinRepository pinRepository
 
IEtbControlleretbControllers [ETB_COUNT] = {nullptr}
 
FuelComputer fuelComputer
 
type_list< Mockable< InjectorModelPrimary >, Mockable< InjectorModelSecondary >,#if EFI_IDLE_CONTROL Mockable< IdleController >,#endif TriggerScheduler,#if EFI_HPFP &&EFI_ENGINE_CONTROL HpfpController,#endif #if EFI_ENGINE_CONTROL Mockable< ThrottleModel >,#endif #if EFI_ALTERNATOR_CONTROL AlternatorController,#endif FuelPumpController, MainRelayController, IgnitionController, Mockable< AcController >, FanControl1, FanControl2, PrimeController, DfcoController,#if EFI_HD_ACR HarleyAcr,#endif Mockable< WallFuelController >,#if EFI_VEHICLE_SPEED GearDetector, TripOdometer,#endif KnockController, SensorChecker,#if EFI_ENGINE_CONTROL LimpManager,#endif #if EFI_VVT_PID VvtController1, VvtController2, VvtController3, VvtController4,#endif #if EFI_BOOST_CONTROL BoostController,#endif EngineModuleengineModules
 
GearControllerBasegearController
 
SwitchedState clutchUpSwitchedState
 
SwitchedState brakePedalSwitchedState
 
SwitchedState acButtonSwitchedState
 
SimpleSwitchedState luaDigitalInputState [LUA_DIGITAL_INPUT_COUNT]
 
LaunchControlBase launchController
 
SoftSparkLimiter softSparkLimiter
 
SoftSparkLimiter hardSparkLimiter
 
AntilagSystemBase antilagController
 
SoftSparkLimiter ALSsoftSparkLimiter
 
LambdaMonitor lambdaMonitor
 
IgnitionState ignitionState
 
Timer startStopStateLastPush
 
LocalVersionHolder versionForConfigurationListeners
 
AuxActor auxValves [AUX_DIGITAL_VALVE_COUNT][2]
 
bool needTdcCallback = true
 
int bailedOnDwell = 0
 
SingleTimerExecutor executor
 
SleepExecutor executor
 
TestExecutor executor
 
std::function< void(IgnitionEvent *, bool)> onIgnitionEvent
 
FuelSchedule injectionEvents
 
IgnitionEventList ignitionEvents
 
scheduling_s tdcScheduler [2]
 
bool etbAutoTune = false
 
bool tdcMarkEnabled = true
 
bool slowCallBackWasInvoked = false
 
RpmCalculator rpmCalculator
 
Timer configBurnTimer
 
int globalConfigurationVersion = 0
 
TpsAccelEnrichment tpsAccelEnrichment
 
TriggerCentral triggerCentral
 
float stftCorrection [STFT_BANK_COUNT] = {0}
 
bool isRunningPwmTest = false
 
bool isFunctionalTestMode = false
 
EngineState engineState
 
dc_motors_s dc_motors
 
sent_state_s sent_state
 
percent_t blipIdlePosition
 
efitimeus_t timeToStopBlip = 0
 
efitimeus_t timeToStopIdleTest = 0
 
SensorsState sensors
 
AirmassModelBasemockAirmassModel = nullptr
 

Private Member Functions

void reset ()
 
void injectEngineReferences ()
 

Detailed Description

Definition at line 89 of file engine.h.

Constructor & Destructor Documentation

◆ Engine()

Engine::Engine ( )

Definition at line 282 of file engine.cpp.

285  acButtonSwitchedState(&module<AcController>().unmock().acButtonState)
286 
287 #if EFI_LAUNCH_CONTROL
288 
289  , softSparkLimiter(false), hardSparkLimiter(true)
290 
291 #if EFI_ANTILAG_SYSTEM
292  , ALSsoftSparkLimiter(false)
293 #endif /* EFI_ANTILAG_SYSTEM */
294 
295 #endif // EFI_LAUNCH_CONTROL
296 {
297  reset();
298 }
SoftSparkLimiter softSparkLimiter
Definition: engine.h:190
SoftSparkLimiter ALSsoftSparkLimiter
Definition: engine.h:200
EngineState engineState
Definition: engine.h:305
SwitchedState brakePedalSwitchedState
Definition: engine.h:184
SwitchedState clutchUpSwitchedState
Definition: engine.h:183
SwitchedState acButtonSwitchedState
Definition: engine.h:185
SoftSparkLimiter hardSparkLimiter
Definition: engine.h:192
void reset()
Definition: engine.cpp:304
acButtonState("AC switch", SensorCategory.SENSOR_INPUTS, FieldType.INT8, 1068, 1.0, -1.0, -1.0, "")
Here is the call graph for this function:

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

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

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

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

◆ getGlobalConfigurationVersion()

int Engine::getGlobalConfigurationVersion ( void  ) const

Definition at line 300 of file engine.cpp.

300  {
302 }
int globalConfigurationVersion
Definition: engine.h:271

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

Here is the caller graph for this function:

◆ injectEngineReferences()

void Engine::injectEngineReferences ( )
private

Definition at line 393 of file engine.cpp.

393  {
394 #if EFI_SHAFT_POSITION_INPUT
396  for (int camIndex = 0;camIndex < CAMS_PER_BANK;camIndex++) {
398  }
399 #endif // EFI_SHAFT_POSITION_INPUT
400 }
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 503 of file engine.cpp.

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

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

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

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

◆ module()

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

Slightly shorter helper function to keep the code looking clean.

Definition at line 174 of file engine.h.

174  {
175  return engineModules.get<get_t>();
176  }
type_list< Mockable< InjectorModelPrimary >, Mockable< InjectorModelSecondary >,#if EFI_IDLE_CONTROL Mockable< IdleController >,#endif TriggerScheduler,#if EFI_HPFP &&EFI_ENGINE_CONTROL HpfpController,#endif #if EFI_ENGINE_CONTROL Mockable< ThrottleModel >,#endif #if EFI_ALTERNATOR_CONTROL AlternatorController,#endif FuelPumpController, MainRelayController, IgnitionController, Mockable< AcController >, FanControl1, FanControl2, PrimeController, DfcoController,#if EFI_HD_ACR HarleyAcr,#endif Mockable< WallFuelController >,#if EFI_VEHICLE_SPEED GearDetector, TripOdometer,#endif KnockController, SensorChecker,#if EFI_ENGINE_CONTROL LimpManager,#endif #if EFI_VVT_PID VvtController1, VvtController2, VvtController3, VvtController4,#endif #if EFI_BOOST_CONTROL BoostController,#endif EngineModule > engineModules
Definition: engine.h:168
constexpr auto get() -> std::enable_if_t< decltype(first)::template has< get_t >(), decltype(first.template get< get_t >())>
Definition: type_list.h:66

Referenced by WallFuel::adjust(), applyPidSettings(), auxPlainPinTurnOn(), canDashboardHaltech(), EtbController::checkStatus(), configureRusefiLuaHooks(), getAdvanceCorrections(), AlternatorController::getClosedLoop(), IdleController::getClosedLoop(), getIdlePosition(), getInjectionMass(), getLimpManager(), getOutputValueByName(), PrimeController::getPrimeDuration(), getRunningAdvance(), IdleController::getRunningOpenLoop(), IdleController::getTargetRpm(), AirmassVeModelBase::getVe(), handleGetDataRequest(), TriggerCentral::handleShaftSignal(), hipThread(), initAlternatorCtrl(), initBoostCtrl(), initVvtActuators(), LambdaMonitorBase::isCurrentlyGood(), lua_getDigital(), mainTriggerCallback(), FanController::onSlowCallback(), InjectionEvent::onTriggerTooth(), EngineState::periodicFastCallback(), populateFrame(), processLastKnockEvent(), resetLua(), HpfpController::scheduleNextCycle(), scheduleOpen(), scheduleSparkEvent(), setAltPFactor(), shouldUpdateCorrection(), startIdleThread(), updateFlags(), updateFuelResults(), LimpManager::updateState(), updateSwitchInputs(), and updateVehicleSpeed().

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

◆ onEngineHasStopped()

void Engine::onEngineHasStopped ( )

Definition at line 456 of file engine.cpp.

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

Referenced by efiWatchdog().

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

◆ onSparkFireKnockSense()

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

Definition at line 161 of file knock_controller.cpp.

161  {
162 #if EFI_HIP_9011 || EFI_SOFTWARE_KNOCK
163  cylinderNumberCopy = cylinderNumber;
164  scheduleByAngle(nullptr, nowNt,
165  /*angle*/engineConfiguration->knockDetectionWindowStart, { startKnockSampling, engine });
166 #else
167  UNUSED(cylinderNumber);
168  UNUSED(nowNt);
169 #endif
170 
171 #if EFI_HIP_9011
172  hip9011_onFireEvent(cylinderNumber, nowNt);
173 #endif
174 }
void hip9011_onFireEvent(uint8_t cylinderNumber, efitick_t nowNt)
Definition: hip9011.cpp:275
UNUSED(samplingTimeSeconds)
static uint8_t cylinderNumberCopy
engine_configuration_s * engineConfiguration
efitick_t scheduleByAngle(scheduling_s *timer, efitick_t nowNt, angle_t angle, action_s 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)
overridevirtual

Implements TriggerStateListener.

Definition at line 346 of file engine.cpp.

346  {
348 }
RpmCalculator rpmCalculator
Definition: engine.h:263
void setSpinningUp(efitick_t nowNt)
Here is the call graph for this function:

◆ OnTriggerSynchronization()

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

Implements TriggerStateListener.

Definition at line 364 of file engine.cpp.

364  {
365  // TODO: this logic probably shouldn't be part of engine.cpp
366 
367  // We only care about trigger shape once we have synchronized trigger. Anything could happen
368  // during first revolution and it's fine
369  if (wasSynchronized) {
370  enginePins.triggerDecoderErrorPin.setValue(isDecodingError);
371 
372  // 'triggerStateListener is not null' means we are running a real engine and now just preparing trigger shape
373  // that's a bit of a hack, a sweet OOP solution would be a real callback or at least 'needDecodingErrorLogic' method?
374  if (isDecodingError) {
375 #if EFI_PROD_CODE
377  efiPrintf("error: synchronizationPoint @ index %d expected %d/%d got %d/%d",
383  }
384 #endif /* EFI_PROD_CODE */
385  }
386 
387  engine->triggerCentral.triggerErrorDetection.add(isDecodingError);
388  }
389 
390 }
RegisteredOutputPin triggerDecoderErrorPin
Definition: efi_gpio.h:116
void setValue(const char *msg, int logicValue, bool isForce=false)
Definition: efi_gpio.cpp:583
PrimaryTriggerDecoder triggerState
TriggerWaveform triggerShape
cyclic_buffer< int > triggerErrorDetection
current_cycle_state_s currentCycle
bool someSortOfTriggerError() const
size_t getExpectedEventCount(TriggerWheel channelIndex) const
Engine * engine
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 350 of file engine.cpp.

350  {
351  // Needed for early instant-RPM detection
353 
356 
357  for (size_t i = 0; i < efi::size(triggerCentral.vvtState); i++) {
358  for (size_t j = 0; j < efi::size(triggerCentral.vvtState[0]); j++) {
360  }
361  }
362 }
void resetState() override
VvtTriggerDecoder vvtState[BANKS_COUNT][CAMS_PER_BANK]
InstantRpmCalculator instantRpm
virtual void resetState()
composite packet size
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 557 of file engine.cpp.

557  {
559 
560 #if EFI_MAP_AVERAGING
562 #endif
563 
565 
566  tachUpdate();
567  speedoUpdate();
568 
569  engine->engineModules.apply_all([](auto & m) { m.onFastCallback(); });
570 }
void periodicFastCallback()
Definition: engine2.cpp:100
void refreshMapAveragingPreCalc()
@ EnginePeriodicFastCallback
void speedoUpdate()
Definition: speedometer.cpp:9
void apply_all(func_t const &f)
Definition: type_list.h:43
void tachUpdate()
Definition: tachometer.cpp:31

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

142  {
144 
145 #if EFI_SHAFT_POSITION_INPUT
146  // Re-read config in case it's changed
148  for (int camIndex = 0;camIndex < CAMS_PER_BANK;camIndex++) {
150  }
151 
153  enginePins.o2heater.setValue(getEngineState()->heaterControlEnabled);
155 #endif // EFI_SHAFT_POSITION_INPUT
156 
157  efiWatchdog();
159  checkShutdown();
160 
162 
164 
165  updateGppwm();
166 
167  engine->engineModules.apply_all([](auto & m) { m.onSlowCallback(); });
168 
169 #if (BOARD_TLE8888_COUNT > 0)
170  tle8888startup();
171 #endif
172 
173 #if EFI_DYNO_VIEW
174  updateDynoView();
175 #endif
176 
177  slowCallBackWasInvoked = true;
178 
179 #if EFI_PROD_CODE
180  void baroLps25Update();
181  baroLps25Update();
182 #endif // EFI_PROD_CODE
183 
184 #if ANALOG_HW_CHECK_MODE
185  criticalAssertVoid(isAdcChannelValid(engineConfiguration->clt.adcChannel), "No CLT setting");
186  efitimesec_t secondsNow = getTimeNowS();
187 
188 #if ! HW_CHECK_ALWAYS_STIMULATE
189  fail("HW_CHECK_ALWAYS_STIMULATE required to have self-stimulation")
190 #endif
191 
192  int hwCheckRpm = 204;
193  if (secondsNow > 2 && secondsNow < 180) {
194  assertCloseTo("RPM", Sensor::get(SensorType::Rpm).Value, hwCheckRpm);
195  } else if (!hasFirmwareError() && secondsNow > 180) {
196  static bool isHappyTest = false;
197  if (!isHappyTest) {
198  setTriggerEmulatorRPM(5 * hwCheckRpm);
199  efiPrintf("TEST PASSED");
200  isHappyTest = true;
201  }
202  }
203 
208 #endif // ANALOG_HW_CHECK_MODE
209 }
bool isAdcChannelValid(adc_channel_e hwChannel)
Definition: adc_inputs.h:20
void updateSlowSensors()
Definition: engine.cpp:215
void checkShutdown()
Definition: engine.cpp:469
bool slowCallBackWasInvoked
Definition: engine.h:261
void efiWatchdog()
Definition: engine.cpp:428
TpsAccelEnrichment tpsAccelEnrichment
Definition: engine.h:273
OutputPin o2heater
Definition: efi_gpio.h:94
RegisteredOutputPin starterRelayDisable
Definition: efi_gpio.h:81
bool isRunning() const
virtual float getRaw() const
Definition: sensor.h:162
static float getOrZero(SensorType type)
Definition: sensor.h:92
void onNewValue(float currentValue)
void updateDynoView()
Definition: dynoview.cpp:146
efitimesec_t getTimeNowS()
Current system time in seconds (32 bits)
Definition: efitime.cpp:42
static void assertCloseTo(const char *msg, float actual, float expected)
Definition: engine.cpp:135
EngineState * getEngineState()
Definition: engine.cpp:576
void updateGppwm()
Definition: gppwm.cpp:56
void baroLps25Update()
Definition: init_baro.cpp:19
@ EnginePeriodicSlowCallback
void tle8888startup()
Definition: smart_gpio.cpp:308
fail("EFI_SHAFT_POSITION_INPUT required to have EFI_EMULATE_POSITION_SENSORS") static_assert(sizeof(composite_logger_s)
void setTriggerEmulatorRPM(int rpm)
static void updateVrThresholdPwm(int rpm, size_t index)
Definition: vr_pwm.cpp:13

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

333  {
334 #if EFI_TUNER_STUDIO
335  // we take 2 bytes of crc32, no idea if it's right to call it crc16 or not
336  // we have a hack here - we rely on the fact that engineMake is the first of three relevant fields
338 
339  // we need and can empty warning message for CRC purposes
340  memset(config->warning_message, 0, sizeof(config->warning_message));
342 #endif /* EFI_TUNER_STUDIO */
343 }
TunerStudioOutputChannels outputChannels
Definition: engine.h:96
persistent_config_s * config

Referenced by incrementGlobalConfigurationVersion(), and validateConfiguration().

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

304  {
305  /**
306  * it's important for wrapAngle() that engineCycle field never has zero
307  */
309  resetLua();
310 }
void resetLua()
Definition: engine.cpp:312
angle_t engineCycle
Definition: engine_state.h:27
@ FOUR_STROKE_CRANK_SENSOR
Definition: rusefi_enums.h:254
angle_t getEngineCycle(operation_mode_e operationMode)

Referenced by Engine().

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

◆ resetEngineSnifferIfInTestMode()

void Engine::resetEngineSnifferIfInTestMode ( )

Definition at line 56 of file engine.cpp.

56  {
57 #if EFI_ENGINE_SNIFFER
59  // TODO: what is the exact reasoning for the exact engine sniffer pause time I wonder
61  waveChart.reset();
62  }
63 #endif /* EFI_ENGINE_SNIFFER */
64 }
bool isFunctionalTestMode
Definition: engine.h:301
efitick_t pauseEngineSnifferUntilNt
WaveChart waveChart

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

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

◆ resetLua()

void Engine::resetLua ( )

Definition at line 312 of file engine.cpp.

312  {
313  // todo: https://github.com/rusefi/rusefi/issues/4308
314  engineState.lua = {};
315  engineState.lua.fuelAdd = 0;
317  engineState.lua.luaDisableEtb = false;
318  engineState.lua.luaIgnCut = false;
319 #if EFI_BOOST_CONTROL
320  module<BoostController>().unmock().resetLua();
321 #endif // EFI_BOOST_CONTROL
324 #if EFI_IDLE_CONTROL
325  module<IdleController>().unmock().luaAdd = 0;
326 #endif // EFI_IDLE_CONTROL
327 }
IgnitionState ignitionState
Definition: engine.h:207

Referenced by reset().

Here is the caller graph for this function:

◆ setConfig()

void Engine::setConfig ( )

Definition at line 402 of file engine.cpp.

402  {
403  efi::clear(config);
404 
406 }
void injectEngineReferences()
Definition: engine.cpp:393

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

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

245  {
246 #if EFI_GPIO_HARDWARE
247  // this value is not used yet
250  }
251  {
252  bool currentState;
253  if (hasAcToggle()) {
254  currentState = getAcToggle();
255 #ifdef EFI_KLINE
256  } else if (engineConfiguration->hondaK) {
257 extern bool kAcRequestState;
258  currentState = kAcRequestState;
259 #endif // EFI_KLINE
260  } else {
261  currentState = engine->engineState.lua.acRequestState;
262  }
263  AcController & acController = engine->module<AcController>().unmock();
264  if (engine->acButtonSwitchedState.update(currentState)) {
265  acController.acSwitchLastChangeTimeMs = US2MS(getTimeNowUs());
266  }
267  }
269 
270 #if EFI_IDLE_CONTROL
273  }
274 #endif // EFI_IDLE_CONTROL
275 
277  pokeAuxDigital();
278 
279 #endif // EFI_GPIO_HARDWARE
280 }
bool getAcToggle()
Definition: allsensors.cpp:19
bool hasAcToggle()
Definition: allsensors.cpp:23
constexpr auto & module()
Definition: engine.h:174
bool update(bool newState)
Definition: efi_output.cpp:10
efitimeus_t getTimeNowUs()
Definition: efitime.cpp:26
static bool getClutchUpState()
Definition: engine.cpp:228
static bool getBrakePedalState()
Definition: engine.cpp:236
void pokeAuxDigital()
bool efiReadPin(brain_pin_e pin)
Definition: io_pins.cpp:89
bool kAcRequestState
Definition: kline.cpp:26
bool isBrainPinValid(brain_pin_e brainPin)

Referenced by updateSlowSensors().

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

◆ updateTriggerWaveform()

void Engine::updateTriggerWaveform ( )

Definition at line 118 of file engine.cpp.

118  {
119 
120 
121 #if EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT
122  // we have a confusing threading model so some synchronization would not hurt
123  chibios_rt::CriticalSectionLocker csl;
124 
126 
127 
130  }
131 #endif /* EFI_ENGINE_CONTROL && EFI_SHAFT_POSITION_INPUT */
132 }
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

Definition at line 185 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 101 of file engine.h.

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

◆ ALSsoftSparkLimiter

SoftSparkLimiter Engine::ALSsoftSparkLimiter

Definition at line 200 of file engine.h.

Referenced by onTriggerEventSparkLogic().

◆ antilagController

AntilagSystemBase Engine::antilagController

◆ auxValves

AuxActor Engine::auxValves[AUX_DIGITAL_VALVE_COUNT][2]

Definition at line 222 of file engine.h.

Referenced by initAuxValves().

◆ bailedOnDwell

int Engine::bailedOnDwell = 0

Definition at line 226 of file engine.h.

◆ blipIdlePosition

percent_t Engine::blipIdlePosition

idle blip is a development tool: alternator PID research for instance have benefited from a repetitive change of RPM

Definition at line 313 of file engine.h.

Referenced by blipIdle(), and IdleController::getIdlePosition().

◆ brakePedalSwitchedState

SwitchedState Engine::brakePedalSwitchedState

Definition at line 184 of file engine.h.

Referenced by sendQcBenchButtonCounters(), and updateSwitchInputs().

◆ clutchUpSwitchedState

SwitchedState Engine::clutchUpSwitchedState

Definition at line 183 of file engine.h.

Referenced by sendQcBenchButtonCounters(), and updateSwitchInputs().

◆ configBurnTimer

Timer Engine::configBurnTimer

Definition at line 265 of file engine.h.

Referenced by assertTimeIsLinear(), and writeToFlashNow().

◆ dc_motors

dc_motors_s Engine::dc_motors

Definition at line 307 of file engine.h.

Referenced by getOutputValueByName(), and updateTunerStudioState().

◆ enableOverdwellProtection

bool Engine::enableOverdwellProtection = true

Definition at line 94 of file engine.h.

◆ engineModules

type_list< Mockable<InjectorModelPrimary>, Mockable<InjectorModelSecondary>,#if EFI_IDLE_CONTROL Mockable<IdleController>,#endif TriggerScheduler,#if EFI_HPFP && EFI_ENGINE_CONTROL HpfpController,#endif #if EFI_ENGINE_CONTROL Mockable<ThrottleModel>,#endif #if EFI_ALTERNATOR_CONTROL AlternatorController,#endif FuelPumpController, MainRelayController, IgnitionController, Mockable<AcController>, FanControl1, FanControl2, PrimeController, DfcoController,#if EFI_HD_ACR HarleyAcr,#endif Mockable<WallFuelController>,#if EFI_VEHICLE_SPEED GearDetector, TripOdometer,#endif KnockController, SensorChecker,#if EFI_ENGINE_CONTROL LimpManager,#endif #if EFI_VVT_PID VvtController1, VvtController2, VvtController3, VvtController4,#endif #if EFI_BOOST_CONTROL BoostController,#endif EngineModule > Engine::engineModules

◆ engineState

EngineState Engine::engineState

Definition at line 305 of file engine.h.

Referenced by auxPlainPinTurnOn(), HpfpQuantity::calcFuelPercent(), canDashboardHaltech(), EtbController::checkStatus(), configureRusefiLuaHooks(), AemXSeriesWideband::decodeRusefiDiag(), detectHellenBoardType(), fireSparkAndPrepareNextSchedule(), firmwareError(), getAcrState(), getAdvanceCorrections(), SpeedDensityAirmass::getAirmass(), AngleBasedEvent::getAngleFromNow(), getBaseFuelMass(), getBoardId(), getBrakePedalState(), getClutchUpState(), getCrankingFuel3(), getEngineState(), getInjectionMass(), getInjectorDutyCycle(), getInjectorDutyCycleStage2(), getMultiSparkCount(), getOutputValueByName(), getPerCylinderFiringOrderOffset(), getRunningAdvance(), getRunningFuel(), AirmassVeModelBase::getVe(), handleGetDataRequest(), handleTestCommand(), initDataStructures(), initializeIgnitionActions(), is_F_OrOlder(), LaunchControlBase::isInsideSwitchCondition(), isMegaModuleRevision(), lua_getDigital(), mapAveragingTriggerCallback(), obdOnCanPacketRx(), KnockControllerBase::onKnockSenseCompleted(), HarleyAcr::onSlowCallback(), onStartStopButtonToggle(), onTriggerEventSparkLogic(), overFireSparkAndPrepareNextSchedule(), periodicFastCallback(), EngineState::periodicFastCallback(), populateFrame(), postMapState(), printConfiguration(), recalculateAuxValveTiming(), refreshMapAveragingPreCalc(), reset(), resetLua(), runOneLua(), sayHello(), scheduleOpen(), scheduleSparkEvent(), sendWidebandInfo(), setBoardConfigOverrides(), Generic4TransmissionController::setPcState(), slowStartStopButtonCallback(), startAveraging(), startDwellByTurningSparkPinHigh(), testRusefiMethods(), THD_FUNCTION(), turnSparkPinHighStartCharging(), updateFuelInfo(), updateSlowSensors(), LimpManager::updateState(), updateSwitchInputs(), updateTunerStudioState(), updateWarningCodes(), and warning().

◆ etbAutoTune

bool Engine::etbAutoTune = false

◆ etbControllers

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

◆ executor [1/3]

SingleTimerExecutor Engine::executor

◆ executor [2/3]

SleepExecutor Engine::executor

Definition at line 239 of file engine.h.

◆ executor [3/3]

TestExecutor Engine::executor

Definition at line 242 of file engine.h.

◆ fuelComputer

FuelComputer Engine::fuelComputer

◆ gearController

GearControllerBase* Engine::gearController

Definition at line 179 of file engine.h.

Referenced by doPeriodicSlowCallback(), 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 271 of file engine.h.

Referenced by getGlobalConfigurationVersion(), and incrementGlobalConfigurationVersion().

◆ hardSparkLimiter

SoftSparkLimiter Engine::hardSparkLimiter

Definition at line 192 of file engine.h.

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 301 of file engine.h.

Referenced by enableOrDisable(), and resetEngineSnifferIfInTestMode().

◆ isPwmEnabled

bool Engine::isPwmEnabled = true

Definition at line 104 of file engine.h.

Referenced by applyPinState(), and enableOrDisable().

◆ isRunningPwmTest

bool Engine::isRunningPwmTest = false

Definition at line 295 of file engine.h.

Referenced by efiWatchdog(), and startPwmTest().

◆ lambdaMonitor

LambdaMonitor Engine::lambdaMonitor

◆ launchController

LaunchControlBase Engine::launchController

◆ luaDigitalInputState

SimpleSwitchedState Engine::luaDigitalInputState[LUA_DIGITAL_INPUT_COUNT]

Definition at line 186 of file engine.h.

Referenced by pokeAuxDigital(), and sendQcBenchAuxDigitalCounters().

◆ mockAirmassModel

AirmassModelBase* Engine::mockAirmassModel = nullptr

Definition at line 346 of file engine.h.

Referenced by getAirmassModel().

◆ needTdcCallback

bool Engine::needTdcCallback = true

Definition at line 225 of file engine.h.

Referenced by onTdcCallback().

◆ onIgnitionEvent

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

Definition at line 244 of file engine.h.

Referenced by fireSparkAndPrepareNextSchedule(), and turnSparkPinHighStartCharging().

◆ outputChannels

TunerStudioOutputChannels Engine::outputChannels

Definition at line 96 of file engine.h.

Referenced by attachMsdSdCard(), canInfo(), EtbController::checkStatus(), TunerStudio::cmdOutputChannels(), completionCallback(), TriggerCentral::decodeMapCam(), executorStatistics(), fast_adc_callback(), fireSparkAndPrepareNextSchedule(), fuelClosedLoopCorrection(), getAdvanceCorrections(), getAvgAdcValue(), VvtController::getClosedLoop(), BoostController::getClosedLoop(), AlternatorController::getClosedLoop(), EtbController::getClosedLoopAutotune(), IdleController::getIdlePosition(), getLiveData(), SpeedDensityAirmass::getMap(), BoostController::getOpenLoop(), getOutputValueByName(), getRunningAdvance(), BoostController::getSetpoint(), VvtController::getSetpoint(), EtbController::getSetpointEtb(), EtbController::getSetpointIdleValve(), TpsAccelEnrichment::getTpsEnrichment(), getTunerStudioOutputChannels(), AirmassVeModelBase::getVe(), grabPedalIsUp(), grabPedalIsWideOpen(), handleCommandX14(), handleFuel(), handleShaftSignal(), handleVvtCamSignal(), initElectronicThrottle(), lua_setDebug(), mapAveragingAdcCallback(), mountMmc(), myAlloc(), onTriggerEventSparkLogic(), InjectionEvent::onTriggerTooth(), populateFrame(), postCanState(), StepperMotorBase::postCurrentPosition(), GearControllerBase::postState(), preCalculate(), prepareCylinderIgnitionSchedule(), printErrorCounters(), printUid(), processLastKnockEvent(), readGppwmChannel(), reportLogicAnalyzerToTS(), runBench(), runOneLua(), IgnitionOutputPin::setHigh(), IgnitionOutputPin::setLow(), EtbController::setOutput(), setToothLogReady(), startLua(), THD_FUNCTION(), tle8888PostState(), triggerScopeDisable(), triggerScopeGetBuffer(), InjectionEvent::update(), SimpleTransmissionController::update(), DynoView::update(), updateEgtSensors(), updateFlags(), updateFuelCorrections(), updateFuelInfo(), updateFuelResults(), updateFuelSensors(), updateGppwm(), updateIgnition(), updateLambda(), updateMiscSensors(), updatePressures(), updateRawSensors(), updateTempSensors(), updateThrottles(), updateTunerStudioState(), updateVehicleSpeed(), updateVvtSensors(), updateWarningCodes(), 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 111 of file engine.h.

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

◆ pinRepository

PinRepository Engine::pinRepository

Definition at line 113 of file engine.h.

Referenced by brain_pin_markUsed(), getBrainUsedPin(), and setPin().

◆ prevOutputName

const char* Engine::prevOutputName = nullptr

Definition at line 106 of file engine.h.

◆ rpmCalculator

RpmCalculator Engine::rpmCalculator

◆ sensors

SensorsState Engine::sensors

◆ sent_state

sent_state_s Engine::sent_state

Definition at line 308 of file engine.h.

Referenced by SentDecoderThread().

◆ slowCallBackWasInvoked

bool Engine::slowCallBackWasInvoked = false

Definition at line 261 of file engine.h.

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

◆ softSparkLimiter

SoftSparkLimiter Engine::softSparkLimiter

Definition at line 190 of file engine.h.

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

◆ startStopStateLastPush

Timer Engine::startStopStateLastPush

Definition at line 210 of file engine.h.

Referenced by disengageStarterIfNeeded(), and onStartStopButtonToggle().

◆ stftCorrection

float Engine::stftCorrection[STFT_BANK_COUNT] = {0}

◆ tdcMarkEnabled

bool Engine::tdcMarkEnabled = true

Definition at line 257 of file engine.h.

Referenced by tdcMarkCallback().

◆ tdcScheduler

scheduling_s Engine::tdcScheduler[2]

Definition at line 250 of file engine.h.

Referenced by tdcMarkCallback().

◆ timeToStopBlip

efitimeus_t Engine::timeToStopBlip = 0

Definition at line 314 of file engine.h.

Referenced by blipIdle(), IdleController::getIdlePosition(), and undoIdleBlipIfNeeded().

◆ timeToStopIdleTest

efitimeus_t Engine::timeToStopIdleTest = 0

Definition at line 315 of file engine.h.

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

◆ tpsAccelEnrichment

TpsAccelEnrichment Engine::tpsAccelEnrichment

◆ triggerCentral

TriggerCentral Engine::triggerCentral

◆ versionForConfigurationListeners

LocalVersionHolder Engine::versionForConfigurationListeners

Definition at line 220 of file engine.h.

Referenced by doPeriodicSlowCallback().


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