Commit Graph

63 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
tx_haggis cb78a45326
Unit Tests: provide correct filename in test messages (#1211)
* Make Unity print the correct file name - VS code output will then provide a clickable link :-)

* Provide macro to save, set & restore Unity filename
2024-05-29 15:27:50 +10:00
tx_haggis 170c3a8a31
Fix compile failure (PR->master branch mismatch issue) (#1200) 2024-03-22 22:48:01 +11:00
tx_haggis e08d5dab25
test_math: make unit tests pass on Teensy (#1137)
Required converting dwell, actualDwell, dwellCrank & dwellRun to unsigned.
2024-03-21 11:45:10 +11:00
Josh Stewart a1302a0cc3 Correct staging unit test for corrected open time 2024-02-20 16:10:40 +11:00
tx_haggis 2eb8daacc8
Add unit tests for recent 3 cylinder squirts changes (init.cpp) (#1179)
* Fix & extend fueling init unit tests for 3 cylinders

* Unit test - Fix possible buffer overrun
2024-02-11 23:11:54 +11:00
tx_haggis b8c14c3d48
Set all the global options the PW unit test depends on. (#1176) 2024-02-10 08:49:09 +11:00
Josh Stewart 7b5bfc8a24 Corrected values for 3 cylinder init unit tests 2024-02-02 15:19:11 +11:00
Josh Stewart 1439750731 Separate PW Limit calculation into own function and optimise. Add unit tests for this 2024-01-16 22:25:15 +11:00
Josh Stewart 7079b50aa1 Fix tests 2023-12-06 15:20:23 +11:00
tx_haggis d5d4274054
Bug fix: reset control can be enabled but pin can be set to zero (#1142)
* Reset control pin: don't over-writie the board default with zero.
The added unit tests interfered with each other & hung -
solution is to reinitialize the global context at the start of
each test.

* Additional pin init tests
2023-11-28 10:13:00 +11:00
tx_haggis 963f6317ba
Save 600+ bytes RAM (step 5 of 9) - De-duplicate setSchedule functions (#1111)
* initialiseSchedulers: factor out shared code.

* Proxy setFuelSchedule\d through generic
setFuelSchedule() function

* Directly call setFuelSchedule

* Simplify unit tests

* Proxy setIgnitionSchedule\d through generic
setIgnitionSchedule() function

* Directly call setIgnitionSchedule

* Simplify unit tests

* Optimize by partially inlining
the set[Fuel|Ignition]Schedule funcs

* Use the embedded schedule compare
& counter members instead of using
hardcoded individual channel macros.

* Unit test adjustCrankAngle
2023-11-24 09:35:43 +11:00
tx_haggis 53d18accf8
Use portable paths (that work on Win & Linux) (#1131) 2023-11-06 18:50:21 +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
Vitor Moreno B. Sales f8ffbb13da
Added taper entering DFCO (#1118)
* Added taper for DFCO for ignition and fuel

Used 1 byte of RAM and 4 on page 9

* Moved data to be compatible with DFCO map thres

* Added taper for DFCO for ignition and fuel

Used 1 byte of RAM and 4 on page 9

* Moved data to be compatible with DFCO map thres

* Fixed potential overflow and DFCO tests

* Moved math into functions and added tests

---------

Co-authored-by: Josh Stewart <josh@noisymime.org>
2023-10-25 10:09:57 +11:00
tx_haggis b03db96ad7
Save 600+ bytes RAM (step 4 of 9) - deduplicate scheduler ISR functions (#1063) 2023-10-07 08:25:26 +11:00
Josh Stewart f0b6ba030d Increase DFCO Hyster range to 0-500.
Fixes #1100
2023-10-05 23:02:15 +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 2a6c6bd8ed Add unit tests for staging and update other tests 2023-06-26 11:48:54 +10:00
Josh Stewart 4e157ce504 Change test paths to use / rather than \
Should be cross platform this way
2023-05-15 15:40:56 +10:00
tx_haggis 18501d4cbd
Additonal schedule initialization unit tests (#1046)
* const

* Add RUN_TEST_P

* Reduce test memory usage.

* More granular fuel tests - better failure reports

* More granular ignition tests - better failure reports

* Add unit tests for no injection timing

* Add fuel schedule oddfire tests

* Unit test ignition odd fire
2023-05-15 15:16:41 +10:00
tx_haggis 424a96d9ea
Test start/end callback assignment (#1044) 2023-05-07 19:42:09 +10:00
Josh Stewart 1e66cfc5a6 Fix unit test build errors from last commit 2023-04-30 19:52:02 +10:00
mike501 e0dbb38794
Renix 44 tooth decoder (includes 66 tooth code) (#1037)
* Renix 44-2-2 & 66-2-2-2 initial version

coded, not tested yet, saving to secure code

* First working version on ardustim

* updates to trigger setup

* latest changes

* 66 tooth working but occasional short dwell

* staging before major rewrite

updating the primary trigger to look for 12th system tooth to increment toothCurrentCount after this checking

* updated working but with bad dwell/timing

code works but the timing and dwell are not accurate once rpm goes over 400rpm

* Renix code 1st release

updated code to do both 44 and 66 tooth within a single set of functions

* remove support for sequential for 44 tooth

Sequential (via cam) was added for 44 tooth to enable future expansion. This is interfering with the normal code on the first testers car.

* updated cam position

* remove Dev logging

* remove logging

* updates to trigger decoding

fixes to 66 tooth pattern and removal of secondary flag for 44 tooth decoder

* fixes to decoder - rpm double

* updates to support display cam tooth position

added code to display which teeth the cam tooth arrives on as VVT1 & 2 and as Aux0 and Aux1.

* Revert "updates to support display cam tooth position"

This reverts commit d2ace89ea7.

* fixes from update to latest speeduino firmware

* Add 4cyl semi-seq injector pairing option

* Add timestamp field to SD logs

* Fix soft and hard rev limiter (#813)

* Increase dwell limiter in RX-8 type ignition (#820)

Currently the dwell limiter calculation considers rotary ignition to have more than 1 pulse per revolution. This only holds true for FC/FD type ignition which is wasted spark correctly resulting in 2 pulses per revolution. RX-8 type ignition however is fully sequential so there is only 1 pulse per revolution. As a result the dwell limiter is being calculated too low.
This change fixes the issue by correctly assuming 1 pulse per revolution in RX-8 type ignition

* All tapers use byte counters (#746)

Fixes

Update idle.ino

* Correct variable size for MAPlast

* Fix issue with SD RPM threshold not correctly detecting on/off

* Reorganise Engine Protection UI

* Add low/high battery voltage indicator (#824)

Fixes #822

* Remove tacho output flags (#814)

* fix typos in code documentation (#816)

* fix typos in code documentation

* minor reverts

* fix typos in ini

Co-authored-by: Josh Stewart <josh@noisymime.org>

* Added Trigger for the Yamaha Vmax motorcycle, 1990 and up. (#823)

* Test 1

* Added the Vmax decoder option

* Added the Yamaha Vmax decoder

Co-authored-by: RempageR1 <unconfigured@null.spigotmc.org>
Co-authored-by: Josh Stewart <josh@noisymime.org>

* Allow for '?' command through legacy comms.

Fixes #821

* Added idle advance start threshold (#747)

* Added idle advance start threshold

On lower temp and/or on ethanol the engine need to crank more, without this my starter get a kick and the engine backfires.

This enable it only at 200 RPM below the target

* Use define to idle advance RPM threshold

Co-authored-by: Josh Stewart <josh@noisymime.org>

* Remove previousLoopTime - never used (#706)

* Simplify the corrections calculations using div100

* Fix the calculations dash figures when battery correction is applied to open time only

* PWM and on/off idle fixes/cleanup (#806)

* Idle fixes #1

* Idle fixes #2

Co-authored-by: Josh Stewart <josh@noisymime.org>

* Remove duplicate iacClosedLoopTable. Lookup idle target RPM @ 4Hz after CLT reading

* Fix validTrigger assignment in Vmax decoder

* Align TPS_rateOfChange scale. Potential fix for #773

* Enable semi sequential and wasted COP on half sync (#478)

* Semi/Full sequential mode

Semi sequential in case of absent phase input at crank, engine will almost aways start in semi sequential mode

Minimal code change at speeduino.ino

Fix RPM reading when in half sync

* Update with latest changes in master

* Less calls to change functions

See #478 chat history for details

* Semi/Full sequential mode

Semi sequential in case of absent phase input at crank, engine will almost aways start in semi sequential mode

Minimal code change at speeduino.ino

Fix RPM reading when in half sync

* Update with latest changes in master

* Less calls to change functions

See #478 chat history for details

* Add sync status to log

* Updates

Updated speeduino.ini
Updated updates.ino

* Fix error in half to full sync function

Co-authored-by: Josh Stewart <josh@noisymime.org>

* Fixes after merge with speeduino master

* improved debug on sync loss using VVTangle

* additional debug

uses aux channels for debug  eg currentStatus.canin[2] these need removing from the full version. Also uses VVT1 pin for debug via VVT1_PIN_OFF()  and VVT1_PIN_ON()

* fixes

* remove secondary trigger

* different logging

* Final Version

* added automated tests

* fixed fuel pump always being on

* fix build issues after merge with master

* Change how 44 or 66 tooth selected

Updated to work out 44 or 66 tooth decoder based on the number of cylinders, 4 cylinder = 44 tooth, 6 cylinder = 66 tooth

* Fix typo in ini

* Delete compile_commands.json

* Remove duplicate declarations

* Remove VVT code from other PR

* fix speeduino.ino

Remove unintended additions to speeduino.ino

---------

Co-authored-by: Josh Stewart <josh@noisymime.org>
Co-authored-by: Pasi Kemppainen <48950874+pazi88@users.noreply.github.com>
Co-authored-by: theKraid <37898397+theKraid@users.noreply.github.com>
Co-authored-by: Vitor Moreno B. Sales <vitor_boss@yahoo.com.br>
Co-authored-by: Corey-Harding <91717711+Corey-Harding@users.noreply.github.com>
Co-authored-by: Daniel Tobias <dantob@users.noreply.github.com>
Co-authored-by: RempageR1 <103254506+RempageR1@users.noreply.github.com>
Co-authored-by: RempageR1 <unconfigured@null.spigotmc.org>
Co-authored-by: tx_haggis <13982343+adbancroft@users.noreply.github.com>
Co-authored-by: Vitor Moreno B. Sales <vitor.m.benevides@outlook.com>
2023-04-30 18:30:34 +10:00
tx_haggis 4a509d19f2
Unit test fuel and ignition scheduler initialisation (#1039)
* Unit test fuel schedule initialisation

* Move initialisation tests to their own harness
Saves memory

* Rename test_misc to test_tables

* Rename test_misc2 to test_math

* Reduce memory usage

* Fill out remaining ignition init unit tests
2023-04-27 14:43:04 +10:00
tx_haggis d1399a0f33
Enable Teensy 3.5 unit testing (#1038)
* Add missing forward declarations
Found while compiling teensy35 unit tests

* Unit test should not rely on EEPROM

* Fix bad lib_dep
Teensy35 #includes FlexCAN_4 headers

* Fix circular include
logger.h needs FPU_MAX_SIZE which is defined
in globals.h. Globals.h includes logger.h!

* Ambguity in integer typedefs
2023-04-26 15:54:15 +10:00
tx_haggis 0afffb2ca0
Unit test the schedule calculations (#1010)
* Refactor: separate out schedule calcs from speeduino.ino
(so they can be unit tested)

* Add unit tests for compute_delay

* Use PROGMEM to store test input & output

* Add some 720 unit tests

* Rename unit test file

* Test ignition codepaths 2-8

* Test ign1 calcs

* Add first injector calc tests

* Add 720 deg tests
Simplify

* Simplify test_calc_inj1_timeout

* Claw back RAM

* Simplify test framework
Channel angle is part of the test data set.

* Move schedule calculation unit tests into their own harness
Competing for RAM with the rest of Speeduino
can cause them to fail,

* Performance: inline all schedule calcs.

* Unit test end angle

* Unit test calculateIgnitionAngle1

* Test start angles also
And test end angles for channel 1

* Unit test calculateIgnitionAngle3

* Unit test calculateIgnitionAngle4

* Improve unit test output

* Add Nissan360 decoder unit tests.

* Add Ford ST170 decoder unit tests

* Add NGC decoder unit tests
2023-03-06 17:23:17 +11:00
DeionSi 3495877d0f
Tests failing due to out of memory and uninitialized variables (#979)
* Free up memory for tests_misc

* Tests failed by uninitialised variables
2023-01-09 06:53:45 +09:00
Josh Stewart b30fde5685 Fix unit tests following #939 2022-12-14 11:25:54 +00:00
Josh Stewart 4693cb2013 Change to single decoder state variable. Small (12 byte) RAM free up 2022-11-22 15:53:35 +11:00
tx_haggis 56ab7c054d
Table 3d: change X-axis orientation to match Y-axis (#771)
* Change X axis in memory orientation to match Y

* X & Y axes can use the same type (Ie.e class)

* Table3D axis iterator: replace reverse() with rbegin()

* Use iterators as part of unit tests

* Doxygen fixes/corrections
2022-11-14 10:26:14 +11:00
Josh Stewart 3997708997 Improvements to init unit tests 2022-09-29 09:47:37 +10:00
Josh Stewart 5fafa94056 Fix unit test value 2022-06-01 17:06:44 +10:00
Josh Stewart ec2fcd906f Add more unit tests for TAE 2022-05-25 15:28:11 +10:00
Josh Stewart 3bd945f546 Add unit test for basic TAE 2022-05-25 11:02:55 +10:00
Vitor Moreno B. Sales 9c3f745c16
All tapers use byte counters (#746)
Fixes

Update idle.ino
2022-04-05 07:27:54 +10:00
tx_haggis 6c12bcc32d
Separate table axis I/O conversion from iteration (#767)
* Missing include

* 1. Add int16_byte class
2. Add axis factory function for int16_byte instances
(flyweight pattern)

* Separate out axis iteration and I/O conversions

* Optimize for size and performance.

* Fix unit test
2022-02-24 16:11:54 +11:00
tx_haggis fc9967e31d
Performance: optimize fuel trim PW calcs (#756)
* Consistent set of div100 functions

* Add typedef for trimTable3d

* Performance: use div100() function
when applying fuel trim corrections

* Silly ARM compiler!

* Unit test fixes

* Fix tests: expected & actual parameters were swapped

* div100(): add 8-bit overloads for completeness

* Fix unit tests
1. Force call to correct div100() overload
2. Use appropriately typed assertion

* Restore use of USE_LIBDIVIDE preprocessor symbol

* Add div360() - encapsulate libdivide use

* Fix copy/paste issue.
2022-02-18 14:55:43 +11:00
DeionSi 323c938988
angleToTime tests (#790)
* angleToTime tests

* Change calculation to work around integer rounding
2022-02-14 09:32:00 +11:00
Josh Stewart 65bcf5b1a7 Add unit tests for maths functions 2022-01-05 13:13:41 +11:00
tx_haggis be0f2c69c7
Add table2d tests (#748)
* Improve native debug experience

* Add unit tests for table2d
2021-12-23 15:07:38 +11:00
tx_haggis 9ad500189b
Performance: 15%+ loop/sec speedup by optimising 3d table bilinear interpolation (#735)
* Bi-linear interpolation - round towards nearest integer

Add the equivalent of 0.5 to the final calculation pre-rounding.
This will have the effect of rounding to the nearest integer, rather
than truncating. I.e. rounding down

* Unit tests: isolate table tests and check interpolation x/y bins

* Unit tests: add native table3d tests

* Unit tests: derive min/max from axis test values

* Unit tests: more detailed messages

* Unit tests: fix rounding & unit tests

* Performance

* Performance: use uint16_t instead of unsigned long
for the fixed point math: we only need the fractional
part. I.e. 1.16 not 16.16

* Use narrowest possible type

* Optimise bin position logic for performance

* Only promote to uint32_t when really required.

* Simplify bin checks - no zero width bins

* Save memory: use a single byte for the last bin caches

* Performance: increment pointers instead of
repeatedly dereferncing array by index.

* Comments

* Incorrect array underrun logic

* Rename type, comments

* Fix unit tests
2021-12-09 20:40:31 +11:00
Josh Stewart 61de6ff038 Fix tests from PR #662 2021-11-18 11:51:32 +11:00
tx_haggis 5ed9ec3ca9
Reduce 3d table memory usage (>500 bytes) (#662)
* Use table_row_iterator_t to adjust ignitionTable

* Separate 2d & 3d table code, abstract page to table iterator conversion.

This is just moving code around in preparation for future changes.

* Reduce table RAM (.bss) usage

Generate a separate type for each possible
3d axis & size combination.

This turns what was runtime information into
compile time data.

* Save 1 byte per table.

Use a flag value (INT16_MAX) instead of a separate boolean
flag

* File renaming

table_iterator -> table3d_iterator.h
table3d.h -> table3d_interpolate.h
table3d.cpp -> table3d_interpolate.cpp
table3d_types.h -> table3d.h

* Optimize page.cpp: reduce code clutter, maintain performance

* Reduce flash usage

* Encapsulate table metadata

* Performance - hoist if statement

* Replace function with macro

* Use a packed enum as a type identifier

Use a packed enum as a type identifier

Slimmer data types

* Use table iterators for random access to table
values and axis.

* Centralize write buffer check

* Encapsulate 16-bit reference concept

* Performance: make table iterators proper classes

This allows us to chain calls on temporaries - not possible
with regular function calls.

* Performance: encapsulate EEPROM update
& address increment

* Save flash - don't duplicate function

* Performance: directly invalidate table cache

* Separate out iterator reversal

* Separate out entity mapping & per-byte access

Much faster, smaller code footprint & easier to understand

* Code quality fixes

* Separate out axis metadata

* Doxygen comments

* Separate int16_ref into separate file

* Separate out table axies & values into separate types

No need for metadata types & more localised code.
E.g. creating iterators is now alongside the data over
which they iterate.

* Doxygen
2021-11-18 11:30:29 +11:00
Josh Stewart efe962598a Fix for OUTPUT test failing due to random pin assignments 2021-10-05 11:15:14 +11:00
Josh Stewart fd9fa36c29 Major revamp of unit testing framework 2020-11-19 21:38:00 +11:00
Josh Stewart efb84d4449 Fix some of the broken tables tests 2020-11-10 16:12:10 +11:00
Josh Stewart 01298b4747 Update tests for new PW calc options 2020-08-17 11:25:00 +10:00
Josh Stewart e3afe69955 Minor fixes from last PR pull 2020-08-16 09:55:13 +10:00
Josh Stewart 99abe431db Take 2 on fixing PW tests 2020-08-14 13:34:23 +10:00