Speeduino
Loading...
Searching...
No Matches
statuses.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <stdint.h>
11#include <SimplyAtomic.h>
12#include "bit_manip.h"
13
14using byte = uint8_t;
15
16//Define bit positions within engine variable
17#define BIT_ENGINE_RUN 0 // Engine running
18#define BIT_ENGINE_CRANK 1 // Engine cranking
19#define BIT_ENGINE_ASE 2 // after start enrichment (ASE)
20#define BIT_ENGINE_WARMUP 3 // Engine in warmup
21#define BIT_ENGINE_ACC 4 // in acceleration mode (TPS accel)
22#define BIT_ENGINE_DCC 5 // in deceleration mode
23#define BIT_ENGINE_MAPACC 6 // MAP acceleration mode
24#define BIT_ENGINE_MAPDCC 7 // MAP deceleration mode
25
26// Bit masks for statuses::status1
27#define BIT_STATUS1_INJ1 0 //inj1
28#define BIT_STATUS1_INJ2 1 //inj2
29#define BIT_STATUS1_INJ3 2 //inj3
30#define BIT_STATUS1_INJ4 3 //inj4
31#define BIT_STATUS1_DFCO 4 //Deceleration fuel cutoff
32#define BIT_STATUS1_BOOSTCUT 5 //Fuel component of MAP based boost cut out
33#define BIT_STATUS1_TOOTHLOG1READY 6 //Used to flag if tooth log 1 is ready
34#define BIT_STATUS1_TOOTHLOG2READY 7 //Used to flag if tooth log 2 is ready (Log is not currently used)
35
36// Bit masks for statuses::status2
37#define BIT_STATUS2_HLAUNCH 0 //Hard Launch indicator
38#define BIT_STATUS2_SLAUNCH 1 //Soft Launch indicator
39#define BIT_STATUS2_HRDLIM 2 //Hard limiter indicator
40#define BIT_STATUS2_SFTLIM 3 //Soft limiter indicator
41#define BIT_STATUS2_BOOSTCUT 4 //Spark component of MAP based boost cut out
42#define BIT_STATUS2_ERROR 5 // Error is detected
43#define BIT_STATUS2_IDLE 6 // idle on
44#define BIT_STATUS2_SYNC 7 // Whether engine has sync or not
45
46// Bit masks for statuses::status3
47#define BIT_STATUS3_RESET_PREVENT 0 //Indicates whether reset prevention is enabled
48#define BIT_STATUS3_NITROUS 1
49#define BIT_STATUS3_FUEL2_ACTIVE 2
50#define BIT_STATUS3_VSS_REFRESH 3
51#define BIT_STATUS3_HALFSYNC 4 //shows if there is only sync from primary trigger, but not from secondary.
52#define BIT_STATUS3_NSQUIRTS1 5
53#define BIT_STATUS3_UNUSED1 6
54#define BIT_STATUS3_UNUSED2 7
55
56// Bit masks for statuses::status4
57#define BIT_STATUS4_WMI_EMPTY 0 //Indicates whether the WMI tank is empty
58#define BIT_STATUS4_VVT1_ERROR 1 //VVT1 cam angle within limits or not
59#define BIT_STATUS4_VVT2_ERROR 2 //VVT2 cam angle within limits or not
60#define BIT_STATUS4_FAN 3 //Fan Status
61#define BIT_STATUS4_BURNPENDING 4
62#define BIT_STATUS4_STAGING_ACTIVE 5
63#define BIT_STATUS4_COMMS_COMPAT 6
64#define BIT_STATUS4_ALLOW_LEGACY_COMMS 7
65
66// Bit masks for statuses::status5
67#define BIT_STATUS5_FLATSH 0 //Flat shift hard cut
68#define BIT_STATUS5_FLATSS 1 //Flat shift soft cut
69#define BIT_STATUS5_SPARK2_ACTIVE 2
70#define BIT_STATUS5_KNOCK_ACTIVE 3
71#define BIT_STATUS5_KNOCK_PULSE 4
72#define BIT_STATUS5_UNUSED6 5
73#define BIT_STATUS5_UNUSED7 6
74#define BIT_STATUS5_UNUSED8 7
75
76#define BIT_AIRCON_REQUEST 0 //Indicates whether the A/C button is pressed
77#define BIT_AIRCON_COMPRESSOR 1 //Indicates whether the A/C compressor is running
78#define BIT_AIRCON_RPM_LOCKOUT 2 //Indicates the A/C is locked out due to the RPM being too high/low, or the post-high/post-low-RPM "stand-down" lockout period
79#define BIT_AIRCON_TPS_LOCKOUT 3 //Indicates the A/C is locked out due to high TPS, or the post-high-TPS "stand-down" lockout period
80#define BIT_AIRCON_TURNING_ON 4 //Indicates the A/C request is on (i.e. A/C button pressed), the lockouts are off, however the start delay has not yet elapsed. This gives the idle up time to kick in before the compressor.
81#define BIT_AIRCON_CLT_LOCKOUT 5 //Indicates the A/C is locked out either due to high coolant temp.
82#define BIT_AIRCON_FAN 6 //Indicates whether the A/C fan is running
83#define BIT_AIRCON_UNUSED8 7
84
85#define ENGINE_PROTECT_BIT_RPM 0
86#define ENGINE_PROTECT_BIT_MAP 1
87#define ENGINE_PROTECT_BIT_OIL 2
88#define ENGINE_PROTECT_BIT_AFR 3
89#define ENGINE_PROTECT_BIT_COOLANT 4
90
98struct statuses {
99 // cppcheck-suppress misra-c2012-6.1 ; False positive - MISRA C:2012 Rule (R 6.1) permits the use of boolean for bit fields.
100 volatile bool hasSync : 1;
102 // cppcheck-suppress misra-c2012-6.1
104 // cppcheck-suppress misra-c2012-6.1
106 // cppcheck-suppress misra-c2012-6.1
108 // cppcheck-suppress misra-c2012-6.1
109 volatile bool fpPrimed : 1;
110 // cppcheck-suppress misra-c2012-6.1
111 volatile bool injPrimed : 1;
112 // cppcheck-suppress misra-c2012-6.1
113 volatile bool tachoSweepEnabled : 1;
114 // cppcheck-suppress misra-c2012-6.1
115 volatile bool tachoAlt : 1;
116
119 long longRPM;
121 long MAP;
127 byte TPSlast;
129 volatile int rpmDOT;
130 byte VE;
131 byte VE1;
132 byte VE2;
137 int IAT;
163 volatile byte ethanolPct;
164 volatile int8_t fuelTemp;
165 unsigned long AEEndTime;
166 volatile byte status1;
167 volatile byte status2;
168 volatile byte status3;
169 volatile byte status4;
170 volatile byte status5;
172 unsigned int PW1;
173 unsigned int PW2;
174 unsigned int PW3;
175 unsigned int PW4;
176 unsigned int PW5;
177 unsigned int PW6;
178 unsigned int PW7;
179 unsigned int PW8;
180 volatile byte runSecs;
181 volatile byte secl;
186 unsigned int clutchEngagedRPM;
191 bool testActive; // Not in use ? Replaced by testOutputs ?
193 byte idleLoad;
199 byte nSquirts;
204 volatile byte syncLossCounter;
206 volatile byte knockCount;
208 byte compositeTriggerUsed; // 0 means composite logger disabled, 2 means use secondary input (1st cam), 3 means use tertiary input (2nd cam), 4 means log both cams together
209 int16_t vvt1Angle; //Has to be a long for PID calcs (CL VVT control)
211 long vvt1Duty; //Has to be a long for PID calcs (CL VVT control)
216 byte gear;
221 byte wmiPW;
222 int16_t vvt2Angle; //Has to be a long for PID calcs (CL VVT control)
224 long vvt2Duty; //Has to be a long for PID calcs (CL VVT control)
226 byte TS_SD_Status; //TunerStudios SD card status
228};
229
234static inline bool HasAnySyncUnsafe(const statuses &status) {
235 return status.hasSync || BIT_CHECK(status.status3, BIT_STATUS3_HALFSYNC);
236}
237
238static inline bool HasAnySync(const statuses &status) {
239 ATOMIC() {
240 return HasAnySyncUnsafe(status);
241 }
242 return false; // Just here to avoid compiler warning.
243}
Bit twiddling macros.
#define BIT_CHECK(var, pos)
Is bit pos (0-7) in byte var set?
Definition bit_manip.h:15
uint8_t byte
Definition config_pages.h:15
static uint32_t rshift(uint32_t a)
Bitwise right shift - generic, unoptimized, case.
Definition bit_shifts.h:349
static bool HasAnySync(const statuses &status)
Definition statuses.h:238
#define BIT_STATUS3_HALFSYNC
Definition statuses.h:51
static bool HasAnySyncUnsafe(const statuses &status)
Non-atomic version of HasAnySync. **Should only be called in an ATOMIC() block***.
Definition statuses.h:234
The status struct with current values for all 'live' variables.
Definition statuses.h:98
byte dwellCorrection
Definition statuses.h:143
uint16_t baroADC
Definition statuses.h:120
volatile byte syncLossCounter
Definition statuses.h:204
byte ASEValue
Definition statuses.h:213
int16_t vvt2Angle
Definition statuses.h:222
byte testOutputs
Test Output bits (only first bit used/tested ?)
Definition statuses.h:190
volatile bool hasSync
Definition statuses.h:100
uint16_t canin[16]
16bit raw value of selected canin data for channels 0-15
Definition statuses.h:194
byte oilPressure
Definition statuses.h:218
uint8_t current_caninchannel
Definition statuses.h:195
bool launchingSoft
Definition statuses.h:183
int16_t EMAP
EMAP ... (See config6::useEMAP for EMAP enablement)
Definition statuses.h:122
unsigned int PW3
In uS.
Definition statuses.h:174
byte launchCorrection
Definition statuses.h:155
unsigned int PW6
In uS.
Definition statuses.h:177
bool idleUpActive
Definition statuses.h:161
long vvt1Duty
Definition statuses.h:211
bool CTPSActive
Definition statuses.h:162
unsigned int PW8
In uS.
Definition statuses.h:179
byte CLIdleTarget
Definition statuses.h:160
byte vvt2TargetAngle
Definition statuses.h:223
volatile byte status5
Status 5 ... (See also config10 Status 5* members and BIT_STATU5_* defines)
Definition statuses.h:170
byte TPSlast
Definition statuses.h:127
bool clutchTrigger
Definition statuses.h:105
bool testActive
Definition statuses.h:191
bool idleUpOutputActive
Definition statuses.h:215
unsigned long AEEndTime
Definition statuses.h:165
byte baroCorrection
Definition statuses.h:154
bool flatShiftingHard
Definition statuses.h:187
int16_t vvt1Angle
Definition statuses.h:209
unsigned int PW4
In uS.
Definition statuses.h:175
byte VE2
Definition statuses.h:132
byte flexCorrection
Definition statuses.h:156
volatile uint16_t loopsPerSecond
Definition statuses.h:182
bool toothLogEnabled
Definition statuses.h:207
byte VE1
Definition statuses.h:131
int IAT
Definition statuses.h:137
int16_t mapDOT
Definition statuses.h:128
byte wueCorrection
Definition statuses.h:151
byte batCorrection
Definition statuses.h:152
int8_t advance
Definition statuses.h:145
unsigned int PW1
In uS.
Definition statuses.h:172
uint16_t dwell
dwell (coil primary winding/circuit on) time (in ms * 10 ? See correctionsDwell)
Definition statuses.h:141
uint8_t tpsADC
Definition statuses.h:125
uint8_t engine
Engine status bits (See BIT_ENGINE_* defines on top of this file)
Definition statuses.h:171
volatile byte knockCount
Definition statuses.h:206
byte nSquirts
Number of injector squirts per cycle (per injector)
Definition statuses.h:199
int8_t advance2
Definition statuses.h:147
volatile byte status4
Status bits (See BIT_STATUS4_* defines on top of this file)
Definition statuses.h:169
uint16_t vss
Definition statuses.h:214
byte knockRetard
Definition statuses.h:205
byte TS_SD_Status
Definition statuses.h:226
uint16_t boostTarget
Definition statuses.h:189
bool fuelPumpOn
Definition statuses.h:203
byte gear
Definition statuses.h:216
volatile bool injPrimed
Tracks whether or not the injector priming has been completed yet.
Definition statuses.h:111
volatile byte secl
Definition statuses.h:181
byte airConStatus
Definition statuses.h:227
int coolant
Definition statuses.h:135
byte VE
Definition statuses.h:130
volatile uint16_t actualDwell
actual dwell time if new ignition mode is used (in uS)
Definition statuses.h:142
byte fuelPressure
Definition statuses.h:217
unsigned int clutchEngagedRPM
Definition statuses.h:186
volatile uint32_t startRevolutions
Definition statuses.h:188
unsigned int PW5
In uS.
Definition statuses.h:176
volatile bool tachoAlt
Definition statuses.h:115
uint16_t boostDuty
Boost Duty percentage value * 100 to give 2 points of precision.
Definition statuses.h:192
bool previousClutchTrigger
Definition statuses.h:107
byte battery10
Definition statuses.h:144
volatile byte runSecs
Definition statuses.h:180
uint16_t iatADC
Definition statuses.h:138
int8_t advance1
Definition statuses.h:146
uint16_t RPM
RPM - Current Revs per minute.
Definition statuses.h:117
long longRPM
RPM as long int (gets assigned to / maintained in statuses.RPM as well)
Definition statuses.h:119
byte wmiPW
Definition statuses.h:221
volatile int8_t fuelTemp
Definition statuses.h:164
byte vvt1TargetAngle
Definition statuses.h:210
byte RPMdiv100
RPM value scaled (divided by 100) to fit a byte (0-255, e.g. 12000 => 120)
Definition statuses.h:118
uint16_t corrections
Definition statuses.h:148
long vvt2Duty
Definition statuses.h:224
byte fanDuty
Definition statuses.h:220
uint8_t TPS
Definition statuses.h:124
byte outputsStatus
Definition statuses.h:225
byte afrTarget
Definition statuses.h:159
volatile byte status3
Status bits (See BIT_STATUS3_* defines on top of this file)
Definition statuses.h:168
bool launchingHard
Definition statuses.h:184
volatile int rpmDOT
Definition statuses.h:129
byte fuelTempCorrection
Definition statuses.h:157
int16_t fuelLoad
Definition statuses.h:201
byte nChannels
Definition statuses.h:200
byte nitrous_status
Definition statuses.h:198
unsigned int PW2
In uS.
Definition statuses.h:173
volatile bool fpPrimed
Tracks whether or not the fuel pump priming has been completed yet.
Definition statuses.h:109
int16_t tpsDOT
Definition statuses.h:126
uint8_t O2_2
Definition statuses.h:134
uint16_t freeRAM
Definition statuses.h:185
int16_t ignLoad
Definition statuses.h:202
byte compositeTriggerUsed
Definition statuses.h:208
byte egoCorrection
Definition statuses.h:150
int16_t flexBoostCorrection
Definition statuses.h:197
bool initialisationComplete
Tracks whether the setup() function has run completely.
Definition statuses.h:103
int8_t flexIgnCorrection
Definition statuses.h:158
byte idleLoad
Either the current steps or current duty cycle for the idle control.
Definition statuses.h:193
uint16_t O2_2ADC
Definition statuses.h:140
byte iatCorrection
Definition statuses.h:153
uint8_t O2
Definition statuses.h:133
uint16_t injAngle
Definition statuses.h:212
long MAP
Manifold absolute pressure. Has to be a long for PID calcs (Boost control)
Definition statuses.h:121
volatile bool tachoSweepEnabled
Definition statuses.h:113
uint16_t crankRPM
Definition statuses.h:196
uint8_t baro
Barometric pressure is simply the initial MAP reading, taken before the engine is running....
Definition statuses.h:123
volatile byte ethanolPct
Definition statuses.h:163
unsigned int PW7
In uS.
Definition statuses.h:178
uint16_t AEamount
Definition statuses.h:149
byte engineProtectStatus
Definition statuses.h:219
volatile byte status2
status 2/control indicator bits (launch control, boost cut, spark errors, See BIT_STATUS2_* defines)
Definition statuses.h:167
uint16_t cltADC
Definition statuses.h:136
uint16_t O2ADC
Definition statuses.h:139
volatile byte status1
Status bits (See BIT_STATUS1_* defines on top of this file)
Definition statuses.h:166