74#if defined(EFI_BOOTLOADER_INCLUDE_CODE)
75#include "bootloader/bootloader.h"
80#ifdef MODULE_MAP_AVERAGING
102using namespace rusefi::stringutil;
105#if EFI_ENGINE_CONTROL
109 for (
size_t i=0;i<efi::size(
events.elements);i++) {
128 return FAST_CALLBACK_PERIOD_MS;
139 return SLOW_CALLBACK_PERIOD_MS;
152#if EFI_SHAFT_POSITION_INPUT
155 bool is_running =
false;
173#if EFI_ENGINE_CONTROL
182#if EFI_SHAFT_POSITION_INPUT
217 snprintf(
buffer, bufferSize,
"NONE");
223 snprintf(
buffer, bufferSize,
"NONE");
240#define isOutOfBounds(offset) ((offset<0) || (offset) >= (int) sizeof(engine_configuration_s))
243 if (isOutOfBounds(
offset))
246 uint16_t value = *ptr;
250 efiPrintf(
"short%s%d is %d", CONSOLE_DATA_PROTOCOL_TAG,
offset, value);
254 if (isOutOfBounds(
offset))
257 uint8_t value = *ptr;
261 efiPrintf(
"byte%s%d is %d", CONSOLE_DATA_PROTOCOL_TAG,
offset, value);
264static void setBit(
const char *offsetStr,
const char *bitStr,
const char *valueStr) {
265 int offset = atoi(offsetStr);
266 if (absI(
offset) == absI(ATOI_ERROR_CODE)) {
267 efiPrintf(
"invalid offset [%s]", offsetStr);
270 if (isOutOfBounds(
offset)) {
273 int bit = atoi(bitStr);
274 if (absI(bit) == absI(ATOI_ERROR_CODE)) {
275 efiPrintf(
"invalid bit [%s]", bitStr);
278 int value = atoi(valueStr);
279 if (absI(value) == absI(ATOI_ERROR_CODE)) {
280 efiPrintf(
"invalid value [%s]", valueStr);
284 *ptr ^= (-value ^ *ptr) & (1 << bit);
288 efiPrintf(
"bit%s%d/%d is %d", CONSOLE_DATA_PROTOCOL_TAG,
offset, bit, value);
293 if (isOutOfBounds(
offset))
296 *ptr = (uint16_t) value;
302 if (isOutOfBounds(
offset))
305 *ptr = (uint8_t) value;
311 if (isOutOfBounds(
offset))
314 int value = (*ptr >> bit) & 1;
318 efiPrintf(
"bit%s%d/%d is %d", CONSOLE_DATA_PROTOCOL_TAG,
offset, bit, value);
322 if (isOutOfBounds(
offset))
329 efiPrintf(
"int%s%d is %d", CONSOLE_DATA_PROTOCOL_TAG,
offset, value);
333 if (isOutOfBounds(
offset))
342 if (isOutOfBounds(
offset))
349 efiPrintf(
"float%s%d is %.5f", CONSOLE_DATA_PROTOCOL_TAG,
offset, value);
352static void setFloat(
const char *offsetStr,
const char *valueStr) {
353 int offset = atoi(offsetStr);
354 if (absI(
offset) == absI(ATOI_ERROR_CODE)) {
355 efiPrintf(
"invalid offset [%s]", offsetStr);
358 if (isOutOfBounds(
offset))
360 float value = atoff(valueStr);
361 if (std::isnan(value)) {
362 efiPrintf(
"invalid value [%s]", valueStr);
394#if EFI_SIMULATOR || EFI_UNIT_TEST
395 printf(
"commonInitEngineController\n");
402#if EFI_ENGINE_CONTROL
413#if EFI_PROD_CODE || EFI_SIMULATOR
416 if (hasFirmwareError()) {
421#if ! EFI_UNIT_TEST && EFI_ENGINE_CONTROL
425#if EFI_ALTERNATOR_CONTROL
433#if EFI_MALFUNCTION_INDICATOR
461#if EFI_ELECTRONIC_THROTTLE_BODY
465#if EFI_MAP_AVERAGING && defined (MODULE_MAP_AVERAGING)
468 efiPrintf(
"No MapAveraging support!");
475#if EFI_LAUNCH_CONTROL
489#ifdef MODULE_TACHOMETER
510 int expectedLastLobeProfileAngle = 360 / lobes;
512 if (expectedLastLobeProfileAngle != actualLastAngle) {
513 criticalError(
"Last HPFP angle expected %d got %f", expectedLastLobeProfileAngle, actualLastAngle);
529 criticalError(
"Broken ETB min/max %d %d",
540#if EFI_PROD_CODE && (BOARD_MC33810_COUNT > 0)
550 if (maxConfiguredCorr * maxConfiguredDwell > maxAllowedDwell) {
551 criticalError(
"Dwell=%.2f/corr=%.2f while 33810 limit %d", maxConfiguredDwell, maxConfiguredCorr, maxAllowedDwell);
563#if EFI_ENGINE_CONTROL
660#if EFI_ANTILAG_SYSTEM
668#if EFI_ELECTRONIC_THROTTLE_BODY
692#if CAM_INPUTS_COUNT != 1
712#if EFI_SHAFT_POSITION_INPUT
728#if EFI_ENGINE_EMULATOR
748#if EFI_LOGIC_ANALYZER
754 if (hasFirmwareError()) {
767#if defined(EFI_BOOTLOADER_INCLUDE_CODE)
769 if (initBootloader() != 0)
void initAccelEnrichment()
void initIgnitionAdvanceControl()
void initAlternatorCtrl()
Utility methods related to bench testing.
void initQcBenchControls()
GearControllerBase * gearController
FuelSchedule injectionEvents
IgnitionEventList ignitionEvents
void periodicFastCallback()
void periodicSlowCallback()
RpmCalculator rpmCalculator
constexpr auto & module()
InjectionEvent elements[MAX_CYLINDER_COUNT]
virtual GearControllerMode getMode() const
IgnitionEvent elements[MAX_CYLINDER_COUNT]
void setValue(const char *msg, int logicValue, bool isForce=false)
virtual int getPeriodMs()=0
virtual void PeriodicTask()=0
bool isStopped() const override
bool isCranking() const override
static void showAllSensorInfo()
void addConsoleAction(const char *token, Void callback)
Register console action without parameters.
void addConsoleActionII(const char *token, VoidIntInt callback)
Register a console command with two Integer parameters.
void addConsoleActionSS(const char *token, VoidCharPtrCharPtr callback)
void addConsoleActionSSS(const char *token, VoidCharPtrCharPtrCharPtr callback)
void addConsoleActionI(const char *token, VoidInt callback)
Register a console command with one Integer parameter.
void(* VoidCharPtrCharPtr)(const char *, const char *)
void(* VoidIntInt)(int, int)
int getAdcChannelPin(adc_channel_e hwChannel)
ioportid_t getAdcChannelPort(const char *msg, adc_channel_e hwChannel)
void initButtonDebounce()
void defaultsOrFixOnBurn()
const char * portname(ioportid_t GPIOx)
void ensureArrayIsAscendingOrDefault(const char *msg, const TValue(&values)[TSize])
void ensureArrayIsAscending(const char *msg, const TValue(&values)[TSize])
void initElectronicThrottle()
void prepareOutputSignals()
void incrementGlobalConfigurationVersion(const char *msg)
static constexpr persistent_config_s * config
static constexpr engine_configuration_s * engineConfiguration
bool validateConfigOnStartUpOrBurn()
static PeriodicFastController fastController
static void setFloat(const char *offsetStr, const char *valueStr)
PUBLIC_API_WEAK bool validateBoardConfig()
static void getShort(int offset)
static void printSensorInfo()
static void getFloat(int offset)
static PeriodicSlowController slowController
static void setByte(const int offset, const int value)
static EngineStateBlinkingTask engineStateBlinkingTask
static void setInt(const int offset, const int value)
static void initConfigActions()
char * getPinNameByAdcChannel(const char *msg, adc_channel_e hwChannel, char *buffer, size_t bufferSize)
static void getByte(int offset)
void initPeriodicEvents()
static void doPeriodicSlowCallback()
void initDataStructures()
static bool validateGdi()
static void getBit(int offset, int bit)
static void setShort(const int offset, const int value)
static void getInt(int offset)
void initRealHardwareEngineController()
static void setBit(const char *offsetStr, const char *bitStr, const char *valueStr)
void commonInitEngineController()
Engine ___engine CCM_OPTIONAL
void slowStartStopButtonCallback()
void initEngineEmulator()
void initFuelMap()
Initialize fuel map data structure.
void initGearController()
Idle Valve Control thread.
This data structure holds current malfunction codes.
void initMalfunctionIndicator(void)
We can blink out OBD-II error codes using Malfunction Indicator Light (MIL)
int getMc33810maxDwellTimer(mc33810maxDwellTimer_e value)
bool isBrainPinValid(brain_pin_e brainPin)
void startStatusThreads()
void initWarningRunningPins()
uint8_t tractionControlSpeedBins[TRACTION_CONTROL_ETB_DROP_SPEED_SIZE]
vr_threshold_s vrThreshold[VR_THRESHOLD_COUNT]
bool enableOilPressureProtect
bool isWaveAnalyzerEnabled
mc33810maxDwellTimer_e mc33810maxDwellTimer
uint8_t etbMaximumPosition
scaled_channel< uint16_t, 100, 1 > tractionControlSlipBins[TRACTION_CONTROL_ETB_DROP_SLIP_SIZE]
GearControllerMode gearControllerMode
brain_input_pin_e camInputs[CAM_INPUTS_COUNT]
scaled_channel< uint8_t, 10, 1 > etbMinimumPosition
uint32_t globalSparkCounter
scaled_channel< int16_t, 100, 1 > battLagCorrBattBins[VBAT_INJECTOR_CURVE_SIZE]
scaled_channel< uint32_t, 10, 1 > battLagCorrPressBins[VBAT_INJECTOR_CURVE_PRESSURE_SIZE]
scaled_channel< uint8_t, 2, 1 > hpfpLobeProfileQuantityBins[HPFP_LOBE_PROFILE_SIZE]
uint16_t injectorStagingRpmBins[INJ_STAGING_COUNT]
scaled_channel< int16_t, 1, 1 > cltIdleRpmBins[CLT_CURVE_SIZE]
uint16_t alsIgnRetardLoadBins[ALS_SIZE]
uint16_t veLoadBins[VE_LOAD_COUNT]
scaled_channel< uint8_t, 1, 100 > iacCoastingRpmBins[CLT_CURVE_SIZE]
scaled_channel< uint16_t, 10, 1 > hpfpFuelMassCompensationFuelPressure[HPFP_FUEL_MASS_COMPENSATION_SIZE]
uint16_t injectorStagingLoadBins[INJ_STAGING_COUNT]
uint16_t alsFuelAdjustmentLoadBins[ALS_SIZE]
uint8_t pedalToTpsPedalBins[PEDAL_TO_TPS_SIZE]
uint16_t ignTrimRpmBins[IGN_TRIM_SIZE]
scaled_channel< uint8_t, 1, 10 > idleVeRpmBins[IDLE_VE_SIZE]
float cltIdleCorrBins[CLT_IDLE_TABLE_CLT_SIZE]
float crankingFuelBins[CRANKING_CURVE_SIZE]
uint16_t injPhaseRpmBins[INJ_PHASE_RPM_COUNT]
float mafDecodingBins[MAF_DECODING_COUNT]
scaled_channel< uint16_t, 1000, 1 > fuelLevelBins[FUEL_LEVEL_TABLE_COUNT]
uint8_t idleVeLoadBins[IDLE_VE_SIZE]
uint16_t injPhaseLoadBins[INJ_PHASE_LOAD_COUNT]
uint16_t sparkDwellRpmBins[DWELL_CURVE_SIZE]
uint16_t ignitionLoadBins[IGN_LOAD_COUNT]
uint16_t fuelTrimRpmBins[FUEL_TRIM_SIZE]
uint8_t hpfpDeadtimeVoltsBins[HPFP_DEADTIME_SIZE]
uint16_t lambdaRpmBins[FUEL_RPM_COUNT]
scaled_channel< uint8_t, 1, 50 > hpfpTargetRpmBins[HPFP_TARGET_SIZE]
float scriptCurve6Bins[SCRIPT_CURVE_8]
scaled_channel< uint8_t, 50, 1 > dwellVoltageCorrValues[DWELL_CURVE_SIZE]
uint16_t boostOpenLoopLoadBins[BOOST_LOAD_COUNT]
uint16_t vvtTable1RpmBins[VVT_TABLE_SIZE]
float scriptCurve4Bins[SCRIPT_CURVE_8]
scaled_channel< uint8_t, 1, 50 > tpsTspCorrValuesBins[TPS_TPS_ACCEL_CLT_CORR_TABLE]
uint16_t vvtTable1LoadBins[VVT_TABLE_SIZE]
uint16_t vvtTable2RpmBins[VVT_TABLE_SIZE]
scaled_channel< uint16_t, 100, 1 > mapEstimateTpsBins[MAP_EST_LOAD_COUNT]
float scriptCurve5Bins[SCRIPT_CURVE_8]
scaled_channel< uint8_t, 1, 100 > boostRpmBins[BOOST_RPM_COUNT]
float tpsTpsAccelFromRpmBins[TPS_TPS_ACCEL_TABLE]
uint16_t ignitionRpmBins[IGN_RPM_COUNT]
float scriptCurve2Bins[SCRIPT_CURVE_16]
int8_t ignitionIatCorrTempBins[IAT_IGN_CORR_COUNT]
scaled_channel< int16_t, 1, 1 > ignitionCltCorrTempBins[CLT_TIMING_CURVE_SIZE]
uint16_t fuelTrimLoadBins[FUEL_TRIM_SIZE]
uint16_t alsIgnRetardrpmBins[ALS_SIZE]
float cltFuelCorrBins[CLT_FUEL_CURVE_SIZE]
float cltBoostCorrBins[BOOST_CURVE_SIZE]
scaled_channel< uint8_t, 1, 100 > rpmIdleCorrBins[CLT_IDLE_TABLE_RPM_SIZE]
float scriptCurve3Bins[SCRIPT_CURVE_8]
scaled_channel< uint8_t, 1, 100 > pedalToTpsRpmBins[PEDAL_TO_TPS_RPM_SIZE]
scaled_channel< uint8_t, 1, 50 > hpfpCompensationRpmBins[HPFP_COMPENSATION_SIZE]
scaled_channel< uint8_t, 1, 50 > idleAdvanceBins[IDLE_ADVANCE_CURVE_SIZE]
float scriptCurve1Bins[SCRIPT_CURVE_16]
float iatBoostCorrBins[BOOST_CURVE_SIZE]
int16_t crankingCycleFuelCltBins[CRANKING_CYCLE_CLT_SIZE]
float iatFuelCorrBins[IAT_CURVE_SIZE]
uint16_t veRpmBins[VE_RPM_COUNT]
uint16_t boostClosedLoopLoadBins[BOOST_LOAD_COUNT]
uint16_t vvtTable2LoadBins[VVT_TABLE_SIZE]
scaled_channel< uint8_t, 1, 5 > ignitionIatCorrLoadBins[IAT_IGN_CORR_LOAD_COUNT]
float crankingCycleBins[CRANKING_CURVE_SIZE]
scaled_channel< uint16_t, 100, 1 > hpfpFuelMassCompensationFuelMass[HPFP_FUEL_MASS_COMPENSATION_SIZE]
float tpsTpsAccelToRpmBins[TPS_TPS_ACCEL_TABLE]
scaled_channel< uint16_t, 10, 1 > hpfpTargetLoadBins[HPFP_TARGET_SIZE]
scaled_channel< uint8_t, 1, 100 > minimumOilPressureBins[8]
scaled_channel< uint8_t, 2, 1 > hpfpLobeProfileAngle[HPFP_LOBE_PROFILE_SIZE]
uint16_t mapEstimateRpmBins[MAP_EST_RPM_COUNT]
float crankingTpsBins[CRANKING_CURVE_SIZE]
scaled_channel< uint16_t, 100, 1 > sparkDwellValues[DWELL_CURVE_SIZE]
scaled_channel< uint8_t, 1, 5 > ignitionCltCorrLoadBins[CLT_TIMING_CURVE_SIZE]
uint16_t ignTrimLoadBins[IGN_TRIM_SIZE]
uint16_t alsFuelAdjustmentrpmBins[ALS_SIZE]
uint16_t lambdaLoadBins[FUEL_LOAD_COUNT]
static std::vector< CompositeEvent > events
void initTriggerCentral()
static BigBufferHandle buffer
void initVrThresholdPwm()