refactoring
This commit is contained in:
parent
56c66c8939
commit
8fe9ab120e
|
@ -1676,8 +1676,8 @@ typedef enum {
|
|||
CUSTOM_NAN_ENGINE_LOAD = 6000,
|
||||
CUSTOM_WRONG_ALGORITHM = 6001,
|
||||
CUSTOM_NAN_ENGINE_LOAD_2 = 6002,
|
||||
CUSTOM_NEGATIVE_DURATION = 6003,
|
||||
CUSTOM_NAN_DURACTION = 6004,
|
||||
CUSTOM_OBD_6003 = 6003,
|
||||
CUSTOM_OBD_6004 = 6004,
|
||||
CUSTOM_EMPTY_FSIO_STACK = 6005,
|
||||
CUSTOM_UNKNOWN_FSIO = 6006,
|
||||
CUSTOM_NO_FSIO = 6007,
|
||||
|
|
|
@ -210,17 +210,91 @@ static void seScheduleByTime(scheduling_s *scheduling, efitimeus_t time, schfunc
|
|||
scheduleByTime(scheduling, time, callback, pair);
|
||||
}
|
||||
|
||||
static void scheduleFuelInjection(InjectionSignalPair *pair, efitimeus_t nowUs,
|
||||
floatus_t injectionStartDelayUs, floatus_t durationUs,
|
||||
InjectionEvent *event DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
if (durationUs < 0) {
|
||||
warning(CUSTOM_NEGATIVE_DURATION, "duration cannot be negative: %d", durationUs);
|
||||
static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event,
|
||||
int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
|
||||
/**
|
||||
* todo: this is a bit tricky with batched injection. is it? Does the same
|
||||
* wetting coefficient works the same way for any injection mode, or is something
|
||||
* x2 or /2?
|
||||
*/
|
||||
const floatms_t injectionDuration = ENGINE(wallFuel).adjust(event->outputs[0]->injectorIndex, ENGINE(fuelMs) PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
#if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__)
|
||||
printf("fuel fuelMs=%f adjusted=%f\t\n", ENGINE(fuelMs), injectionDuration);
|
||||
#endif /*EFI_PRINTF_FUEL_DETAILS */
|
||||
|
||||
/**
|
||||
* todo: pre-calculate 'numberOfInjections'
|
||||
* see also injectorDutyCycle
|
||||
*/
|
||||
if (!isCrankingR(rpm) && injectionDuration * getNumberOfInjections(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER_SUFFIX) > getEngineCycleDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX)) {
|
||||
warning(CUSTOM_TOO_LONG_FUEL_INJECTION, "Too long fuel injection %fms", injectionDuration);
|
||||
} else if (isCrankingR(rpm) && injectionDuration * getNumberOfInjections(engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER_SUFFIX) > getEngineCycleDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX)) {
|
||||
warning(CUSTOM_TOO_LONG_CRANKING_FUEL_INJECTION, "Too long cranking fuel injection %fms", injectionDuration);
|
||||
}
|
||||
|
||||
ENGINE(actualLastInjection) = injectionDuration;
|
||||
if (cisnan(injectionDuration)) {
|
||||
warning(CUSTOM_OBD_NAN_INJECTION, "NaN injection pulse");
|
||||
return;
|
||||
}
|
||||
if (cisnan(durationUs)) {
|
||||
warning(CUSTOM_NAN_DURACTION, "NaN in scheduleFuelInjection", durationUs);
|
||||
if (injectionDuration < 0) {
|
||||
warning(CUSTOM_OBD_NEG_INJECTION, "Negative injection pulse %f", injectionDuration);
|
||||
return;
|
||||
}
|
||||
floatus_t durationUs = MS2US(injectionDuration);
|
||||
|
||||
|
||||
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
|
||||
scheduleMsg(logger, "handleFuel totalPerCycle=%f", totalPerCycle);
|
||||
scheduleMsg(logger, "handleFuel engineCycleDuration=%f", engineCycleDuration);
|
||||
#endif /* FUEL_MATH_EXTREME_LOGGING */
|
||||
|
||||
floatus_t injectionStartDelayUs = ENGINE(rpmCalculator.oneDegreeUs) * event->injectionStart.angleOffset;
|
||||
|
||||
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
|
||||
scheduleMsg(logger, "handleFuel pin=%s eventIndex %d duration=%fms %d", event->output->name,
|
||||
eventIndex,
|
||||
injectionDuration,
|
||||
getRevolutionCounter());
|
||||
scheduleMsg(logger, "handleFuel pin=%s delay=%f %d", event->output->name, injectionStartDelayUs,
|
||||
getRevolutionCounter());
|
||||
#endif /* EFI_DEFAILED_LOGGING */
|
||||
|
||||
InjectionSignalPair *pair = &ENGINE(fuelActuators[injEventIndex]);
|
||||
|
||||
if (event->isSimultanious) {
|
||||
/**
|
||||
* this is pretty much copy-paste of 'scheduleOutput'
|
||||
* 'scheduleOutput' is currently only used for injection, so maybe it should be
|
||||
* changed into 'scheduleInjection' and unified? todo: think about it.
|
||||
*/
|
||||
|
||||
scheduling_s * sUp = &pair->signalTimerUp;
|
||||
// todo: sequential need this logic as well, just do not forget to clear flag pair->isScheduled = true;
|
||||
scheduling_s * sDown = &pair->signalTimerDown;
|
||||
|
||||
scheduleTask(sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, event);
|
||||
scheduleTask(sDown, (int) injectionStartDelayUs + durationUs,
|
||||
(schfunc_t) &endSimultaniousInjection, event);
|
||||
|
||||
} else {
|
||||
#if EFI_UNIT_TEST || defined(__DOXYGEN__)
|
||||
printf("scheduling injection angle=%f/delay=%f injectionDuration=%f\r\n", event->injectionStart.angleOffset, injectionStartDelayUs, injectionDuration);
|
||||
#endif
|
||||
|
||||
// we are in this branch of code only in case of NOT IM_SIMULTANEOUS injection
|
||||
// we are ignoring low RPM in order not to handle "engine was stopped to engine now running" transition
|
||||
if (rpm > 2 * engineConfiguration->cranking.rpm) {
|
||||
const char *outputName = event->outputs[0]->name;
|
||||
if (prevOutputName == outputName && engineConfiguration->injectionMode != IM_SIMULTANEOUS) {
|
||||
warning(CUSTOM_OBD_SKIPPED_FUEL, "looks like skipped fuel event %d %s", getRevolutionCounter(), outputName);
|
||||
}
|
||||
prevOutputName = outputName;
|
||||
}
|
||||
|
||||
efitimeus_t nowUs = getTimeNowUs();
|
||||
|
||||
InjectorOutputPin *output = event->outputs[0];
|
||||
#if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__)
|
||||
printf("fuelout %s duration %d total=%d\t\n", output->name, (int)durationUs,
|
||||
|
@ -255,92 +329,6 @@ static void scheduleFuelInjection(InjectionSignalPair *pair, efitimeus_t nowUs,
|
|||
efitimeus_t turnOffTime = nowUs + (int) (injectionStartDelayUs + durationUs);
|
||||
seScheduleByTime(sDown, turnOffTime, (schfunc_t) &seTurnPinLow, pair);
|
||||
}
|
||||
|
||||
static ALWAYS_INLINE void handleFuelInjectionEvent(int injEventIndex, InjectionEvent *event,
|
||||
int rpm DECLARE_ENGINE_PARAMETER_SUFFIX) {
|
||||
|
||||
/**
|
||||
* todo: this is a bit tricky with batched injection. is it? Does the same
|
||||
* wetting coefficient works the same way for any injection mode, or is something
|
||||
* x2 or /2?
|
||||
*/
|
||||
const floatms_t injectionDuration = ENGINE(wallFuel).adjust(event->outputs[0]->injectorIndex, ENGINE(fuelMs) PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
#if EFI_PRINTF_FUEL_DETAILS || defined(__DOXYGEN__)
|
||||
printf("fuel fuelMs=%f adjusted=%f\t\n", ENGINE(fuelMs), injectionDuration);
|
||||
#endif /*EFI_PRINTF_FUEL_DETAILS */
|
||||
|
||||
/**
|
||||
* todo: pre-calculate 'numberOfInjections'
|
||||
* see also injectorDutyCycle
|
||||
*/
|
||||
if (!isCrankingR(rpm) && injectionDuration * getNumberOfInjections(engineConfiguration->injectionMode PASS_ENGINE_PARAMETER_SUFFIX) > getEngineCycleDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX)) {
|
||||
warning(CUSTOM_TOO_LONG_FUEL_INJECTION, "Too long fuel injection %fms", injectionDuration);
|
||||
} else if (isCrankingR(rpm) && injectionDuration * getNumberOfInjections(engineConfiguration->crankingInjectionMode PASS_ENGINE_PARAMETER_SUFFIX) > getEngineCycleDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX)) {
|
||||
warning(CUSTOM_TOO_LONG_CRANKING_FUEL_INJECTION, "Too long cranking fuel injection %fms", injectionDuration);
|
||||
}
|
||||
|
||||
ENGINE(actualLastInjection) = injectionDuration;
|
||||
if (cisnan(injectionDuration)) {
|
||||
warning(CUSTOM_OBD_NAN_INJECTION, "NaN injection pulse");
|
||||
return;
|
||||
}
|
||||
if (injectionDuration < 0) {
|
||||
warning(CUSTOM_OBD_NEG_INJECTION, "Negative injection pulse %f", injectionDuration);
|
||||
return;
|
||||
}
|
||||
|
||||
#if FUEL_MATH_EXTREME_LOGGING || defined(__DOXYGEN__)
|
||||
scheduleMsg(logger, "handleFuel totalPerCycle=%f", totalPerCycle);
|
||||
scheduleMsg(logger, "handleFuel engineCycleDuration=%f", engineCycleDuration);
|
||||
#endif /* FUEL_MATH_EXTREME_LOGGING */
|
||||
|
||||
floatus_t injectionStartDelayUs = ENGINE(rpmCalculator.oneDegreeUs) * event->injectionStart.angleOffset;
|
||||
|
||||
#if EFI_DEFAILED_LOGGING || defined(__DOXYGEN__)
|
||||
scheduleMsg(logger, "handleFuel pin=%s eventIndex %d duration=%fms %d", event->output->name,
|
||||
eventIndex,
|
||||
injectionDuration,
|
||||
getRevolutionCounter());
|
||||
scheduleMsg(logger, "handleFuel pin=%s delay=%f %d", event->output->name, injectionStartDelayUs,
|
||||
getRevolutionCounter());
|
||||
#endif /* EFI_DEFAILED_LOGGING */
|
||||
|
||||
InjectionSignalPair *pair = &ENGINE(fuelActuators[injEventIndex]);
|
||||
|
||||
if (event->isSimultanious) {
|
||||
/**
|
||||
* this is pretty much copy-paste of 'scheduleOutput'
|
||||
* 'scheduleOutput' is currently only used for injection, so maybe it should be
|
||||
* changed into 'scheduleInjection' and unified? todo: think about it.
|
||||
*/
|
||||
|
||||
scheduling_s * sUp = &pair->signalTimerUp;
|
||||
// todo: sequential need this logic as well, just do not forget to clear flag pair->isScheduled = true;
|
||||
scheduling_s * sDown = &pair->signalTimerDown;
|
||||
|
||||
scheduleTask(sUp, (int) injectionStartDelayUs, (schfunc_t) &startSimultaniousInjection, event);
|
||||
scheduleTask(sDown, (int) injectionStartDelayUs + MS2US(injectionDuration),
|
||||
(schfunc_t) &endSimultaniousInjection, event);
|
||||
|
||||
} else {
|
||||
#if EFI_UNIT_TEST || defined(__DOXYGEN__)
|
||||
printf("scheduling injection angle=%f/delay=%f injectionDuration=%f\r\n", event->injectionStart.angleOffset, injectionStartDelayUs, injectionDuration);
|
||||
#endif
|
||||
|
||||
// we are in this branch of code only in case of NOT IM_SIMULTANEOUS injection
|
||||
// we are ignoring low RPM in order not to handle "engine was stopped to engine now running" transition
|
||||
if (rpm > 2 * engineConfiguration->cranking.rpm) {
|
||||
const char *outputName = event->outputs[0]->name;
|
||||
if (prevOutputName == outputName && engineConfiguration->injectionMode != IM_SIMULTANEOUS) {
|
||||
warning(CUSTOM_OBD_SKIPPED_FUEL, "looks like skipped fuel event %d %s", getRevolutionCounter(), outputName);
|
||||
}
|
||||
prevOutputName = outputName;
|
||||
}
|
||||
|
||||
efitimeus_t nowUs = getTimeNowUs();
|
||||
floatus_t durationUs = MS2US(injectionDuration);
|
||||
scheduleFuelInjection(pair, nowUs, injectionStartDelayUs, durationUs, event PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
}
|
||||
}
|
||||
|
||||
static void fuelClosedLoopCorrection(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
|
||||
|
|
Loading…
Reference in New Issue