From dd02db4c7bd17bb3abf338d650410f259fea89e8 Mon Sep 17 00:00:00 2001 From: Matthew Kennedy Date: Sat, 15 Jun 2024 17:52:29 -0400 Subject: [PATCH] bundle up MAP samplers --- .../engine_cycle/map_averaging.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/firmware/controllers/engine_cycle/map_averaging.cpp b/firmware/controllers/engine_cycle/map_averaging.cpp index b7f40f58bf..537cfa82bf 100644 --- a/firmware/controllers/engine_cycle/map_averaging.cpp +++ b/firmware/controllers/engine_cycle/map_averaging.cpp @@ -54,15 +54,19 @@ static int averagedMapBufIdx = 0; /** * here we have averaging start and averaging end points for each cylinder */ -static scheduling_s startTimers[MAX_CYLINDER_COUNT][2]; -static scheduling_s endTimers[MAX_CYLINDER_COUNT][2]; +struct sampler { + scheduling_s startTimer; + scheduling_s endTimer; +}; + +static sampler samplers[MAX_CYLINDER_COUNT][2]; #if EFI_ENGINE_CONTROL && EFI_PROD_CODE static void endAveraging(MapAverager* arg); static size_t currentMapAverager = 0; -static void startAveraging(scheduling_s *endAveragingScheduling) { +static void startAveraging(sampler* s) { efiAssertVoid(ObdCode::CUSTOM_ERR_6649, hasLotsOfRemainingStack(), "lowstck#9"); // TODO: set currentMapAverager based on cylinder bank @@ -71,7 +75,7 @@ static void startAveraging(scheduling_s *endAveragingScheduling) { mapAveragingPin.setHigh(); - scheduleByAngle(endAveragingScheduling, getTimeNowNt(), engine->engineState.mapAveragingDuration, + scheduleByAngle(&s->endTimer, getTimeNowNt(), engine->engineState.mapAveragingDuration, { endAveraging, &averager }); } #endif // EFI_ENGINE_CONTROL && EFI_PROD_CODE @@ -259,14 +263,13 @@ void mapAveragingTriggerCallback( // only if value is already prepared int structIndex = getRevolutionCounter() % 2; - scheduling_s *startTimer = &startTimers[i][structIndex]; - scheduling_s *endTimer = &endTimers[i][structIndex]; + sampler* s = &samplers[i][structIndex]; // at the moment we schedule based on time prediction based on current RPM and angle // we are loosing precision in case of changing RPM - the further away is the event the worse is precision // todo: schedule this based on closest trigger event, same as ignition works - scheduleByAngle(startTimer, edgeTimestamp, samplingStart, - { startAveraging, endTimer }); + scheduleByAngle(&s->startTimer, edgeTimestamp, samplingStart, + { startAveraging, s }); } #endif // EFI_ENGINE_CONTROL && EFI_PROD_CODE }