Commit Graph

19 Commits

Author SHA1 Message Date
tx_haggis 0f13753ed3
Performance: optimized 32-bit shifts (#1187)
* Add optimized 32-bit shifting

* Tooth based time to angle coversion is only used by a few decoders.
So move the functions into decoders.cpp

* Better separation of deocders and crank maths.

* Apply optimised shifts

* Doxygen
2024-05-30 14:12:14 +10:00
Josh Stewart f49d6ca5d8 Fix erratic pulse issue with 3 and 5 squirt configurations 2024-01-22 17:20:06 +11:00
tx_haggis 9bbd16c81b
Performance: optimize division (#1082)
* Add udiv_32_16

* Apply udiv_32_16() where possible

* Convert udiv_32_16 to assembler
It's worth 20 loop/s

* Remove unused functions

* Remove degreesPeruSx2048 - unused

* Remove angleToTime - replace with direct calls
1. Drop angleToTime()
It's slow, only partially implemented and adds zero value
(and has MISRA violations)
2. Consistent function naming
3. Doxygen

* triggerPri_Nissan360 shouldn't set timePerDegree.
It will be overwritten every loop by doCrankSpeedCalcs()

* Use angleToTimeMicroSecPerDegree() instead of timePerDegree
No loss in performance
Increased injection open/close time accuracy (so unit test values must change)
Can remove timePerDegree global.

* Hide (encapsulate) crank math globals.

* Base all angle to time conversions on decoder computed variables.
This is within 2us of the revolution based method
and is much faster - which is essentially zero percent change.

* Performance: move calculation of degreesPeruSx32768
into decoders.
Remove doCrankSpeedCalcs() - it's doing nothing
at the moment.

* Apply libdivide to triggerSetEndTeeth functions.
Since triggerToothAngle is set once at initialization
time, we can generate the libdivide struct
once and reuse it many times.

* Remove lastToothCalcAdvance - unused

* Replace 16-bit division with shift

* Replace 32-bit divison with 16-bit division

* Avoid 32-bit division; use div100()

* inline percentage()

* Optimize div100()

* MISRA fixes

* Replace magic numbers with #defs

* Replace libdivide structs with inline constants
No perf or memory changes

* Use fixed types for PWM max count variables

* Accurate rounded integer division
* Formalise rounding behavior (DIV_ROUND_CORRECT)
* Apply DIV_ROUND_CORRECT to DIV_ROUND_CLOSEST(),
UDIV_ROUND_CLOSEST(), div100(), div360(),
percentage() & halfPercentage()
* Add, fix & improve unit tests

* Add udiv_32_16_closest()

* Perf: Limit percentage calculations to 16-bits

* MISRA fixes

* Add compare_executiontime() to encapsulate common perf testing code

* Signed to unsigned division

* Convert ignitionLimits() to an inline function.
Slight speed up, probably due to removing
multiple evaluations of macro arguments.

* Split unit tests up.

* udiv_32_16 - check for valid parameters
2023-11-06 09:10:08 +11:00
Josh Stewart fc536d15f0 Rename all ino files to cpp (Excluding speeduino.ino).
Confirmed this compiles OK in Arduino IDE 2.x
Frees up 8 bytes of RAM
2023-10-06 18:10:20 +11:00
tx_haggis d9b5554a8c
Save 600+ bytes RAM (step 3 of 9) - remove per-channel schedule calculation functions, use generic equivalents instead (#1018)
* calculateInjector1Timeout proxies calculateInjectorNTimeout
Unit test still pass.

* Remove calculateInjector1Timeout,
Replace with call to calculateInjectorTimeout
All unit tests still pass.

* Remove unecassary unit test

* calculateIgnition1Timeout proxies calculateIgnitionNTimeout
Unit test all pass

* Remove calculateIgnition1Timeout,
Replace with call to calculateIgnitionTimeout
All unit tests still pass.

* Remove unecassary unit test

* calculateIgnitionAngle\d proxies
calculateIgnitionAngle
Unit tests all pass

* Remove calculateIgnitionAngle\d
Just call calculateIgnitionAngle() directly

* Route rotary ignition angle calcs
through generic calculateIgnitionTrailingRotary
function.

* Remove calculateIgnitionAngle\d
Just call calculateIgnitionTrailingRotary() directly

* calculateInjectorStartAngle: inject all parameters
Do not rely on global state
Easier unit testing.

* calculateIgnitionAngle: inject all parameters
Do not rely on global state
Easier unit testing.

* Pull all ignition global vars into schedule_calcs

* Conditional compile for schedule calc vars
Saves memory

* Optimize: break out angleToTimeIntervalRev
from angleToTime. The new function will
always be inlined.

* Optimize - simpler code path
when no channel offset (zero)

Some optimization of arithmetic operations.

* Fix unit tests

* Fix bug on injector angle calculations
Need while loops to correctly bring intermediate
values into range

---------

Co-authored-by: Josh Stewart <josh@noisymime.org>
2023-06-26 12:13:53 +10:00
Josh Stewart 4693cb2013 Change to single decoder state variable. Small (12 byte) RAM free up 2022-11-22 15:53:35 +11:00
Josh Stewart 2fc29ceef5 MISRA cleanup rule: misra-c2012-8.2 2022-11-06 09:43:29 +11:00
DeionSi 323c938988
angleToTime tests (#790)
* angleToTime tests

* Change calculation to work around integer rounding
2022-02-14 09:32:00 +11:00
Bruno Bousquet f1521b65d8 Fix MISRA violations (#268)
* improve misra checking

* fix 1600 misra violations

* fix mistyped pointer

* misra script was not filtering duplicates
2019-10-22 11:49:07 +10:00
Josh Stewart b6108b5050 Warnings cleanup 2019-08-02 10:14:25 +10:00
Josh Stewart fa621ea071 Big MISRA cleanup 2019-07-08 17:56:02 +10:00
Josh Stewart ae5cecb8a6 Fix potential overflow on low res patterns at low RPMs 2018-09-08 13:37:22 +10:00
Josh Stewart bf6c7b19d4 Minor cleanup of the crank maths code 2018-09-04 15:13:14 +10:00
Josh Stewart 765e52fce5 Move a chunk of the prediction code out of speeduino.ino into crankMaths 2018-08-31 17:35:29 +10:00
Josh Stewart 189234015f Huge amount of optimsation work on new ignition system 2018-08-14 12:46:39 +10:00
Josh Stewart cc6bf05a43 Initial work on new ignition timing method (Very messy) 2018-08-08 15:17:09 +10:00
Josh Stewart ce0e399201 More warnings cleanup 2018-07-19 23:26:31 +10:00
Josh Stewart b8a5586422 Initial conversion to the new timing maths code 2018-07-12 20:45:27 +10:00
Josh Stewart 5ce2d61186 Stub versions of new crank maths files to allow compiling 2018-06-30 09:21:13 +10:00