speeduino icon indicating copy to clipboard operation
speeduino copied to clipboard

Deduplicate ignition scheduler code

Open DeionSi opened this issue 3 years ago • 1 comments

  • Refactor IgnitionSchedule1-8 variables into IgnitionSchedule[] array.
  • Add compare, counter, timerEnable, timerDisable, startAngle, endAngle, degreesAfterTDC1 (previously channelXIgnDegrees) and channel to Schedule struct.
  • The changes to the Schedule struct has the benefit of deduplicating multiple functions/code segments:
    • refreshIgnitionTiming
    • setIgnitionSchedule
    • ignitionScheduleInterrupt
    • checkIgnitionSchedule
    • calculateIgnitionAngle

This is a direct continuation of #648 and that pull request is used as base. It is also related to #578.

This change more or less only refactors code. The logic changes are that the scheduler callbacks are only set once in initialiseAll and a small optimization into calculateIgnitionAngleWithSpecificEndAngle for rotary.

ignitionSchedule[i].member calls seem to be slowed than ignitionSchedule->member calls. This is why most functions pass a pointer to the array member rather than the number of the ignition channel.

Tested on mega2560. Loops/sec reduced by 0,5% (from Tunerstudio). Size reduced by 1,8% and memory by 0,72% (PlatformIO compile info). I've done some basic testing on the bench and the ignition events appear to happen at the correct time (scope tested).

There are other areas where code can be deduplicated as a continuation of this change.

DeionSi avatar Oct 17 '21 18:10 DeionSi

Fixed the decoder and scheduler tests. Both are successful.

DeionSi avatar Nov 07 '21 17:11 DeionSi