FreeEMS  0.2.0-SNAPSHOT-282-g9efc524
containerTypes.h
Go to the documentation of this file.
1 /* FreeEMS - the open source engine management system
2  *
3  * Copyright 2008-2013 Fred Cooke
4  *
5  * This file is part of the FreeEMS project.
6  *
7  * FreeEMS software is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * FreeEMS software is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with any FreeEMS software. If not, see http://www.gnu.org/licenses/
19  *
20  * We ask that if you make any changes to this file you email them upstream to
21  * us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
22  *
23  * Thank you for choosing FreeEMS to run your engine!
24  */
25 
26 
27 /** @file
28  *
29  * @ingroup allHeaders
30  * @ingroup globalHeaders
31  * @ingroup dataStructures
32  *
33  * @brief Container struct typedefs
34  *
35  * This file contains all of the data container struct typedefs used for calculations.
36  */
37 
38 
39 /* Header file multiple inclusion protection courtesy eclipse Header Template */
40 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */
41 #ifndef FILE_CONTAINER_TYPES_H_SEEN
42 #define FILE_CONTAINER_TYPES_H_SEEN
43 
44 
45 /** Use this block to ensure that the components are contiguous and we can then reference
46  * them via offsets and pointers (NC= Not (likely) connected).
47  */
48 typedef struct {
49  /* ADC0 raw readings */
50  unsigned short IAT; ///< Inlet Air Temperature
51  unsigned short CHT; ///< Coolant / Head Temperature
52  unsigned short TPS; ///< Throttle Position Sensor
53  unsigned short EGO; ///< Exhaust Gas Oxygen
54  unsigned short MAP; ///< Manifold Absolute Pressure
55  unsigned short AAP; ///< Atmospheric Absolute Pressure
56  unsigned short BRV; ///< Battery Reference Voltage
57  unsigned short MAT; ///< Manifold Air Temperature
58 
59  /* ADC1 raw readings (Subject to change! http://issues.freeems.org/view.php?id=190) */
60  unsigned short EGO2; ///< Exhaust Gas Oxygen
61  unsigned short IAP; ///< Intercooler Absolute Pressure
62  unsigned short MAF; ///< Mass Air Flow
63  unsigned short SpareADC3; ///< Spare ADC1 port 3
64  unsigned short SpareADC4; ///< Spare ADC1 port 4
65  unsigned short SpareADC5; ///< Spare ADC1 port 5
66  unsigned short SpareADC6; ///< Spare ADC1 port 6
67  unsigned short SpareADC7; ///< Spare ADC1 port 7
68 } ADCBuffer;
69 
70 
71 /// Use this block to make it easy to manage the core variables.
72 typedef struct {
73  /* Calculated and averaged from ADC0 readings */
74  unsigned short IAT; ///< Inlet Air Temperature : 0.0 - 655.35 (0.01 Kelvin (/100))
75  unsigned short CHT; ///< Coolant / Head Temperature : 0.0 - 655.35 (0.01 Kelvin (/100))
76  unsigned short TPS; ///< Throttle Position Sensor : 0.0 - 102.398438 (0.0015625 % (/640))
77  unsigned short EGO; ///< Exhaust Gas Oxygen : 0.0 - 1.99996948 (0.0000305175781 lambda (/32768))
78  unsigned short MAP; ///< Manifold Absolute Pressure : 0.0 - 655.35 (0.01 kPa (/100))
79  unsigned short AAP; ///< Atmospheric Absolute Pressure : 0.0 - 655.35 (0.01 kPa (/100))
80  unsigned short BRV; ///< Battery Reference Voltage : 0.0 - 65.535 (0.001 Volts (/1000))
81  unsigned short MAT; ///< Manifold Air Temperature : 0.0 - 655.35 (0.01 Kelvin (/100))
82 
83  /* Calculated and averaged from ADC1 readings (Subject to change! http://issues.freeems.org/view.php?id=190) */
84  unsigned short EGO2; ///< Exhaust Gas Oxygen : 0.0 - 1.99996948 (0.0000305175781 lambda (/32768))
85  unsigned short IAP; ///< Intercooler Absolute Pressure : 0.0 - 655.35 (0.01 kPa (/100))
86  unsigned short MAF; ///< Mass Air Flow : 0.0 - 65535.0 (raw units from lookup)
87 
88  /* Calculated from MAP and TPS history */
89  unsigned short DMAP; ///< Delta MAP kPa/second or similar
90  unsigned short DTPS; ///< Delta TPS %/second or similar
91 
92  /* Calculated from engine position data */
93  unsigned short RPM; ///< Revolutions Per Minute (Calced) : 0.0 - 32767.5 (0.5 RPM (/2))
94  unsigned short DRPM; ///< Delta RPM (Calced) : 0.0 - 32767.5 (0.5 RPM/Second (/2))
95  unsigned short DDRPM; ///< Delta Delta RPM (Calced) : 0.0 - 32767.5 (0.5 RPM/Second^2 (/2))
96 } CoreVar;
97 
98 
99 /** Use this block to make it easy to manage the derived variables.
100  * Calculated from core vars stored in CoreVar .
101  */
102 typedef struct {
103  /* */
104  unsigned short LoadMain; ///< Configurable unit of load, same scale as VE by default
105  unsigned short VEMain; ///< Divide by 512 to get 0 - 128%
106  unsigned short Lambda; ///< Divide by 32768 to get Lamda 0 - 2.0
107 
108  // TODO remove these:
109  unsigned short AirFlow; ///< Top half of the equation - intermediate, take this out of derived vars into own special struct with other intermediates
110  unsigned short densityAndFuel; ///< Bottom half of the equation - ditto, or, just ditch. This is dev/debug code, really...
111 
112  unsigned short BasePW; ///< Raw PW before corrections divide by PW_TICK_FACTOR for milli seconds
113  unsigned short ETE; ///< Engine Temperature Enrichment percentage correction divide by 327.68 for 0 - 200%
114  signed short TFCTotal; ///< Transient fuel correction PW (+/-) divide by PW_TICK_FACTOR for milli seconds
115 
116  unsigned short EffectivePW; ///< Actual PW of fuel delivery, before per channel corrections, divide by PW_TICK_FACTOR for milli seconds
117  unsigned short IDT; ///< PW duration before fuel flow begins, before per channel corrections, divide by PW_TICK_FACTOR for milli seconds
118  unsigned short RefPW; ///< Reference electrical PW what each cylinder is based on, used for all general decisions, divide by PW_TICK_FACTOR for milli seconds
119 
120  unsigned short Advance; ///< Ignition advance (scaled degrees / ANGLE_FACTOR = degrees)
121  unsigned short Dwell; ///< Dwell period, divide by PW_TICK_FACTOR for milli seconds
122 } DerivedVar;
123 
124 
125 /// Important "always send" stuff for datalogging
126 typedef struct {
127  // To be improved MAJORLY:
128  unsigned char tempClock; ///< Incremented once per log sent
129  unsigned char spareChar; ///< Unused at this time.
130 
131  // All flags! Pair keeps things sane for hacky apps that think everything is 16 bit.
132  unsigned char coreStatusA; ///< Duplicated, migrate here, remove global var
133  unsigned char decoderFlags; ///< Various decoder state flags
134  unsigned short flaggableFlags; ///< Flags to go with our flaggables struct.
135  // counter flags once counter mechanism implemented
136 
137  // These things should only exist once in memory, and should be grouped in a struct, perhaps this one
138  unsigned char currentEvent; ///< Which input event was last to come in
139  unsigned char syncLostWithThisID; ///< A unique identifier for the reason behind a loss of sync
140  unsigned char syncLostOnThisEvent; ///< Where in the input pattern it all went very badly wrong
141  unsigned char syncCaughtOnThisEvent; ///< Where in the input pattern that things started making sense
142  unsigned char syncResetCalls; ///< Sum of sync losses and state clears
143  unsigned char primaryTeethSeen; ///< Free running counters for number of input events, useful at lower RPM
144  unsigned char secondaryTeethSeen; ///< @copydoc primaryTeethSeen
145 
146  // Likewise these too
147  unsigned char serialOverrunErrors; ///< Incremented when an overrun occurs due to high interrupt load, not a fault, just a fact of life at high RPM
148  unsigned char serialHardwareErrors; ///< Sum of noise, parity, and framing errors
149  unsigned char serialAndCommsCodeErrors; ///< Sum of checksum, escape mismatches, starts inside, and over/under length
150  unsigned short inputEventTimeTolerance; ///< Required to tune noise rejection over RPM TODO add to LT1 and MissingTeeth
151 
152  // TODO move this up above with the other flags post OLV 0.0.3 release
153  unsigned short flaggableFlags2; ///< Flags to go with our flaggables2 struct.
154 
155  // replace highest first to avoid hassles for offset based dave/mtx...
156  unsigned short zsp9; ///< Spare US variable
157  unsigned short zsp8; ///< Spare US variable
158  unsigned short zsp7; ///< Spare US variable
159  unsigned short zsp6; ///< Spare US variable
160 
161  // TODO move these:
162  unsigned short blendAlphaNPercent; ///< TODO migrate to correct place once OLV/EMStudio are flexible...
163  unsigned short speedDensityAirFlow; ///< TODO migrate to correct place once OLV/EMStudio are flexible...
164  unsigned short alphaNAirFlow; ///< TODO migrate to correct place once OLV/EMStudio are flexible...
165 
166  // Do we want these recorded at log assembly time, or at recording of ADC time, or at calculation of vars (core and/or deriv) or at enabling of scheduling, or all of the above?
167  unsigned short clockInMilliSeconds; ///< Migrate to start of all large datalogs once analysed
168  unsigned short clockIn8thsOfAMilli; ///< Migrate to start of all large datalogs once analysed
169  unsigned char ignitionCuts; ///< Up to 8 reasons to not schedule ignition
170  unsigned char injectionCuts; ///< Up to 8 reasons to not schedule injection
171 } KeyUserDebug;
172 
173 
174 /// Active flags for each injection cut
175 typedef struct { // BIT7 at the top
176  unsigned Spare7 :1;
177  unsigned Spare6 :1;
178  unsigned Spare5 :1;
179  unsigned Spare4 :1;
180  unsigned InjSelfClock :1; ///< @todo document this
181  unsigned InjLostPLL :1; ///< @todo document this
182  unsigned InjOverBoost :1; ///< @todo document this
183  unsigned InjectionRPM :1; ///< @todo document this
184 } injectionCutFlags; // BIT0 at the bottom
185 
186 
187 /// Active flags for each ignition cut
188 typedef struct { // BIT7 at the top
189  unsigned Spare7 :1;
190  unsigned Spare6 :1;
191  unsigned Spare5 :1;
192  unsigned Spare4 :1;
193  unsigned IgnSelfClock :1; ///< @todo document this
194  unsigned IgnLostPLL :1; ///< @todo document this
195  unsigned IgnOverBoost :1; ///< @todo document this
196  unsigned IgnitionRPM :1; ///< @todo document this
197 } ignitionCutFlags; // BIT0 at the bottom
198 
199 
200 #else
201  /* let us know if we are being untidy with headers */
202  #warning "Header file CONTAINER_TYPES_H seen before, sort it out!"
203 /* end of the wrapper ifdef from the very top */
204 #endif