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); } }
static ALWAYS_INLINE void handleFuel(bool limitedFuel, uint32_t eventIndex, int rpm DECLARE_ENGINE_PARAMETER_S) { if (!isInjectionEnabled(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 = ENGINE(engineConfiguration2)->injectionEvents; InjectionEventList *source = &fs->injectionEvents; if (!fs->hasEvents[eventIndex]) return; ENGINE(tpsAccelEnrichment.onNewValue(getTPS(PASS_ENGINE_PARAMETER_F) PASS_ENGINE_PARAMETER)); ENGINE(engineLoadAccelEnrichment.onEngineCycle(PASS_ENGINE_PARAMETER_F)); ENGINE(fuelMs) = getFuelMs(rpm PASS_ENGINE_PARAMETER) * CONFIG(globalFuelCorrection); for (int i = 0; i < source->size; i++) { InjectionEvent *event = &source->elements[i]; if (event->injectionStart.eventIndex != eventIndex) continue; handleFuelInjectionEvent(i, limitedFuel, event, rpm PASS_ENGINE_PARAMETER); } }
/** * 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. */ void Engine::periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) { int rpm = rpmCalculator.rpmValue; if (isValidRpm(rpm)) { MAP_sensor_config_s * c = &engineConfiguration->map; angle_t start = interpolate2d(rpm, c->samplingAngleBins, c->samplingAngle, MAP_ANGLE_SIZE); angle_t offsetAngle = TRIGGER_SHAPE(eventAngles[CONFIG(mapAveragingSchedulingAtIndex)]); for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { angle_t cylinderOffset = getEngineCycle(engineConfiguration->operationMode) * i / engineConfiguration->specs.cylindersCount; float cylinderStart = start + cylinderOffset - offsetAngle + tdcPosition(); fixAngle(cylinderStart); engine->engineState.mapAveragingStart[i] = cylinderStart; } engine->engineState.mapAveragingDuration = interpolate2d(rpm, c->samplingWindowBins, c->samplingWindow, MAP_WINDOW_SIZE); } else { for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { engine->engineState.mapAveragingStart[i] = NAN; } engine->engineState.mapAveragingDuration = NAN; } engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_F); engine->m.beforeFuelCalc = GET_TIMESTAMP(); ENGINE(fuelMs) = getFuelMs(rpm PASS_ENGINE_PARAMETER) * engineConfiguration->globalFuelCorrection; engine->m.fuelCalcTime = GET_TIMESTAMP() - engine->m.beforeFuelCalc; prepareFuelSchedule(PASS_ENGINE_PARAMETER_F); }
static void printState(void) { #if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__) // todo: make SWO work // char *msg = "hello\r\n"; // for(int i=0;i<strlen(msg);i++) { // ITM_SendChar(msg[i]); // } int rpm = getRpmE(engine); if (subscription[(int) RO_TOTAL_REVOLUTION_COUNTER]) debugInt(&logger, "ckp_c", getCrankEventCounter()); if (subscription[(int) RO_RUNNING_REVOLUTION_COUNTER]) debugInt(&logger, "ckp_r", triggerCentral.triggerState.runningRevolutionCounter); if (subscription[(int) RO_RUNNING_TRIGGER_ERROR]) debugInt(&logger, "trg_r_errors", triggerCentral.triggerState.runningTriggerErrorCounter); if (subscription[(int) RO_RUNNING_ORDERING_TRIGGER_ERROR]) debugInt(&logger, "trg_r_order_errors", triggerCentral.triggerState.runningOrderingErrorCounter); if (subscription[(int) RO_WAVE_CHART_CURRENT_SIZE]) debugInt(&logger, "wave_chart_current", 0); // debugInt(&logger, "idl", getIdleSwitch()); // debugFloat(&logger, "table_spark", getAdvance(rpm, getMaf()), 2); float engineLoad = getEngineLoadT(PASS_ENGINE_PARAMETER_F); float baseFuel = getBaseFuel(rpm PASS_ENGINE_PARAMETER); debugFloat(&logger, "fuel_base", baseFuel, 2); // debugFloat(&logger, "fuel_iat", getIatCorrection(getIntakeAirTemperature()), 2); // debugFloat(&logger, "fuel_clt", getCltCorrection(getCoolantTemperature()), 2); debugFloat(&logger, "fuel_lag", engine->injectorLagMs, 2); debugFloat(&logger, "fuel", getFuelMs(rpm PASS_ENGINE_PARAMETER), 2); debugFloat(&logger, "timing", engine->engineState.timingAdvance, 2); // float map = getMap(); #endif /* EFI_SHAFT_POSITION_INPUT */ }
percent_t getInjectorDutyCycle(int rpm DECLARE_ENGINE_PARAMETER_S) { floatms_t totalPerCycle = getFuelMs(rpm PASS_ENGINE_PARAMETER) * getNumberOfInjections(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER); floatms_t engineCycleTime = getCrankshaftRevolutionTimeMs(rpm) * (engineConfiguration->operationMode == TWO_STROKE ? 1 : 2); return 100 * totalPerCycle / engineCycleTime; }
static void printSensors(Logging *log, bool fileFormat) { // current time, in milliseconds int nowMs = currentTimeMillis(); float sec = ((float) nowMs) / 1000; reportSensorF(log, fileFormat, "time", "", sec, 3); int rpm = 0; #if EFI_SHAFT_POSITION_INPUT || defined(__DOXYGEN__) rpm = getRpmE(engine); reportSensorI(log, fileFormat, "rpm", "RPM", rpm); // reportSensorF(log, fileFormat, "TRG_0_DUTY", "%", getTriggerDutyCycle(0), 2); // reportSensorF(log, fileFormat, "TRG_1_DUTY", "%", getTriggerDutyCycle(1), 2); #endif if (hasMafSensor()) { reportSensorF(log, fileFormat, "maf", "V", getMaf(), 2); reportSensorF(log, fileFormat, "mafr", "kg/hr", getRealMaf(), 2); } reportSensorF(log, fileFormat, "ENGINE_LOAD", "x", getEngineLoadT(), 2); #if EFI_ANALOG_SENSORS || defined(__DOXYGEN__) if (engineConfiguration->hasMapSensor) { reportSensorF(log, fileFormat, "MAP", "kPa", getMap(), 2); // reportSensorF(log, fileFormat, "map_r", "V", getRawMap(), 2); } if (hasBaroSensor()) { reportSensorF(log, fileFormat, "baro", "kPa", getBaroPressure(), 2); } if (engineConfiguration->hasAfrSensor) { reportSensorF(log, fileFormat, "afr", "AFR", getAfr(), 2); } #endif #if EFI_VEHICLE_SPEED || defined(__DOXYGEN__) if (engineConfiguration->hasVehicleSpeedSensor) { reportSensorF(log, fileFormat, "vss", "kph", getVehicleSpeed(), 2); } #endif /* EFI_PROD_CODE */ reportSensorF(log, fileFormat, "ks", "count", engine->knockCount, 0); reportSensorF(log, fileFormat, "kv", "v", engine->knockVolts, 2); // reportSensorF(log, fileFormat, "vref", "V", getVRef(engineConfiguration), 2); if (hasVBatt(PASS_ENGINE_PARAMETER_F)) { reportSensorF(log, fileFormat, "vbatt", "V", getVBatt(PASS_ENGINE_PARAMETER_F), 2); } reportSensorF(log, fileFormat, "TP", "%", getTPS(PASS_ENGINE_PARAMETER_F), 2); if (fileFormat) { reportSensorF(log, fileFormat, "tpsacc", "ms", engine->tpsAccelEnrichment.getTpsEnrichment(PASS_ENGINE_PARAMETER_F), 2); reportSensorF(log, fileFormat, "advance", "deg", engine->tpsAccelEnrichment.getTpsEnrichment(PASS_ENGINE_PARAMETER_F), 2); reportSensorF(log, fileFormat, "advance", "deg", getFuelMs(rpm PASS_ENGINE_PARAMETER), 2); } if (engineConfiguration->hasCltSensor) { reportSensorF(log, fileFormat, "CLT", "C", getCoolantTemperature(PASS_ENGINE_PARAMETER_F), 2); } reportSensorF(log, fileFormat, "MAT", "C", getIntakeAirTemperature(PASS_ENGINE_PARAMETER_F), 2); // debugFloat(&logger, "tch", getTCharge1(tps), 2); }