static ALWAYS_INLINE void handleFuel(uint32_t eventIndex, int rpm DECLARE_ENGINE_PARAMETER_S) { if (!isInjectionEnabled(engine->engineConfiguration)) return; efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#3"); efiAssertVoid(eventIndex < engine->triggerShape.getLength(), "handleFuel/event index"); /** * Ignition events are defined by addFuelEvents() according to selected * fueling strategy */ FuelSchedule *fs = isCrankingR(rpm) ? &ENGINE(engineConfiguration2)->crankingInjectionEvents : &engine->engineConfiguration2->injectionEvents; InjectionEventList *source = &fs->events; if (!fs->hasEvents[eventIndex]) return; engine->tpsAccelEnrichment.onEngineCycleTps(PASS_ENGINE_PARAMETER_F); engine->mapAccelEnrichment.onEngineCycle(PASS_ENGINE_PARAMETER_F); ENGINE(fuelMs) = getFuelMs(rpm PASS_ENGINE_PARAMETER) * engineConfiguration->globalFuelCorrection; for (int i = 0; i < source->size; i++) { InjectionEvent *event = &source->elements[i]; if (event->injectionStart.eventIndex != eventIndex) continue; handleFuelInjectionEvent(event, rpm PASS_ENGINE_PARAMETER); } }
float getAdvance(int rpm, float engineLoad) { float angle; if (isCrankingR(rpm)) { angle = engineConfiguration->crankingTimingAngle; } else { angle = getBaseAdvance(rpm, engineLoad); } return fixAngle(angle + engineConfiguration->ignitionOffset); }
/** * @return Spark dwell time, in milliseconds. */ float getSparkDwellMsT(engine_configuration_s *engineConfiguration, int rpm) { if (isCrankingR(rpm)) { // technically this could be implemented via interpolate2d float angle = engineConfiguration->crankingChargeAngle; return getOneDegreeTimeMs(rpm) * angle; } efiAssert(!cisnan(rpm), "invalid rpm", NAN); return interpolate2d(rpm, engineConfiguration->sparkDwellBins, engineConfiguration->sparkDwell, DWELL_CURVE_SIZE); }
/** * @returns Length of each individual fuel injection, in milliseconds */ floatms_t getFuelMs(int rpm DECLARE_ENGINE_PARAMETER_S) { float theoreticalInjectionLength; if (isCrankingR(rpm)) { theoreticalInjectionLength = getCrankingFuel(PASS_ENGINE_PARAMETER_F) / getNumberOfInjections(engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER); } else { float baseFuel = getBaseFuel(rpm PASS_ENGINE_PARAMETER); float fuelPerCycle = getRunningFuel(baseFuel, rpm PASS_ENGINE_PARAMETER); theoreticalInjectionLength = fuelPerCycle / getNumberOfInjections(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER); } return theoreticalInjectionLength + ENGINE(injectorLagMs); }
void Engine::prepareFuelSchedule(DECLARE_ENGINE_PARAMETER_F) { int rpm = rpmCalculator.rpmValue; ENGINE(m.beforeInjectonSch) = GET_TIMESTAMP(); injection_mode_e mode = isCrankingR(rpm) ? CONFIG(crankingInjectionMode) : CONFIG(injectionMode); ENGINE(engineConfiguration2)->processing->addFuelEvents( mode PASS_ENGINE_PARAMETER); ENGINE(m.injectonSchTime) = GET_TIMESTAMP() - ENGINE(m.beforeInjectonSch); /** * Swap pointers. This way we are always reading from one instance while adjusting scheduling of another instance. */ FuelSchedule * t = ENGINE(engineConfiguration2)->injectionEvents; ENGINE(engineConfiguration2)->injectionEvents = ENGINE(engineConfiguration2)->processing; ENGINE(engineConfiguration2)->processing = t; }
static msg_t csThread(void) { chRegSetThreadName("status"); #if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__) while (true) { int rpm = getRpmE(engine); int is_cranking = isCrankingR(rpm); int is_running = rpm > 0 && !is_cranking; if (is_running) { // blinking while running runningPin.setValue(0); chThdSleepMilliseconds(50); runningPin.setValue(1); chThdSleepMilliseconds(50); } else { // constant on while cranking and off if engine is stopped runningPin.setValue(is_cranking); chThdSleepMilliseconds(100); } } #endif /* EFI_SHAFT_POSITION_INPUT */ return -1; }
int isCranking(void) { int rpm = getRpm(); return isCrankingR(rpm); }
injection_mode_e Engine::getCurrentInjectionMode(DECLARE_ENGINE_PARAMETER_F) { int rpm = rpmCalculator.rpmValue; return isCrankingR(rpm) ? CONFIG(crankingInjectionMode) : CONFIG(injectionMode); }
void EngineState::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { int rpm = ENGINE(rpmCalculator.rpmValue); efitick_t nowNt = getTimeNowNt(); if (isCrankingR(rpm)) { crankingTime = nowNt; } else { timeSinceCranking = nowNt - crankingTime; } sparkDwell = getSparkDwell(rpm PASS_ENGINE_PARAMETER); dwellAngle = sparkDwell / getOneDegreeTimeMs(rpm); // todo: move this into slow callback, no reason for IAT corr to be here iatFuelCorrection = getIatCorrection(iat PASS_ENGINE_PARAMETER); // todo: move this into slow callback, no reason for CLT corr to be here if (boardConfiguration->useWarmupPidAfr && clt < engineConfiguration->warmupAfrThreshold) { if (rpm < 200) { cltFuelCorrection = 1; warmupAfrPid.reset(); } else { cltFuelCorrection = warmupAfrPid.getValue(warmupTargetAfr, getAfr(PASS_ENGINE_PARAMETER_F), 1); } #if ! EFI_UNIT_TEST || defined(__DOXYGEN__) if (engineConfiguration->debugMode == WARMUP_ENRICH) { tsOutputChannels.debugFloatField1 = warmupTargetAfr; warmupAfrPid.postState(&tsOutputChannels); } #endif } else { cltFuelCorrection = getCltFuelCorrection(clt PASS_ENGINE_PARAMETER); } cltTimingCorrection = getCltTimingCorrection(clt PASS_ENGINE_PARAMETER); engineNoiseHipLevel = interpolate2d(rpm, engineConfiguration->knockNoiseRpmBins, engineConfiguration->knockNoise, ENGINE_NOISE_CURVE_SIZE); baroCorrection = getBaroCorrection(PASS_ENGINE_PARAMETER_F); injectionOffset = getinjectionOffset(rpm PASS_ENGINE_PARAMETER); float engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_F); timingAdvance = getAdvance(rpm, engineLoad PASS_ENGINE_PARAMETER); if (engineConfiguration->fuelAlgorithm == LM_SPEED_DENSITY) { float coolantC = ENGINE(engineState.clt); float intakeC = ENGINE(engineState.iat); float tps = getTPS(PASS_ENGINE_PARAMETER_F); tChargeK = convertCelsiusToKelvin(getTCharge(rpm, tps, coolantC, intakeC PASS_ENGINE_PARAMETER)); float map = getMap(); /** * *0.01 because of https://sourceforge.net/p/rusefi/tickets/153/ */ currentVE = baroCorrection * veMap.getValue(rpm, map) * 0.01; targetAFR = afrMap.getValue(rpm, map); } else { baseTableFuel = getBaseTableFuel(engineConfiguration, rpm, engineLoad); } }
bool isCrankingE(Engine *engine) { int rpm = getRpmE(engine); return isCrankingR(rpm); }