diff --git a/firmware/controllers/algo/engine.cpp b/firmware/controllers/algo/engine.cpp index 1e375ad743..cd319c64bb 100644 --- a/firmware/controllers/algo/engine.cpp +++ b/firmware/controllers/algo/engine.cpp @@ -22,6 +22,7 @@ #include "efilib2.h" #include "settings.h" #include "aux_valves.h" +#include "map_averaging.h" #if EFI_PROD_CODE || defined(__DOXYGEN__) #include "injector_central.h" @@ -443,31 +444,15 @@ injection_mode_e Engine::getCurrentInjectionMode(DECLARE_ENGINE_PARAMETER_SIGNAT * so that trigger event handler/IO scheduler tasks are faster. */ void Engine::periodicFastCallback(DECLARE_ENGINE_PARAMETER_SIGNATURE) { - int rpm = rpmCalculator.rpmValue; - if (isValidRpm(rpm)) { - MAP_sensor_config_s * c = &engineConfiguration->map; - angle_t start = interpolate2d("mapa", 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, "cylinderStart"); - engine->engineState.mapAveragingStart[i] = cylinderStart; - } - engine->engineState.mapAveragingDuration = interpolate2d("samp", 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; - } +#if EFI_MAP_AVERAGING + refreshMapAveragingPreCalc(PASS_ENGINE_PARAMETER_SIGNATURE); +#endif engineState.periodicFastCallback(PASS_ENGINE_PARAMETER_SIGNATURE); engine->m.beforeFuelCalc = GET_TIMESTAMP(); + int rpm = rpmCalculator.rpmValue; ENGINE(injectionDuration) = getInjectionDuration(rpm PASS_ENGINE_PARAMETER_SUFFIX); engine->m.fuelCalcTime = GET_TIMESTAMP() - engine->m.beforeFuelCalc; diff --git a/firmware/controllers/map_averaging.cpp b/firmware/controllers/map_averaging.cpp index 0065812d05..3ad170ef11 100644 --- a/firmware/controllers/map_averaging.cpp +++ b/firmware/controllers/map_averaging.cpp @@ -59,7 +59,7 @@ static volatile int measurementsPerRevolutionCounter = 0; static volatile int measurementsPerRevolution = 0; /** - * In this lock-free imlementation 'readIndex' is always pointing + * In this lock-free implementation 'readIndex' is always pointing * to the consistent copy of accumulator and counter pair */ static int readIndex = 0; @@ -208,6 +208,30 @@ static void applyMapMinBufferLength() { } } +void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE) { + int rpm = engine->rpmCalculator.rpmValue; + if (isValidRpm(rpm)) { + MAP_sensor_config_s * c = &engineConfiguration->map; + angle_t start = interpolate2d("mapa", 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, "cylinderStart"); + engine->engineState.mapAveragingStart[i] = cylinderStart; + } + engine->engineState.mapAveragingDuration = interpolate2d("samp", 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; + } + +} + /** * Shaft Position callback used to schedule start and end of MAP averaging */ diff --git a/firmware/controllers/map_averaging.h b/firmware/controllers/map_averaging.h index ddcff65fc2..dd8516816f 100644 --- a/firmware/controllers/map_averaging.h +++ b/firmware/controllers/map_averaging.h @@ -17,6 +17,7 @@ void mapAveragingCallback(adcsample_t newValue); #endif void initMapAveraging(Logging *sharedLogger, Engine *engine); +void refreshMapAveragingPreCalc(DECLARE_ENGINE_PARAMETER_SIGNATURE); #endif /* EFI_MAP_AVERAGING */