1 /* Copyright 2008 Fred Cooke
3 This file is part of the FreeEMS project.
5 FreeEMS software is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
10 FreeEMS software is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/
18 We ask that if you make any changes to this file you email them upstream to
19 us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
21 Thank you for choosing FreeEMS to run your engine! */
26 * @ingroup globalHeaders
28 * @brief General struct typedefs
30 * This file contains all of the general purpose and smaller struct typedefs.
36 /* Header file multiple inclusion protection courtesy eclipse Header Template */
37 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */
38 #ifndef FILE_STRUCTS_H_SEEN
39 #define FILE_STRUCTS_H_SEEN
42 /* For noobs : http://www.space.unibe.ch/comp_doc/c_manual/C/SYNTAX/struct.html
43 * http://en.wikipedia.org/wiki/Composite_type
44 * http://www.cs.usfca.edu/~wolber/SoftwareDev/C/CStructs.htm
45 * http://sandbox.mc.edu/~bennet/cs220/codeex/struct_c.html
49 /* Naming should be in the singular form such that the instantiation can be the plural */
54 * BEWARE : Be explicit!!
56 * char 8 bit (defaults to unsigned, but always specify signed/unsigned anyway)
57 * short 16 bit (defaults to signed, but always specify signed/unsigned anyway)
58 * int 16 bit DO NOT USE! (current compile flags make this 16 bits, but a change of flags could will change your program if you use this because they will all be 32 bit all of a sudden)
59 * long 32 bit (defaults to signed, but always specify signed/unsigned anyway)
60 * long long 64 bit (inefficient, avoid these, if using : defaults to signed, but always specify signed/unsigned anyway)
61 * float 32 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math)
62 * double 64 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math)
66 // TODO various new structs
70 // Engine position struct
71 // Validity flags, or they should be in the status struct?
75 * Addressable memory block description. This structure holds
76 * the size, RAM page and address and flash page and address.
77 * It is used for looking up the details of a memory block to
78 * allow serial operations on RAM and flash data structures.
81 unsigned char RAMPage
;
82 unsigned char FlashPage
;
89 #define DERIVED_VARS_SIZE sizeof(DerivedVar)
90 #define DERIVED_VARS_WIDTH IN_OUT_BANKS /* How many elements per array currently 2 at 25/6/08 */
91 #define DERIVED_VARS_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */
92 /* Use this block to make it easy to manage the derived variables */
94 /* Calculated from core vars */
95 unsigned short LoadMain
; /* Configurable unit of load */
96 // unsigned short LoadSecondary;
98 unsigned short VEMain
; /* Divide by 512 to get % */
99 // unsigned short VESecondary;
101 unsigned short Lambda
; /* Divide by 32768 to get Lamda */
102 unsigned short AirFlow
; /* top half */
103 unsigned short densityAndFuel
; /* bottom half */
105 unsigned short BasePW
; /* In timer ticks of 0.8us */
106 unsigned short IDT
; /* 0.8us ticks */
107 unsigned short ETE
; /* 0.8us ticks */
108 signed short TFCTotal
; /* Transient fuel correction */
110 unsigned short FinalPW
; /* In timer ticks of 0.8us */
111 unsigned short RefPW
; /* In timer ticks of 0.8us */
113 unsigned short sp1
; /* */
114 unsigned short sp2
; /* */
115 unsigned short sp3
; /* */
116 unsigned short sp4
; /* */
117 unsigned short sp5
; /* */
119 // unsigned short ; /* */
123 #define RUNTIME_VARS_SIZE sizeof(RuntimeVar)
124 #define RUNTIME_VARS_LENGTH 13 /* How many runtime vars */
125 #define RUNTIME_VARS_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */
126 /* Use this block to manage the execution time of various functions loops and ISRs etc */
128 /* Engine position and RPM code runtimes */
129 unsigned short primaryInputLeadingRuntime
;
130 unsigned short primaryInputTrailingRuntime
;
131 unsigned short secondaryInputLeadingRuntime
;
132 unsigned short secondaryInputTrailingRuntime
;
134 /* Mathematics runtimes */
135 unsigned short calcsRuntime
;
136 unsigned short genCoreVarsRuntime
;
137 unsigned short genDerivedVarsRuntime
;
138 unsigned short mathTotalRuntime
;
139 unsigned short mathSumRuntime
;
141 unsigned short RTCRuntime
;
144 unsigned short mainLoopRuntime
;
145 unsigned short logSendingRuntime
;
146 unsigned short serialISRRuntime
;
150 #define ISR_LATENCY_VARS_SIZE sizeof(ISRLatencyVar)
151 #define ISR_LATENCY_VARS_LENGTH 2 /* How many latency vars */
152 #define ISR_LATENCY_VARS_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */
153 /* Use this block to manage the execution time of various functions loops and ISRs etc */
155 /* Engine position and RPM code latencies */
156 unsigned short primaryInputLatency
;
157 unsigned short secondaryInputLatency
;
159 /* Injector latencies */
160 unsigned short Injector1Latency
;
161 unsigned short Injector2Latency
;
162 unsigned short Injector3Latency
;
163 unsigned short Injector4Latency
;
164 unsigned short Injector5Latency
;
165 unsigned short Injector6Latency
;
167 unsigned short DwellLatency
;
168 unsigned short IgniteLatency
;
170 /* Not an ISR, but important none the less */
171 unsigned short mathLatency
;
172 unsigned short mathSampleTimeStamp0
;
173 unsigned short mathSampleTimeStamp1
;
177 #define CORE_VARS_SIZE sizeof(CoreVar)
178 #define CORE_VARS_LENGTH 16 /* How many arrays */
179 #define CORE_VARS_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */
180 /* Use this block to make it easy to manage the core variables */
182 /* Calculated and averaged from ADC0 readings */
183 unsigned short IAT
; /* Inlet Air Temperature (MAT JS) : 0.0 - 655.35 (0.01 Kelvin (/100)) */
184 unsigned short CHT
; /* Coolant / Head Temperature (CLT JS) : 0.0 - 655.35 (0.01 Kelvin (/100)) */
185 unsigned short TPS
; /* Throttle Position Sensor (TPS JS) : 0.0 - 102.39 (0.001? % (/640)) */
186 unsigned short EGO
; /* Exhaust Gas Oxygen (O2 JS) : 0.000 - 1.999999 (0.0001? lambda (/32768)) */
187 unsigned short MAP
; /* Manifold Absolute Pressure (5euroh1) : 0.0 - 655.35 (0.01 kPa (/100)) */
188 unsigned short AAP
; /* Atmospheric Absolute Pressure (6euroh1) : 0.0 - 655.35 (0.01 kPa (/100)) */
189 unsigned short BRV
; /* Battery Reference Voltage (4euroh1) : 0.000 - 65.535 (0.001 Volts (/1000)) */
190 unsigned short MAT
; /* Manifold Air Temperature (Spare JS) : 0.0 - 655.35 (0.01 Kelvin (/100)) */
192 /* Calculated and averaged from ADC1 readings */
193 unsigned short EGO2
; /* Exhaust Gas Oxygen (NC) : 0.000 - 1.999999 (0.0001? lambda (/32768)) */
194 unsigned short IAP
; /* Intercooler Absolute Pressure (NC) : 0.0 - 655.35 (0.01 kPa (/100)) */
195 unsigned short MAF
; /* Mass Air Flow : 0.0 - 65535.0 (raw units from lookup) */
197 /* Calculated from MAP and TPS history */
198 unsigned short DMAP
; /* Delta MAP kPa/second or similar */
199 unsigned short DTPS
; /* Delta TPS %/second or similar */
201 /* Calculated from engine position data */
202 unsigned short RPM
; /* Revolutions Per Minute (Calced) : 0 - 32767.5 (0.5 RPM (/2)) */
203 unsigned short DRPM
; /* Delta RPM (Calced) : 0 - 32767.5 (0.5 RPM/Second (/2)) */
204 unsigned short DDRPM
; /* Delta Delta RPM (Calced) : 0 - 32767.5 (0.5 RPM/Second^2 (/2)) */
208 #define ADC_ARRAY_SIZE sizeof(ADCArray)
209 #define ADC_ARRAY_LENGTH 16 /* How many arrays */
210 #define ADC_ARRAY_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */
211 /* Use this block to ensure that the components are contiguous and we can then reference them via offsets and pointers */
213 /* ADC0 raw readings */
214 unsigned short IAT
; /* Inlet Air Temperature (MAT JS) */ /* COMPULSORY! */
215 unsigned short CHT
; /* Coolant / Head Temperature (CLT JS) */ /* COMPULSORY! */
216 unsigned short TPS
; /* Throttle Position Sensor (TPS JS) */ /* Reduced performance without */
217 unsigned short EGO
; /* Exhaust Gas Oxygen (O2 JS) */ /* Recommended */
218 unsigned short BRV
; /* Battery Reference Voltage (4euroh1) */ /* COMPULSORY! */
219 unsigned short MAP
; /* Manifold Absolute Pressure (5euroh1) */ /* COMPULSORY OR TPS OR MAF */
220 unsigned short AAP
; /* Atmospheric Absolute Pressure (6euroh1) */ /* Recommended */
221 unsigned short MAT
; /* Manifold Air Temperature (Spare JS) */ /* Could help heat soak issues */
223 /* ADC1 raw readings */
224 unsigned short EGO2
; /* Exhaust Gas Oxygen (NC) */ /* V engine option */
225 unsigned short IAP
; /* Intercooler Absolute Pressure (NC) */ /* Turbo engine option */
226 unsigned short MAF
; /* Mass Air Flow (NC) */ /* OEM engine option */
227 unsigned short SpareADC3
; /* Spare ADC1 port 3 (NC) */
228 unsigned short SpareADC4
; /* Spare ADC1 port 4 (NC) */
229 unsigned short SpareADC5
; /* Spare ADC1 port 5 (NC) */
230 unsigned short SpareADC6
; /* Spare ADC1 port 6 (NC) */
231 unsigned short SpareADC7
; /* Spare ADC1 port 7 (NC) */
235 #define MAINTABLE_SIZE sizeof(mainTable)
236 #define MAINTABLE_RPM_LENGTH 24 /* How many cells on the X axis */
237 #define MAINTABLE_LOAD_LENGTH 19 /* How many cells on the Y axis */
238 #define MAINTABLE_MAX_RPM_LENGTH 27 /* How many cells on the X axis max */
239 #define MAINTABLE_MAX_LOAD_LENGTH 21 /* How many cells on the Y axis max */
240 #define MAINTABLE_MAX_MAIN_LENGTH 462 /* 924B 462 shorts maximum main table length */
241 /* Main Table Structure definition */
242 /* Use this block to manage the main VE, Lambda and Timing tables. *
243 * Tables can be made any size from 1x1 to 27x17 or 22x21 provided *
244 * that the multiple of the two doesn't exceed the max main length *
245 * and neither axis exceeds it's specified maximum. */
247 unsigned short RPMLength
; /* The length of the RPM axis array */
248 unsigned short LoadLength
; /* The length of the Load axis array */
249 unsigned short RPM
[MAINTABLE_MAX_RPM_LENGTH
]; /* The array of RPM (X) axis values */
250 unsigned short Load
[MAINTABLE_MAX_LOAD_LENGTH
]; /* The array of Load (Y) axis values */
251 unsigned short Table
[MAINTABLE_MAX_MAIN_LENGTH
]; /* The table as an array of values */
255 #define TWODTABLEUS_SIZE sizeof(twoDTableUS)
256 #define TWODTABLEUS_LENGTH 16
257 /* This block used for various curves */
259 unsigned short Axis
[TWODTABLEUS_LENGTH
];
260 unsigned short Values
[TWODTABLEUS_LENGTH
];
264 #define TWODTABLESS_SIZE sizeof(twoDTableSS)
265 #define TWODTABLESS_LENGTH 16
266 /* This block used for various curves */
268 signed short Axis
[TWODTABLESS_LENGTH
];
269 signed short Values
[TWODTABLESS_LENGTH
];
273 #define TWODTABLEMS_SIZE sizeof(twoDTableMS)
274 #define TWODTABLEMS_LENGTH 16
275 /* This block used for various curves */
277 unsigned short Axis
[TWODTABLEMS_LENGTH
];
278 signed short Values
[TWODTABLEMS_LENGTH
];
282 #define TWODTABLEUC_SIZE sizeof(twoDTableUC)
283 #define TWODTABLEUC_LENGTH 8
284 /* This block used for various curves */
286 unsigned char Axis
[TWODTABLEUC_LENGTH
];
287 unsigned char Values
[TWODTABLEUC_LENGTH
];
291 #define COUNTER_SIZE sizeof(Counter)
292 #define COUNTER_LENGTH 21 /* How many counters */
293 #define COUNTER_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */
294 /* Use this block to manage the execution count of various functions loops and ISRs etc */
296 /* Event Counters (all require init to zero) */
297 unsigned short callsToUISRs
; /* Counter to ensure we aren't accidentally triggering unused ISRs */
298 unsigned short lowVoltageConditions
; /* Counter for low voltage conditions */
300 unsigned short crankSyncLosses
; /* Counter for number of lost crank syncs */
301 unsigned short camSyncLosses
; /* Counter for number of lost cam syncs */
302 unsigned short RPMValidityLosses
; /* Counter for number of lost RPM validity events */
303 unsigned short primaryTeethDroppedFromLackOfSync
; /* Counter for number of primary teeth dropped due to no primary sync */
304 // TODO remove the one above this line about teeth dropped???? probably...
306 unsigned short primaryTeethSeen
; /* Free running counters for number of teeth seen such that... */
307 unsigned short secondaryTeethSeen
; /* ...tooth timing can be used to reconstruct the signal at lower rpm */
309 unsigned short syncedADCreadings
; /* Incremented each time a syncronous ADC reading is taken */
310 unsigned short timeoutADCreadings
; /* Incremented for each ADC reading in RTC because of timeout */
312 unsigned short calculationsPerformed
; /* Incremented for each time the fuel and ign calcs are done */
313 unsigned short datalogsSent
; /* Incremented for each time we send out a log entry */
315 /* UART/serial specific counters */
316 unsigned short serialStartsInsideAPacket
; /* Incremented when a start byte is found inside a packet */
317 unsigned short serialEscapePairMismatches
; /* Incremented when an escape is found but not followed by an escapee */
318 unsigned short serialPacketsOverLength
; /* Incremented when the buffer fills up before the end */
319 unsigned short serialNoiseErrors
; /* Incremented when noise is detected */
320 unsigned short serialOverrunErrors
; /* Incremented when an overrun occurs */
321 unsigned short serialFramingErrors
; /* Incremented when a framing error occurs */
322 unsigned short serialParityErrors
; /* Incremented when a parity error occurs */
324 /* Generic com counters */
325 unsigned short commsChecksumMismatches
; /* Incremented when calculated checksum did not match the received one */
326 unsigned short commsDebugMessagesNotSent
; /* Incremented when a debug message can't be sent due to the TX buffer */
327 unsigned short commsErrorMessagesNotSent
; /* Incremented when an error message can't be sent due to the TX buffer */
331 #define CLOCK_SIZE sizeof(Clock)
332 #define CLOCK_LENGTH 9 /* How many clocks */
333 #define CLOCK_UNIT 2 /* How large each element is in bytes (short = 2 bytes) */
334 /* Use this block to manage the various clocks kept */
336 /* Real Time and other Clocks (all require init to zero) */
337 unsigned short realTimeClockMain
; /* Variable to count RTI executions, 0.125ms exactly */
338 unsigned short realTimeClockMillis
; /* Variable to count milliseconds exactly */
339 unsigned short realTimeClockTenths
; /* Variable to count tenths of a second exactly */
340 unsigned short realTimeClockSeconds
; /* Variable to count seconds exactly */
341 unsigned short realTimeClockMinutes
; /* Variable to count minutes exactly */
343 unsigned short millisToTenths
; /* Rollover variable for counting tenths */
344 unsigned short tenthsToSeconds
; /* Rollover variable for counting seconds */
345 unsigned short secondsToMinutes
; /* Rollover variable for counting minutes */
347 unsigned short timeoutADCreadingClock
; /* Timeout clock/counter for synced ADC readings */
352 /* let us know if we are being untidy with headers */
353 #warning "Header file STRUCTS_H seen before, sort it out!"
354 /* end of the wrapper ifdef from the very top */