bundle up MAP samplers

This commit is contained in:
Matthew Kennedy 2024-06-15 17:52:29 -04:00 committed by rusefillc
parent e7ef178c8d
commit dd02db4c7b
1 changed files with 11 additions and 8 deletions

View File

@ -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
}