2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @file engine.h
|
|
|
|
*
|
|
|
|
* @date May 21, 2014
|
2020-01-07 21:02:40 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2019-09-19 21:17:00 -07:00
|
|
|
|
|
|
|
#pragma once
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2022-09-01 08:47:56 -07:00
|
|
|
#include "global_shared.h"
|
2021-11-19 20:06:51 -08:00
|
|
|
#include "engine_module.h"
|
2019-05-27 16:05:59 -07:00
|
|
|
#include "engine_state.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#include "rpm_calculator.h"
|
|
|
|
#include "event_registry.h"
|
|
|
|
#include "table_helper.h"
|
|
|
|
#include "listener_array.h"
|
|
|
|
#include "accel_enrichment.h"
|
2015-09-13 14:02:44 -07:00
|
|
|
#include "trigger_central.h"
|
2019-04-15 18:02:42 -07:00
|
|
|
#include "local_version_holder.h"
|
2020-09-02 17:17:58 -07:00
|
|
|
#include "buttonshift.h"
|
2020-10-09 20:34:45 -07:00
|
|
|
#include "gear_controller.h"
|
2021-11-19 20:06:51 -08:00
|
|
|
#include "high_pressure_fuel_pump.h"
|
2020-12-26 14:30:46 -08:00
|
|
|
#include "limp_manager.h"
|
2021-07-14 22:56:04 -07:00
|
|
|
#include "pin_repository.h"
|
2021-10-13 21:47:26 -07:00
|
|
|
#include "ac_control.h"
|
2021-11-01 20:33:59 -07:00
|
|
|
#include "knock_logic.h"
|
2021-10-16 20:55:29 -07:00
|
|
|
#include "idle_state_generated.h"
|
2021-11-17 09:13:19 -08:00
|
|
|
#include "idle_thread.h"
|
|
|
|
#include "injector_model.h"
|
2021-11-15 15:57:12 -08:00
|
|
|
#include "launch_control.h"
|
2021-11-18 11:27:21 -08:00
|
|
|
#include "trigger_scheduler.h"
|
2021-11-19 19:23:12 -08:00
|
|
|
#include "fuel_pump.h"
|
2021-11-24 04:47:51 -08:00
|
|
|
#include "main_relay.h"
|
2021-11-25 04:59:31 -08:00
|
|
|
#include "ac_control.h"
|
2021-11-17 09:13:19 -08:00
|
|
|
#include "type_list.h"
|
2021-11-24 09:59:57 -08:00
|
|
|
#include "boost_control.h"
|
2021-12-07 18:28:04 -08:00
|
|
|
#include "ignition_controller.h"
|
2021-12-05 15:33:50 -08:00
|
|
|
#include "alternator_controller.h"
|
2022-01-23 16:44:41 -08:00
|
|
|
#include "dfco.h"
|
2022-04-06 13:15:58 -07:00
|
|
|
#include "gear_detector.h"
|
2022-04-13 13:39:59 -07:00
|
|
|
#include "advance_map.h"
|
2022-04-13 14:55:31 -07:00
|
|
|
#include "fan_control.h"
|
2022-07-30 14:08:48 -07:00
|
|
|
#include "sensor_checker.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-17 10:45:10 -08:00
|
|
|
#ifndef EFI_UNIT_TEST
|
|
|
|
#error EFI_UNIT_TEST must be defined!
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef EFI_SIMULATOR
|
|
|
|
#error EFI_SIMULATOR must be defined!
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef EFI_PROD_CODE
|
|
|
|
#error EFI_PROD_CODE must be defined!
|
|
|
|
#endif
|
|
|
|
|
2019-01-08 21:53:54 -08:00
|
|
|
#if EFI_SIGNAL_EXECUTOR_ONE_TIMER
|
|
|
|
// PROD real firmware uses this implementation
|
2019-03-29 06:11:13 -07:00
|
|
|
#include "single_timer_executor.h"
|
2019-01-08 21:53:54 -08:00
|
|
|
#endif /* EFI_SIGNAL_EXECUTOR_ONE_TIMER */
|
|
|
|
#if EFI_SIGNAL_EXECUTOR_SLEEP
|
2019-01-08 22:07:50 -08:00
|
|
|
#include "signal_executor_sleep.h"
|
2019-01-08 21:53:54 -08:00
|
|
|
#endif /* EFI_SIGNAL_EXECUTOR_SLEEP */
|
|
|
|
#if EFI_UNIT_TEST
|
|
|
|
#include "global_execution_queue.h"
|
|
|
|
#endif /* EFI_UNIT_TEST */
|
|
|
|
|
2019-10-16 20:02:24 -07:00
|
|
|
#define FAST_CALLBACK_PERIOD_MS 5
|
2020-11-11 18:47:19 -08:00
|
|
|
#define SLOW_CALLBACK_PERIOD_MS 50
|
2016-11-30 19:06:43 -08:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
class RpmCalculator;
|
2021-05-14 04:17:22 -07:00
|
|
|
struct AirmassModelBase;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
#define MAF_DECODING_CACHE_SIZE 256
|
|
|
|
|
|
|
|
#define MAF_DECODING_CACHE_MULT (MAF_DECODING_CACHE_SIZE / 5.0)
|
|
|
|
|
2019-01-14 07:58:38 -08:00
|
|
|
/**
|
|
|
|
* I am not sure if this needs to be configurable.
|
|
|
|
*
|
|
|
|
* Also technically the whole feature might be implemented as cranking fuel coefficient curve by TPS.
|
|
|
|
*/
|
|
|
|
// todo: not great location for these
|
|
|
|
#define CLEANUP_MODE_TPS 90
|
|
|
|
#define STEPPER_PARKING_TPS CLEANUP_MODE_TPS
|
2019-01-05 20:48:37 -08:00
|
|
|
|
2019-12-13 10:52:34 -08:00
|
|
|
class IEtbController;
|
2020-12-11 09:50:10 -08:00
|
|
|
struct IFuelComputer;
|
2020-12-17 14:46:51 -08:00
|
|
|
struct IIdleController;
|
2019-12-13 10:52:34 -08:00
|
|
|
|
2020-10-04 16:29:26 -07:00
|
|
|
class PrimaryTriggerConfiguration final : public TriggerConfiguration {
|
2020-08-23 22:21:42 -07:00
|
|
|
public:
|
2020-10-05 13:42:50 -07:00
|
|
|
PrimaryTriggerConfiguration() : TriggerConfiguration("TRG ") {}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool isUseOnlyRisingEdgeForTrigger() const override;
|
|
|
|
bool isVerboseTriggerSynchDetails() const override;
|
2022-05-30 16:36:47 -07:00
|
|
|
trigger_config_s getType() const override;
|
2020-08-23 22:21:42 -07:00
|
|
|
};
|
|
|
|
|
2020-10-04 16:29:26 -07:00
|
|
|
class VvtTriggerConfiguration final : public TriggerConfiguration {
|
2020-08-26 20:35:11 -07:00
|
|
|
public:
|
2021-07-21 19:21:59 -07:00
|
|
|
const int index;
|
2021-07-21 19:14:21 -07:00
|
|
|
|
2021-07-21 19:28:35 -07:00
|
|
|
VvtTriggerConfiguration(const char * prefix, const int index) : TriggerConfiguration(prefix), index(index) {
|
2021-07-21 19:14:21 -07:00
|
|
|
}
|
2020-10-05 13:42:50 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
bool isUseOnlyRisingEdgeForTrigger() const override;
|
|
|
|
bool isVerboseTriggerSynchDetails() const override;
|
2022-05-30 16:36:47 -07:00
|
|
|
trigger_config_s getType() const override;
|
2020-08-26 20:35:11 -07:00
|
|
|
};
|
|
|
|
|
2021-12-08 04:26:49 -08:00
|
|
|
class PrimeController : public EngineModule {
|
|
|
|
public:
|
|
|
|
void onIgnitionStateChanged(bool ignitionOn) override;
|
|
|
|
|
2021-12-08 13:20:19 -08:00
|
|
|
floatms_t getPrimeDuration() const;
|
|
|
|
|
|
|
|
void onPrimeStart();
|
|
|
|
void onPrimeEnd();
|
|
|
|
|
|
|
|
bool isPriming() const {
|
|
|
|
return m_isPriming;
|
|
|
|
}
|
|
|
|
|
2021-12-08 04:26:49 -08:00
|
|
|
private:
|
|
|
|
scheduling_s m_start;
|
|
|
|
scheduling_s m_end;
|
2021-12-08 13:20:19 -08:00
|
|
|
|
|
|
|
bool m_isPriming = false;
|
|
|
|
|
|
|
|
static void onPrimeStartAdapter(PrimeController* instance) {
|
|
|
|
instance->onPrimeStart();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void onPrimeEndAdapter(PrimeController* instance) {
|
|
|
|
instance->onPrimeEnd();
|
|
|
|
}
|
2021-12-08 04:26:49 -08:00
|
|
|
};
|
2021-08-03 16:48:24 -07:00
|
|
|
|
2021-11-16 13:52:11 -08:00
|
|
|
class Engine final : public TriggerStateListener {
|
2015-07-10 06:01:56 -07:00
|
|
|
public:
|
2016-12-18 07:02:38 -08:00
|
|
|
Engine();
|
2021-11-25 04:59:31 -08:00
|
|
|
|
2021-11-15 17:32:25 -08:00
|
|
|
// todo: technical debt: enableOverdwellProtection #3553
|
2021-10-01 22:10:24 -07:00
|
|
|
bool enableOverdwellProtection = true;
|
2021-11-15 17:32:25 -08:00
|
|
|
|
2021-12-07 17:18:47 -08:00
|
|
|
TunerStudioOutputChannels outputChannels;
|
|
|
|
|
2021-12-07 07:35:52 -08:00
|
|
|
/**
|
|
|
|
* Sometimes for instance during shutdown we need to completely supress CAN TX
|
|
|
|
*/
|
|
|
|
bool allowCanTx = true;
|
|
|
|
|
2021-11-15 17:32:25 -08:00
|
|
|
// used by HW CI
|
2020-11-26 14:48:09 -08:00
|
|
|
bool isPwmEnabled = true;
|
2021-11-15 17:32:25 -08:00
|
|
|
|
2021-06-23 03:10:27 -07:00
|
|
|
const char *prevOutputName = nullptr;
|
2021-12-05 18:20:54 -08:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
|
|
|
bool pauseCANdueToSerial = false;
|
2021-06-23 03:10:27 -07:00
|
|
|
|
2021-07-14 22:56:04 -07:00
|
|
|
PinRepository pinRepository;
|
|
|
|
|
2022-04-16 18:23:37 -07:00
|
|
|
IEtbController *etbControllers[ETB_COUNT] = {nullptr};
|
2022-09-01 17:16:57 -07:00
|
|
|
// we have pointers mixed with... not pointers (reference?) between different controllers
|
2020-08-17 14:03:59 -07:00
|
|
|
IFuelComputer *fuelComputer = nullptr;
|
2021-11-17 09:13:19 -08:00
|
|
|
|
|
|
|
type_list<
|
|
|
|
Mockable<InjectorModel>,
|
|
|
|
#if EFI_IDLE_CONTROL
|
2022-01-20 11:08:54 -08:00
|
|
|
Mockable<IdleController>,
|
2021-11-19 20:06:51 -08:00
|
|
|
#endif // EFI_IDLE_CONTROL
|
2021-11-18 11:27:21 -08:00
|
|
|
TriggerScheduler,
|
2021-11-19 20:06:51 -08:00
|
|
|
#if EFI_HPFP && EFI_ENGINE_CONTROL
|
|
|
|
HpfpController,
|
|
|
|
#endif // EFI_HPFP && EFI_ENGINE_CONTROL
|
2021-12-05 15:33:50 -08:00
|
|
|
#if EFI_ALTERNATOR_CONTROL
|
|
|
|
AlternatorController,
|
|
|
|
#endif /* EFI_ALTERNATOR_CONTROL */
|
2021-11-19 19:23:12 -08:00
|
|
|
FuelPumpController,
|
2021-11-24 04:47:51 -08:00
|
|
|
MainRelayController,
|
2021-12-07 18:28:04 -08:00
|
|
|
IgnitionController,
|
2021-11-25 04:59:31 -08:00
|
|
|
AcController,
|
2021-12-08 04:26:49 -08:00
|
|
|
PrimeController,
|
2022-01-23 16:44:41 -08:00
|
|
|
DfcoController,
|
2022-01-27 04:45:50 -08:00
|
|
|
Mockable<WallFuelController>,
|
2022-04-06 13:15:58 -07:00
|
|
|
#if EFI_VEHICLE_SPEED
|
|
|
|
GearDetector,
|
|
|
|
#endif // EFI_VEHICLE_SPEED
|
2022-04-18 05:03:16 -07:00
|
|
|
KnockController,
|
2022-07-30 14:08:48 -07:00
|
|
|
SensorChecker,
|
2021-11-17 09:13:19 -08:00
|
|
|
EngineModule // dummy placeholder so the previous entries can all have commas
|
|
|
|
> engineModules;
|
2019-12-13 10:52:34 -08:00
|
|
|
|
2021-11-17 18:50:00 -08:00
|
|
|
/**
|
|
|
|
* Slightly shorter helper function to keep the code looking clean.
|
|
|
|
*/
|
|
|
|
template<typename get_t>
|
|
|
|
auto & module() {
|
|
|
|
return engineModules.get<get_t>();
|
|
|
|
}
|
|
|
|
|
2020-01-21 22:22:44 -08:00
|
|
|
cyclic_buffer<int> triggerErrorDetection;
|
|
|
|
|
2022-04-23 04:34:39 -07:00
|
|
|
#if EFI_TCU
|
2020-09-02 12:39:50 -07:00
|
|
|
GearControllerBase *gearController;
|
2022-04-23 04:34:39 -07:00
|
|
|
#endif
|
|
|
|
|
2021-12-16 13:19:33 -08:00
|
|
|
#if EFI_LAUNCH_CONTROL
|
2021-11-15 15:57:12 -08:00
|
|
|
LaunchControlBase launchController;
|
2021-11-16 10:15:12 -08:00
|
|
|
SoftSparkLimiter softSparkLimiter;
|
2022-02-06 15:46:09 -08:00
|
|
|
#endif // EFI_LAUNCH_CONTROL
|
2020-09-02 12:39:50 -07:00
|
|
|
|
2021-11-24 09:59:57 -08:00
|
|
|
#if EFI_BOOST_CONTROL
|
|
|
|
BoostController boostController;
|
|
|
|
#endif // EFI_BOOST_CONTROL
|
|
|
|
|
2022-04-13 13:39:59 -07:00
|
|
|
IgnitionState ignitionState;
|
2022-07-14 09:36:55 -07:00
|
|
|
void resetLua();
|
2022-04-13 13:39:59 -07:00
|
|
|
|
2022-04-13 14:55:31 -07:00
|
|
|
FanControl1 fan1;
|
|
|
|
FanControl2 fan2;
|
|
|
|
|
2021-07-17 13:12:54 -07:00
|
|
|
efitick_t mostRecentSparkEvent;
|
|
|
|
efitick_t mostRecentIgnitionEvent;
|
|
|
|
|
2020-08-23 22:21:42 -07:00
|
|
|
PrimaryTriggerConfiguration primaryTriggerConfiguration;
|
2021-07-21 20:06:35 -07:00
|
|
|
#if CAMS_PER_BANK == 1
|
|
|
|
VvtTriggerConfiguration vvtTriggerConfiguration[CAMS_PER_BANK] = {{"VVT1 ", 0}};
|
2021-07-21 19:38:00 -07:00
|
|
|
#else
|
2021-07-21 19:14:21 -07:00
|
|
|
VvtTriggerConfiguration vvtTriggerConfiguration[CAMS_PER_BANK] = {{"VVT1 ", 0}, {"VVT2 ", 1}};
|
2021-07-21 19:38:00 -07:00
|
|
|
#endif
|
|
|
|
|
2020-11-18 20:54:30 -08:00
|
|
|
efitick_t startStopStateLastPushTime = 0;
|
2020-08-23 22:21:42 -07:00
|
|
|
|
2020-02-26 15:16:35 -08:00
|
|
|
#if EFI_SHAFT_POSITION_INPUT
|
2020-01-26 03:12:01 -08:00
|
|
|
void OnTriggerStateDecodingError();
|
2019-12-05 22:57:11 -08:00
|
|
|
void OnTriggerStateProperState(efitick_t nowNt) override;
|
2022-05-10 13:55:28 -07:00
|
|
|
void OnTriggerSyncronization(bool wasSynchronized, bool isDecodingError) override;
|
2020-01-26 09:02:54 -08:00
|
|
|
void OnTriggerSynchronizationLost() override;
|
2020-02-26 15:16:35 -08:00
|
|
|
#endif
|
2019-12-05 22:57:11 -08:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void setConfig();
|
|
|
|
injection_mode_e getCurrentInjectionMode();
|
2016-12-18 07:02:38 -08:00
|
|
|
|
2019-04-15 18:09:43 -07:00
|
|
|
LocalVersionHolder versionForConfigurationListeners;
|
|
|
|
LocalVersionHolder auxParametersVersion;
|
2021-11-16 01:15:29 -08:00
|
|
|
operation_mode_e getOperationMode();
|
2019-08-07 21:19:09 -07:00
|
|
|
|
2019-12-02 21:29:12 -08:00
|
|
|
AuxActor auxValves[AUX_DIGITAL_VALVE_COUNT][2];
|
2019-11-23 19:55:21 -08:00
|
|
|
|
2019-12-23 18:58:06 -08:00
|
|
|
#if EFI_UNIT_TEST
|
2019-12-23 18:55:08 -08:00
|
|
|
bool needTdcCallback = true;
|
2019-12-23 18:58:06 -08:00
|
|
|
#endif /* EFI_UNIT_TEST */
|
|
|
|
|
2019-05-07 13:45:29 -07:00
|
|
|
|
2019-11-11 19:19:35 -08:00
|
|
|
// this is useful at least for real hardware integration testing - maybe a proper solution would be to simply
|
|
|
|
// GND input pins instead of leaving them floating
|
|
|
|
bool hwTriggerInputEnabled = true;
|
|
|
|
|
2019-01-15 18:51:09 -08:00
|
|
|
int getGlobalConfigurationVersion(void) const;
|
2021-11-15 17:22:05 -08:00
|
|
|
|
2019-01-15 18:51:09 -08:00
|
|
|
|
2019-01-08 21:53:54 -08:00
|
|
|
// a pointer with interface type would make this code nicer but would carry extra runtime
|
|
|
|
// cost to resolve pointer, we use instances as a micro optimization
|
|
|
|
#if EFI_SIGNAL_EXECUTOR_ONE_TIMER
|
2019-01-08 22:07:50 -08:00
|
|
|
SingleTimerExecutor executor;
|
2019-01-08 21:53:54 -08:00
|
|
|
#endif
|
|
|
|
#if EFI_SIGNAL_EXECUTOR_SLEEP
|
2019-01-08 22:07:50 -08:00
|
|
|
SleepExecutor executor;
|
2019-01-08 21:53:54 -08:00
|
|
|
#endif
|
|
|
|
#if EFI_UNIT_TEST
|
|
|
|
TestExecutor executor;
|
2022-06-18 11:17:36 -07:00
|
|
|
#endif // EFI_UNIT_TEST
|
2016-01-25 09:01:30 -08:00
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_ENGINE_CONTROL
|
2016-12-18 09:03:48 -08:00
|
|
|
FuelSchedule injectionEvents;
|
2019-10-07 23:35:21 -07:00
|
|
|
IgnitionEventList ignitionEvents;
|
2021-06-24 22:37:43 -07:00
|
|
|
scheduling_s tdcScheduler[2];
|
2016-12-18 09:03:48 -08:00
|
|
|
#endif /* EFI_ENGINE_CONTROL */
|
2016-02-06 07:01:34 -08:00
|
|
|
|
2022-08-25 16:58:10 -07:00
|
|
|
// todo: move to electronic_throttle something?
|
2019-01-19 19:31:55 -08:00
|
|
|
bool etbAutoTune = false;
|
2016-01-30 19:03:36 -08:00
|
|
|
/**
|
2022-06-18 11:17:36 -07:00
|
|
|
* this is based on engineSnifferRpmThreshold settings and current RPM
|
2016-01-30 19:03:36 -08:00
|
|
|
*/
|
2022-06-18 11:17:36 -07:00
|
|
|
bool isEngineSnifferEnabled = false;
|
2021-06-24 22:31:53 -07:00
|
|
|
|
2022-06-18 11:17:36 -07:00
|
|
|
#if EFI_UNIT_TEST
|
|
|
|
bool tdcMarkEnabled = true;
|
|
|
|
#endif // EFI_UNIT_TEST
|
2021-06-24 22:31:53 -07:00
|
|
|
|
2016-01-30 19:03:36 -08:00
|
|
|
/**
|
|
|
|
* this is based on sensorChartMode and sensorSnifferRpmThreshold settings
|
|
|
|
*/
|
2019-01-19 19:31:55 -08:00
|
|
|
sensor_chart_e sensorChartMode = SC_OFF;
|
2016-01-26 20:01:44 -08:00
|
|
|
|
2019-01-14 05:57:08 -08:00
|
|
|
bool slowCallBackWasInvoked = false;
|
2017-05-11 05:32:08 -07:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
RpmCalculator rpmCalculator;
|
|
|
|
|
2020-03-23 07:32:41 -07:00
|
|
|
bool startStopState = false;
|
|
|
|
int startStopStateToggleCounter = 0;
|
|
|
|
|
2020-09-07 11:41:04 -07:00
|
|
|
/**
|
|
|
|
* this is needed by getTimeIgnitionSeconds() and checkShutdown()
|
2022-08-25 16:58:10 -07:00
|
|
|
* todo: refactor to Timer?
|
2020-09-07 11:41:04 -07:00
|
|
|
*/
|
|
|
|
efitick_t ignitionOnTimeNt = 0;
|
|
|
|
|
2019-04-15 18:37:54 -07:00
|
|
|
/**
|
2019-05-02 14:52:48 -07:00
|
|
|
* This counter is incremented every time user adjusts ECU parameters online (either via rusEfi console or other
|
2019-04-15 18:37:54 -07:00
|
|
|
* tuning software)
|
|
|
|
*/
|
2022-08-27 19:28:29 -07:00
|
|
|
int globalConfigurationVersion = 0;
|
2019-04-15 18:37:54 -07:00
|
|
|
|
2016-01-30 19:03:36 -08:00
|
|
|
/**
|
|
|
|
* always 360 or 720, never zero
|
|
|
|
*/
|
2016-01-14 21:01:42 -08:00
|
|
|
angle_t engineCycle;
|
|
|
|
|
2019-07-12 20:15:52 -07:00
|
|
|
TpsAccelEnrichment tpsAccelEnrichment;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2022-04-16 14:07:57 -07:00
|
|
|
#if EFI_SHAFT_POSITION_INPUT
|
2015-09-13 14:02:44 -07:00
|
|
|
TriggerCentral triggerCentral;
|
2022-04-16 14:07:57 -07:00
|
|
|
#endif // EFI_SHAFT_POSITION_INPUT
|
2015-09-13 14:02:44 -07:00
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
/**
|
2016-10-12 22:02:02 -07:00
|
|
|
* Each individual fuel injection duration for current engine cycle, without wall wetting
|
|
|
|
* including everything including injector lag, both cranking and running
|
2017-11-06 19:29:39 -08:00
|
|
|
* @see getInjectionDuration()
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2019-01-19 19:31:55 -08:00
|
|
|
floatms_t injectionDuration = 0;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-03-03 04:30:56 -08:00
|
|
|
// Per-injection fuel mass, including TPS accel enrich
|
2021-12-31 23:19:59 -08:00
|
|
|
float injectionMass[MAX_CYLINDER_COUNT] = {0};
|
2021-05-08 14:41:50 -07:00
|
|
|
|
|
|
|
float stftCorrection[STFT_BANK_COUNT] = {0};
|
2021-03-03 04:30:56 -08:00
|
|
|
|
2020-05-05 05:01:40 -07:00
|
|
|
// Standard cylinder air charge - 100% VE at standard temperature, grams per cylinder
|
|
|
|
float standardAirCharge = 0;
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void periodicFastCallback();
|
|
|
|
void periodicSlowCallback();
|
|
|
|
void updateSlowSensors();
|
|
|
|
void updateSwitchInputs();
|
2022-04-02 16:27:18 -07:00
|
|
|
void updateTriggerWaveform();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2019-01-19 19:31:55 -08:00
|
|
|
bool isRunningPwmTest = false;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* are we running any kind of functional test? this affect
|
|
|
|
* some areas
|
|
|
|
*/
|
2020-08-08 08:25:17 -07:00
|
|
|
bool isFunctionalTestMode = false;
|
2019-12-21 18:11:09 -08:00
|
|
|
|
2020-09-19 01:38:59 -07:00
|
|
|
/**
|
|
|
|
* See also triggerSimulatorFrequency
|
|
|
|
*/
|
2020-04-23 19:38:14 -07:00
|
|
|
bool directSelfStimulation = false;
|
|
|
|
|
2019-12-21 17:43:11 -08:00
|
|
|
void resetEngineSnifferIfInTestMode();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* pre-calculated reference to which output pin should be used for
|
|
|
|
* given sequence index within engine cycle
|
2016-01-16 14:02:38 -08:00
|
|
|
* todo: update documentation
|
2015-07-10 06:01:56 -07:00
|
|
|
*/
|
2021-07-06 17:14:08 -07:00
|
|
|
int ignitionPin[MAX_CYLINDER_COUNT];
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-11-20 12:01:48 -08:00
|
|
|
/**
|
|
|
|
* this is invoked each time we register a trigger tooth signal
|
|
|
|
*/
|
2021-03-15 07:23:19 -07:00
|
|
|
void onTriggerSignalEvent();
|
2015-07-10 06:01:56 -07:00
|
|
|
EngineState engineState;
|
2021-10-16 21:27:12 -07:00
|
|
|
/**
|
|
|
|
* idle blip is a development tool: alternator PID research for instance have benefited from a repetitive change of RPM
|
|
|
|
*/
|
|
|
|
percent_t blipIdlePosition;
|
|
|
|
efitimeus_t timeToStopBlip = 0;
|
|
|
|
efitimeus_t timeToStopIdleTest = 0;
|
|
|
|
|
2021-10-16 20:55:29 -07:00
|
|
|
|
2017-03-06 23:24:57 -08:00
|
|
|
SensorsState sensors;
|
2021-01-10 20:46:50 -08:00
|
|
|
efitick_t mainRelayBenchStartNt = 0;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* value of 'triggerShape.getLength()'
|
|
|
|
* pre-calculating this value is a performance optimization
|
|
|
|
*/
|
2019-01-19 19:31:55 -08:00
|
|
|
uint32_t engineCycleEventCount = 0;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void preCalculate();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
void watchdog();
|
2017-06-24 22:35:46 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Needed by EFI_MAIN_RELAY_CONTROL to shut down the engine correctly.
|
2020-09-07 11:41:04 -07:00
|
|
|
* This method cancels shutdown if the ignition voltage is detected.
|
2017-06-24 22:35:46 -07:00
|
|
|
*/
|
2021-11-16 01:15:29 -08:00
|
|
|
void checkShutdown();
|
2020-09-07 11:41:04 -07:00
|
|
|
|
2017-06-24 22:35:46 -07:00
|
|
|
/**
|
|
|
|
* Allows to finish some long-term shutdown procedures (stepper motor parking etc.)
|
2020-09-07 11:41:04 -07:00
|
|
|
Called when the ignition switch is turned off (vBatt is too low).
|
2017-06-24 22:35:46 -07:00
|
|
|
Returns true if some operations are in progress on background.
|
|
|
|
*/
|
2021-11-16 01:15:29 -08:00
|
|
|
bool isInShutdownMode() const;
|
2020-09-07 11:41:04 -07:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
bool isInMainRelayBench();
|
2021-01-10 20:46:50 -08:00
|
|
|
|
2020-09-07 11:41:04 -07:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2021-11-16 01:15:29 -08:00
|
|
|
bool isMainRelayEnabled() const;
|
2020-09-07 12:02:11 -07:00
|
|
|
|
2020-09-07 11:41:04 -07:00
|
|
|
/**
|
|
|
|
* Needed by EFI_MAIN_RELAY_CONTROL to handle fuel pump and shutdown timings correctly.
|
|
|
|
* This method returns the number of seconds since the ignition voltage is present.
|
|
|
|
* The return value is float for more FSIO flexibility.
|
|
|
|
*/
|
|
|
|
float getTimeIgnitionSeconds(void) const;
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-09-21 14:39:21 -07:00
|
|
|
void onSparkFireKnockSense(uint8_t cylinderIndex, efitick_t nowNt);
|
|
|
|
|
2022-08-25 19:34:16 -07:00
|
|
|
#if EFI_UNIT_TEST
|
2020-07-26 20:33:18 -07:00
|
|
|
AirmassModelBase* mockAirmassModel = nullptr;
|
2022-08-25 19:34:16 -07:00
|
|
|
#endif
|
2020-07-26 20:33:18 -07:00
|
|
|
|
2020-12-26 14:30:46 -08:00
|
|
|
LimpManager limpManager;
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
private:
|
|
|
|
/**
|
|
|
|
* By the way:
|
|
|
|
* 'cranking' means engine is not stopped and the rpm are below crankingRpm
|
|
|
|
* 'running' means RPM are above crankingRpm
|
|
|
|
* 'spinning' means the engine is not stopped
|
|
|
|
*/
|
2019-01-19 19:31:55 -08:00
|
|
|
bool isSpinning = false;
|
2019-01-19 18:10:58 -08:00
|
|
|
void reset();
|
2020-10-04 16:29:26 -07:00
|
|
|
|
|
|
|
void injectEngineReferences();
|
2015-07-10 06:01:56 -07:00
|
|
|
};
|
|
|
|
|
2021-12-31 12:47:25 -08:00
|
|
|
trigger_type_e getVvtTriggerType(vvt_mode_e vvtMode);
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void prepareShapes();
|
|
|
|
void applyNonPersistentConfiguration();
|
|
|
|
void prepareOutputSignals();
|
2018-02-03 07:48:35 -08:00
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void validateConfiguration();
|
|
|
|
void doScheduleStopEngine();
|
2022-07-30 09:23:53 -07:00
|
|
|
void scheduleReboot();
|
|
|
|
bool isLockedFromUser();
|
|
|
|
void unlockEcu(int password);
|
2020-10-11 16:05:56 -07:00
|
|
|
|
|
|
|
#define HW_CHECK_RPM 200
|
|
|
|
|
2021-07-16 15:13:33 -07:00
|
|
|
// These externs aren't needed for unit tests - everything is injected instead
|
|
|
|
#if !EFI_UNIT_TEST
|
|
|
|
extern Engine ___engine;
|
2021-11-17 00:53:17 -08:00
|
|
|
static Engine * const engine = &___engine;
|
|
|
|
#else // EFI_UNIT_TEST
|
2021-11-15 21:23:14 -08:00
|
|
|
extern Engine *engine;
|
2021-11-17 00:53:17 -08:00
|
|
|
#endif // EFI_UNIT_TEST
|