Skip to content

Commit

Permalink
Bug fixes for getAdvance1, getAdvance2 & secondary tables. (speeduino…
Browse files Browse the repository at this point in the history
…#1155)

* Unit testability: split out definition of statuses struct.

* Separate out getLoad() function

* Bug Fix: getAdvance1() & getAdvance2() should return a signed value.

* secondarytables.cpp - extract duplicate code into functions.

* Bug fix: BIT_STATUS3_FUEL2_ACTIVE not set in 2 cases.

* Performance: secondaryTables call percentage()
(which is optimised)

* Add secondary table tests

* Bug Fix: do not correct secondary spark multiplier

* Unit test no secondary spark with fixed timing.

* MISRA fixes

* Save memory: remove statuses::ignLoad2 & fuelLoad2 (unused)

* Unit testability: split out definition of config page structs.

* Make 3D table interpolation a const operation.

* Unit testability: inject the tune & status.

* Make the advance2 gauge work correctly in multiply mode

* Secondary table tests - no global state

* Secondary table tests: add additional spark multiply tests to cover speeduino#1274

---------

Co-authored-by: Josh Stewart <[email protected]>
  • Loading branch information
adbancroft and noisymime authored Jan 9, 2025
1 parent 784c2ed commit fbd1e4f
Show file tree
Hide file tree
Showing 18 changed files with 2,073 additions and 1,428 deletions.
14 changes: 11 additions & 3 deletions reference/speeduino.ini
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,12 @@

#define loadSourceNames = "MAP", "TPS", "IMAP/EMAP", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"
#define loadSourceUnits = "kPa", "% TPS", "%", "INVALID", "INVALID", "INVALID", "INVALID", "INVALID"

algorithmNames = bits, U08, [0:2], $loadSourceNames
algorithmUnits = bits, U08, [0:2], "kPa", "% TPS", "%", "% TPS", "INVALID", "INVALID", "INVALID", "INVALID"
algorithmLimits = array, U16, [8], "", 1.0, 0, 0, 511, 0, noMsqSave
fuel2SwitchUnits = bits, U08, [0:2], "rpm", "kPa", "% TPS", "%", "% TPS", "INVALID", "INVALID", "INVALID"
spark2ModeUnits = bits, U08, [0:2], "", "%", "deg", "deg", "deg","INVALID","INVALID","INVALID"

;All definitions of split fullStatus should keep 32 options
#define fullStatus_def_1= "seconds", "status bits", "Engine status", "syncLossCounter", "MAP (Kpa)", "INVALID", "IAT / MAT", "coolant", "batCorrection", "battery voltage x10", "O2", "egoCorrection", "iatCorrection", "wueCorrection", "RPM", "INVALID", "AEamount/2", "GammaE", "INVALID", "VE1", "VE2", "AFR Target", "TPS DOT", "INVALID", "Advance", "TPS", "loopsPerSecond", "INVALID", "free RAM", "INVALID", "boostTarget/2", "Boost duty"
Expand Down Expand Up @@ -5160,9 +5162,9 @@ cmdVSSratio6 = "E\x99\x06"
baroCorrectGauge = baroCorrection,"Baro Correction", "%", 0, 200, 130, 140, 140, 150, 0, 0
flexEnrich = flexFuelCor, "Flex Correction", "%", 0, 200, 130, 140, 140, 150, 0, 0
fuelTempCorGauge = fuelTempCor, "Fuel Temp Correction", "%", 0, 200, 130, 140, 140, 150, 0, 0
advanceGauge = advance, "Advance (Current)", "deg", 50, -10, 0, 0, 35, 45, 0, 0
advance1Gauge = advance1, "Advance1 (Spark Table 1)", "deg",50, -10, 0, 0, 35, 45, 0, 0
advance2Gauge = advance2, "Advance2 (Spark Table 2)", "deg",50, -10, 0, 0, 35, 45, 0, 0
advanceGauge = advance, "Advance (Current)", "deg", -10, 50, 0, 0, 35, 45, 0, 0
advance1Gauge = advance1, "Advance1 (Spark Table 1)", "deg",-10, 50, 0, 0, 35, 45, 0, 0
advance2Gauge = advance2ForGauge, "Advance2 (Spark Table 2)", { bitStringValue( spark2ModeUnits, spark2Mode ) }, { ign2ValuesMin }, { ign2ValuesMax }, { ign2ValueLoD }, { ign2ValueLoW }, { ign2ValueHiW }, { ign2ValueHiD }, 0, 0
dwellGauge = dwell, "Dwell (Requested)", "mSec", 0, 35.0, 1.0, 1.2, 20, 25, 3, 3
dwellActualGauge = dwellActual, "Dwell (Measured)", "mSec", 0, 35.0, 1.0, 1.2, 20, 25, 3, 3
boostTargetGauge = boostTarget, "Target Boost", "kPa", 0, {maphigh}, 0, 20, {mapwarn}, {mapdang}, 0, 0
Expand Down Expand Up @@ -5566,6 +5568,12 @@ cmdVSSratio6 = "E\x99\x06"
ign2LoadMax = { (spark2Algorithm == 0 || spark2Algorithm == 2) ? 511 : 100.0 }
ign2ValuesMin = { (spark2Mode == 1) ? 0 : -40 }
ign2ValuesMax = { (spark2Mode == 1) ? 215 : 70 }
; We have to pass a U08 through a S08 in multiply mode
advance2ForGauge = { (spark2Mode == 1) ? advance2+127 : advance2 }
ign2ValueLoD = { (spark2Mode == 1) ? ign2ValuesMin : (ign2ValuesMin/10)*9 }
ign2ValueHiD = { (spark2Mode == 1) ? ign2ValuesMax : (ign2ValuesMax/10)*9 }
ign2ValueLoW = { (spark2Mode == 1) ? ign2ValuesMin : (ign2ValuesMin/10)*8 }
ign2ValueHiW = { (spark2Mode == 1) ? ign2ValuesMax : (ign2ValuesMax/10)*8 }

fuelLoad2 = { fuel2Algorithm == 0 ? map : fuel2Algorithm == 1 ? tps : fuel2Algorithm == 2 ? 0 : 0 }
ignLoad2 = { spark2Algorithm == 0 ? map : spark2Algorithm == 1 ? tps : spark2Algorithm == 2 ? 0 : ignLoad }
Expand Down
21 changes: 21 additions & 0 deletions speeduino/bit_manip.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#pragma once

/**
* @file
* @brief Bit twiddling macros
*/

/** @brief Set bit b (0-7) in byte a */
#define BIT_SET(var,pos) ((var) |= (1U<<(pos)))

/** @brief Clear bit b (0-7) in byte a */
#define BIT_CLEAR(var,pos) ((var) &= ~(1U<<(pos)))

/** @brief Is bit pos (0-7) in byte var set? */
#define BIT_CHECK(var,pos) !!((var) & (1U<<(pos)))

/** @brief Toggle the value of bit pos (0-7) in byte var */
#define BIT_TOGGLE(var,pos) ((var)^= 1UL << (pos))

/** @brief Set the value ([0,1], [true, false]) of bit pos (0-7) in byte var */
#define BIT_WRITE(var, pos, bitvalue) ((bitvalue) ? BIT_SET((var), (pos)) : BIT_CLEAR((var), (pos)))
Loading

0 comments on commit fbd1e4f

Please sign in to comment.