72#if defined(EFI_BOOTLOADER_INCLUDE_CODE)
73#include "bootloader/bootloader.h"
78#ifdef MODULE_MAP_AVERAGING
100using namespace rusefi::stringutil;
103#if EFI_ENGINE_CONTROL
107 for (
size_t i=0;i<efi::size(
events.elements);i++) {
126 return FAST_CALLBACK_PERIOD_MS;
137 return SLOW_CALLBACK_PERIOD_MS;
150#if EFI_SHAFT_POSITION_INPUT
153 bool is_running =
false;
171#if EFI_ENGINE_CONTROL
180#if EFI_SHAFT_POSITION_INPUT
215 snprintf(
buffer, bufferSize,
"NONE");
221 snprintf(
buffer, bufferSize,
"NONE");
238#define isOutOfBounds(offset) ((offset<0) || (offset) >= (int) sizeof(engine_configuration_s))
241 if (isOutOfBounds(
offset))
244 uint16_t value = *ptr;
248 efiPrintf(
"short%s%d is %d", CONSOLE_DATA_PROTOCOL_TAG,
offset, value);
252 if (isOutOfBounds(
offset))
255 uint8_t value = *ptr;
259 efiPrintf(
"byte%s%d is %d", CONSOLE_DATA_PROTOCOL_TAG,
offset, value);
262static void setBit(
const char *offsetStr,
const char *bitStr,
const char *valueStr) {
263 int offset = atoi(offsetStr);
264 if (absI(
offset) == absI(ATOI_ERROR_CODE)) {
265 efiPrintf(
"invalid offset [%s]", offsetStr);
268 if (isOutOfBounds(
offset)) {
271 int bit = atoi(bitStr);
272 if (absI(bit) == absI(ATOI_ERROR_CODE)) {
273 efiPrintf(
"invalid bit [%s]", bitStr);
276 int value = atoi(valueStr);
277 if (absI(value) == absI(ATOI_ERROR_CODE)) {
278 efiPrintf(
"invalid value [%s]", valueStr);
282 *ptr ^= (-value ^ *ptr) & (1 << bit);
286 efiPrintf(
"bit%s%d/%d is %d", CONSOLE_DATA_PROTOCOL_TAG,
offset, bit, value);
291 if (isOutOfBounds(
offset))
294 *ptr = (uint16_t) value;
300 if (isOutOfBounds(
offset))
303 *ptr = (uint8_t) value;
309 if (isOutOfBounds(
offset))
312 int value = (*ptr >> bit) & 1;
316 efiPrintf(
"bit%s%d/%d is %d", CONSOLE_DATA_PROTOCOL_TAG,
offset, bit, value);
320 if (isOutOfBounds(
offset))
327 efiPrintf(
"int%s%d is %d", CONSOLE_DATA_PROTOCOL_TAG,
offset, value);
331 if (isOutOfBounds(
offset))
340 if (isOutOfBounds(
offset))
347 efiPrintf(
"float%s%d is %.5f", CONSOLE_DATA_PROTOCOL_TAG,
offset, value);
350static void setFloat(
const char *offsetStr,
const char *valueStr) {
351 int offset = atoi(offsetStr);
352 if (absI(
offset) == absI(ATOI_ERROR_CODE)) {
353 efiPrintf(
"invalid offset [%s]", offsetStr);
356 if (isOutOfBounds(
offset))
358 float value = atoff(valueStr);
359 if (std::isnan(value)) {
360 efiPrintf(
"invalid value [%s]", valueStr);
392#if EFI_SIMULATOR || EFI_UNIT_TEST
393 printf(
"commonInitEngineController\n");
400#if EFI_ENGINE_CONTROL
411#if EFI_PROD_CODE || EFI_SIMULATOR
414 if (hasFirmwareError()) {
419#if ! EFI_UNIT_TEST && EFI_ENGINE_CONTROL
423#if EFI_ALTERNATOR_CONTROL
431#if EFI_MALFUNCTION_INDICATOR
459#if EFI_ELECTRONIC_THROTTLE_BODY
463#if EFI_MAP_AVERAGING && defined (MODULE_MAP_AVERAGING)
466 efiPrintf(
"No MapAveraging support!");
473#if EFI_LAUNCH_CONTROL
487#ifdef MODULE_TACHOMETER
508 int expectedLastLobeProfileAngle = 360 / lobes;
510 if (expectedLastLobeProfileAngle != actualLastAngle) {
511 criticalError(
"Last HPFP angle expected %d got %f", expectedLastLobeProfileAngle, actualLastAngle);
523#if defined(HW_HELLEN_UAEFI)
531 criticalError(
"Broken ETB min/max %d %d",
542#if EFI_PROD_CODE && (BOARD_MC33810_COUNT > 0)
552 if (maxConfiguredCorr * maxConfiguredDwell > maxAllowedDwell) {
553 criticalError(
"Dwell=%.2f/corr=%.2f while 33810 limit %d", maxConfiguredDwell, maxConfiguredCorr, maxAllowedDwell);
565#if EFI_ENGINE_CONTROL
662#if EFI_ANTILAG_SYSTEM
670#if EFI_ELECTRONIC_THROTTLE_BODY
694#if CAM_INPUTS_COUNT != 1
714#if EFI_SHAFT_POSITION_INPUT
730#if EFI_ENGINE_EMULATOR
750#if EFI_LOGIC_ANALYZER
756 if (hasFirmwareError()) {
769#if defined(EFI_BOOTLOADER_INCLUDE_CODE)
771 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]
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 alsIgnRetardrpmBins[ALS_RPM_SIZE]
uint16_t vvtTable2RpmBins[VVT_TABLE_RPM_SIZE]
uint16_t ignTrimRpmBins[IGN_TRIM_SIZE]
scaled_channel< uint8_t, 1, 50 > hpfpCompensationRpmBins[HPFP_COMPENSATION_RPM_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 alsFuelAdjustmentrpmBins[ALS_RPM_SIZE]
uint16_t lambdaRpmBins[FUEL_RPM_COUNT]
scaled_channel< uint8_t, 1, 10 > idleVeRpmBins[IDLE_VE_SIZE_RPM]
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]
float scriptCurve4Bins[SCRIPT_CURVE_8]
scaled_channel< uint8_t, 1, 50 > tpsTspCorrValuesBins[TPS_TPS_ACCEL_CLT_CORR_TABLE]
uint16_t vvtTable1LoadBins[VVT_TABLE_SIZE]
scaled_channel< uint16_t, 100, 1 > mapEstimateTpsBins[MAP_EST_LOAD_COUNT]
scaled_channel< uint8_t, 1, 5 > ignitionCltCorrLoadBins[CLT_TIMING_LOAD_AXIS_SIZE]
scaled_channel< int16_t, 1, 1 > ignitionCltCorrTempBins[CLT_TIMING_TEMP_AXIS_SIZE]
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]
uint16_t fuelTrimLoadBins[FUEL_TRIM_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 > 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]
uint16_t injectorStagingRpmBins[INJ_STAGING_RPM_SIZE]
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 vvtTable1RpmBins[VVT_TABLE_RPM_SIZE]
uint16_t mapEstimateRpmBins[MAP_EST_RPM_COUNT]
float crankingTpsBins[CRANKING_CURVE_SIZE]
scaled_channel< uint16_t, 100, 1 > sparkDwellValues[DWELL_CURVE_SIZE]
uint16_t ignTrimLoadBins[IGN_TRIM_SIZE]
uint16_t lambdaLoadBins[FUEL_LOAD_COUNT]
static std::vector< CompositeEvent > events
void initTriggerCentral()
static BigBufferHandle buffer
void initVrThresholdPwm()