Closes issue #180 by exposing the last thing that I currently know about that should...
[freeems-vanilla.git] / src / inc / FixedConfigs.h
blob05e0eb5d81531cfdb4d592828d9c6f02101c4075
1 /* FreeEMS - the open source engine management system
3 * Copyright 2008-2012 Fred Cooke
5 * This file is part of the FreeEMS project.
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.
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.
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/
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!
23 * Thank you for choosing FreeEMS to run your engine!
27 /** @file
29 * @ingroup allHeaders
30 * @ingroup globalHeaders
31 * @ingroup dataStructures
33 * @brief Struct typedefs for fixed configuration
35 * This file contains the struct data type definitions for fixed configuration items.
37 * Fixed, in this context means that it typically is not tuned in a live way
38 * and therefore should not be cached in RAM while running. Usually these are
39 * values that do not change such as cylinder volume, injector size, cylinder
40 * count and other constants related to physical aspects of the engine setup.
41 * When adding configuration values, please consider adding them here first.
42 * If a value doesn't need to be live tunable definitely put it here instead.
46 /* Header file multiple inclusion protection courtesy eclipse Header Template */
47 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */
48 #ifndef FILE_FIXED_CONFIGS_H_SEEN
49 #define FILE_FIXED_CONFIGS_H_SEEN
52 /// Decoder and scheduling settings
53 typedef struct {
54 unsigned short accelerationInputEventTimeTolerance; ///< This will be replaced: http://issues.freeems.org/view.php?id=118
55 unsigned short decelerationInputEventTimeTolerance; ///< This will be replaced: http://issues.freeems.org/view.php?id=118
56 unsigned short missingToothTolerance; ///< The future of this variable is uncertain!
57 } decoderSetting;
60 #define SOURCE_NORMAL 0
61 #define SOURCE_PRESET 1
62 #define SOURCE_LINEAR 2 ///< Read from the normal ADC pin, but process linearly. For bench use, mainly.
64 /**
65 * Configuration that controls how the values of variables are determined.
67 typedef struct {
68 unsigned char BRV;
69 unsigned char CHT;
70 unsigned char IAT;
71 } sensorSource;
74 /** @brief Preset values for inputs and other variables
76 * In some cases you may want to ignore input readings and just use some
77 * configured value for a particular sensor. These are the values used when you
78 * choose to use a fixed reading instead of the real thing.
80 typedef struct {
81 unsigned short presetIAT; ///< Preset variable value to override calculated values.
82 unsigned short presetCHT; ///< @copydoc presetIAT
83 unsigned short presetBRV; ///< @copydoc presetIAT
85 unsigned short failsafeIATIgnition; ///< Value to fall back on if a sensor fault is detected
86 unsigned short failsafeIATInjection; ///< @copydoc failsafeIATIgnition
87 unsigned short failsafeCHT; ///< @copydoc failsafeIATIgnition
88 unsigned short failsafeBRV; ///< @copydoc failsafeIATIgnition
89 unsigned short failsafeMAP; ///< @copydoc failsafeIATIgnition
90 unsigned short failsafeAAP; ///< @copydoc failsafeIATIgnition
91 unsigned short failsafeTPS; ///< @copydoc failsafeIATIgnition
92 } sensorPreset;
95 /// Ranges for sensors with linear config
96 typedef struct {
97 signed short MAPMinimum; ///< Vacuum required to make the sensor reach 0 Volt output. Theoretical only, most do not rail.
98 unsigned short MAPRange; ///< Number of kPa between 0 Volts and 5 Volts.
99 unsigned short AAPMinimum; ///< @copydoc MAPMinimum
100 unsigned short AAPRange; ///< @copydoc MAPRange
101 unsigned short EGOMinimum; ///< Lambda that 0 Volt input corresponds to.
102 unsigned short EGORange; ///< Lambda difference between what 0V and 5V inputs correspond to.
103 unsigned short BRVMinimum; ///< Battery Voltage that 0 Volt input means. 0 Volts usually. TODO YAGNI usually? always? what/why?
104 unsigned short BRVRange; ///< TODO reword when above is fixed. Real world voltage difference between lowest and highest ADC reading (0 to 5V). FreeEMS standard is 24.5 Volts for 1k and 3k9 resistors on a 12v vehicle.
105 unsigned short TPSMinimumADC; ///< This should be zero, but often isn't, this value is what the TPS input reads with the throttle fully closed.
106 unsigned short TPSMaximumADC; ///< This should be the maximum ADC value, but often isn't. This value is what the TPS input reads with the throttle fully open.
107 } sensorRange;
110 /// Fuel injection settings
111 typedef struct {
112 unsigned short perCylinderVolume; ///< 500cc = 0.5l 0.5 * 32768 = pcv, so divide by 32768 go get litres */
113 unsigned short injectorFlow; ///< Injector flow of 240cc/min / 60 is 4ml/second is multiplied by 1024, so divide by 1024 for ml/second, divide by 1000 for litres/second */
114 unsigned short stoichiometricAFR; ///< 34 for hydrogen, all others less, figure is 14.7 * 1024, divide by 1024 to get AFR */
115 unsigned short densityOfFuelAtSTP; ///< 703gm/litre for Octane. 32 * fuel density = number, divide by 32 for the real figure */
116 } engineSetting;
119 /// Settings related to serial communications
120 typedef struct {
121 unsigned short baudDivisor; ///< The number used to set the data rate. 22 = (40MHz / (16*115.2kHz)) = 21.7013889
122 } serialSetting;
125 /// Settings for coarse bit bang outputs
126 typedef struct {
127 unsigned char outputActions[256]; ///< Nothing, On, Off, Toggle for each input event.
128 unsigned char* ports[4]; ///< The addresses of the port control registers.
129 unsigned char masks[4]; ///< The masks to apply to the ports above.
130 unsigned char numberConfigured; ///< How many to loop through, max of 4
131 } coarseBitBangSetting;
134 /// Settings for ignition and injection output scheduling
135 typedef struct {
136 unsigned short anglesOfTDC[MAX_NUMBER_OF_OUTPUT_EVENTS]; ///< The effective TDC angle of the event in question.
137 unsigned char outputEventPinNumbers[MAX_NUMBER_OF_OUTPUT_EVENTS]; ///< Which of the 6 pins should be associated with this event
138 unsigned char schedulingConfigurationBits[MAX_NUMBER_OF_OUTPUT_EVENTS]; ///< 0 = ignition, 1 = injection
139 unsigned short decoderEngineOffset;
140 /**<
141 * Add decoderEngineOffset to code degrees to find 0/TDC for cyl/output 1
142 * or subtract from real degrees to get code degrees. Make this number
143 * larger to advance the base timing, make it smaller to retard it. IE, if
144 * you have 10btdc in your table, flat, and a timing light shows 5btdc on
145 * the engine, then increase this number by 5 degrees. More here:
147 * http://forum.diyefi.org/viewtopic.php?f=54&t=1523
149 unsigned char numberOfConfiguredOutputEvents; ///< Should match the used section of the three arrays above
150 unsigned char numberOfInjectionsPerEngineCycle; ///< How much to divide the fuel pulse width by to get the per injection fuel pulse width
151 } schedulingSetting;
154 /// Enable flags for each cut
155 typedef struct {
156 unsigned InjectionRPM :1; ///< @todo document this
157 unsigned IgnitionRPM :1; ///< @todo document this
158 unsigned InjOverBoost :1; ///< @todo document this
159 unsigned IgnOverBoost :1; ///< @todo document this
160 unsigned Spare0 :1;
161 unsigned Spare1 :1;
162 unsigned Spare2 :1;
163 unsigned Spare3 :1;
164 unsigned Spare4 :1;
165 unsigned Spare5 :1;
166 unsigned Spare6 :1;
167 unsigned Spare7 :1;
168 unsigned Spare8 :1;
169 unsigned Spare9 :1;
170 unsigned SpareA :1;
171 unsigned SpareB :1;
172 } cutEnabled;
175 /// Single cut/limiter
176 typedef struct {
177 unsigned short disableThreshold; ///< Level at which to disable outputs
178 unsigned short reenableThreshold; ///< Level at which to re-enable outputs
179 } singleCut;
182 /// Cuts and limiters
183 typedef struct { // Comment represents normal and recommended cut type
184 singleCut InjectionRPM; ///< Injection, enabled by default at 5k with both and 200 RPM hysteresis
185 singleCut IgnitionRPM; ///< Ignition, enabled by default at 5k with both and 220 RPM hysteresis to ensure not lean when power comes back on
186 singleCut OverBoost; ///< Ignition, enabled by default, set to rail value for sensor, with large hysteresis, requires time out to operate safely
188 // Disabled by default until duties are available, then enabled and fuel duty hard coded, elec duty optional, re enabled by time out not just hysteresis
189 // singleCut InjectionFuelDuty; ///< Both, disabled by default, until duties are available
190 // singleCut InjectionElecDuty; ///< Both, disabled by default, until duties are available
192 // These require other logic in addition to the generic logic:
193 // singleCut TwoStep; ///< Ignition only or both, disabled by default
194 // singleCut OverHeat; ///< Ignition only or both, disabled by default
195 // singleCut Overrun; ///< Injection, disabled by default
196 // singleCut FloodClear; ///< Injection, disabled by default
197 cutEnabled cutsEnabled; ///< Override hard code on for desired fuel duty not to exceed 102.4% or similar
198 } cutAndLimiterSetting;
201 typedef struct {
202 unsigned short* variable;
203 unsigned short upperValue;
204 unsigned short lowerValue;
205 unsigned char* port;
206 unsigned char mask;
207 unsigned char flags; // for go high or low on success.
208 } singleSimpleGPOutput;
211 #define NUMBER_OF_OUTPUT_CONFIGS 8
212 typedef struct {
213 singleSimpleGPOutput outputConfigs[NUMBER_OF_OUTPUT_CONFIGS];
214 unsigned char numberConfigured;
215 unsigned char spare;
216 } simpleGPIOSetting;
219 /// Settings related to sensor reading
220 typedef struct {
221 unsigned short readingTimeout; ///< How often an ADC reading MUST occur.
222 unsigned char numberOfADCsToRead;
223 unsigned char spare8bitConfig;
224 } sensorSetting;
227 #define LOAD_MAP 0
228 #define LOAD_TPS 1
229 #define LOAD_MAF 2
230 #define LOAD_AAP 3
232 #define ALGO_SPEED_DENSITY 0
233 #define ALGO_ALPHA_N 1
234 #define ALGO_MAF 2
236 #define DWELL_BRV 0
237 #define DWELL_RPM 1
238 #define DWELL_FIXED 2
240 /// Settings for fueling algorithms
241 typedef struct {
242 unsigned char loadType;
243 unsigned char algorithmType;
244 unsigned char dwellType;
245 unsigned char padding;
246 unsigned short dwellFixedPeriod;
247 } algorithmSetting;
250 /// Input output pin usage configuration @todo TODO document this better
251 typedef struct {
252 // unsigned char PullUpEnable; ///< Enables per-port weak (~100k) internal pullups. See section 22.3.2.11 on page 834 of MC9S12XDP512RMV2.pdf
253 // unsigned char ReducedDrive; ///< Do NOT change this! This reduces drive strength and could harm your engine. See section 22.3.2.12 on page 835 of MC9S12XDP512RMV2.pdf
254 unsigned char PWMEnable; ///< Enables the PWM functionality for each pin. Note for 16 bit you the low order bit enabled. See section 8.3.2.1 on page 368 of MC9S12XDP512RMV2.pdf
255 unsigned char PWMPolarity; ///< Inverts the duty of the output. 1 means "duty is high portion", 0 means "duty is low portion". See section 8.3.2.2 on page 370 of MC9S12XDP512RMV2.pdf
256 unsigned char PWMClock; ///< TODO abstract this away
257 unsigned char PWMClockPrescaler; ///< TODO abstract this away
258 unsigned char PWMCenterAlign; ///< See section 8.3.2.5 on page 372 of MC9S12XDP512RMV2.pdf
259 unsigned char PWMControl; ///< The high four bits concatenate the 8 bit PWM channels into 4 16 bit channels on a pair by pair basis. 4 joins (0,1), 5 joins (2,3), 6 joins (4,5), 7 joins (6,7).
260 unsigned char PWMScalerA; ///< TODO abstract this away
261 unsigned char PWMScalerB; ///< TODO abstract this away
263 unsigned char PWMPeriod0; ///< TODO abstract this away
264 unsigned char PWMPeriod1; ///< TODO abstract this away
265 unsigned char PWMPeriod2; ///< TODO abstract this away
266 unsigned char PWMPeriod3; ///< TODO abstract this away
267 unsigned char PWMPeriod4; ///< TODO abstract this away
268 unsigned char PWMPeriod5; ///< TODO abstract this away
269 unsigned char PWMPeriod6; ///< TODO abstract this away
270 unsigned char PWMPeriod7; ///< TODO abstract this away
272 unsigned char PWMInitialDuty0; ///< The duty cycle at power up. Usually unimportant due to being overwritten by the algorithm involved milliseconds later.
273 unsigned char PWMInitialDuty1; ///< The duty cycle at power up. Usually unimportant due to being overwritten by the algorithm involved milliseconds later.
274 unsigned char PWMInitialDuty2; ///< The duty cycle at power up. Usually unimportant due to being overwritten by the algorithm involved milliseconds later.
275 unsigned char PWMInitialDuty3; ///< The duty cycle at power up. Usually unimportant due to being overwritten by the algorithm involved milliseconds later.
276 unsigned char PWMInitialDuty4; ///< The duty cycle at power up. Usually unimportant due to being overwritten by the algorithm involved milliseconds later.
277 unsigned char PWMInitialDuty5; ///< The duty cycle at power up. Usually unimportant due to being overwritten by the algorithm involved milliseconds later.
278 unsigned char PWMInitialDuty6; ///< The duty cycle at power up. Usually unimportant due to being overwritten by the algorithm involved milliseconds later.
279 unsigned char PWMInitialDuty7; ///< The duty cycle at power up. Usually unimportant due to being overwritten by the algorithm involved milliseconds later.
281 unsigned char PortInitialValueA; ///< The state of the port at power up. @see PortDirectionA
282 unsigned char PortInitialValueB; ///< The state of the port at power up. @see PortDirectionB
283 unsigned char PortInitialValueC; ///< The state of the port at power up. @see PortDirectionC
284 unsigned char PortInitialValueD; ///< The state of the port at power up. @see PortDirectionD
285 unsigned char PortInitialValueE; ///< The state of the port at power up. @see PortDirectionE
286 unsigned char PortInitialValueH; ///< The state of the port at power up. @see PortDirectionH
287 unsigned char PortInitialValueJ; ///< The state of the port at power up. @see PortDirectionJ
288 unsigned char PortInitialValueK; ///< The state of the port at power up. @see PortDirectionK
289 unsigned char PortInitialValueM; ///< The state of the port at power up. @see PortDirectionM
290 unsigned char PortInitialValueP; ///< The state of the port at power up. @see PortDirectionP
291 unsigned char PortInitialValueS; ///< The state of the port at power up. @see PortDirectionS
292 unsigned char PortInitialValueT; ///< The state of the port at power up. @see PortDirectionT Currently this setting is ignored. TODO Make it take effect on unused port T pins.
294 unsigned char PortDirectionA; ///< @see PortDirectionB Pin 6 is the Firmware Load switch input AND the Check Engine Light output. Pin 7 is the standard fuel pump relay drive pin. These bits are therefore overridden and have no effect.
295 unsigned char PortDirectionB; ///< Whether pins act as inputs or outputs, 1 means output, 0 means input. 0 is the default for most pins. Note, peripheral modules which use these pins override this control.
296 unsigned char PortDirectionC; ///< @see PortDirectionB
297 unsigned char PortDirectionD; ///< @see PortDirectionB
298 unsigned char PortDirectionE; ///< @see PortDirectionB This port is associated with various control bits. Extreme care should be taken when using them, regardless of what for. Pins 0 and 1 are always inputs regardless of this setting.
299 unsigned char PortDirectionH; ///< @see PortDirectionB This port is associated with the SPI1 (0-3), SPI2 (4-7), SCI4 (4,5), and SCI5 (6,7) modules.
300 unsigned char PortDirectionJ; ///< @see PortDirectionB This port is associated with the SCI2 (0,1), I2C0 (6,7), I2C1 (4,5), and CAN4 (6,7) modules.
301 unsigned char PortDirectionK; ///< @see PortDirectionB
302 unsigned char PortDirectionM; ///< @see PortDirectionB This port is associated with the CAN0 (0,1), CAN1 (2,3), CAN2 (4,5), CAN3 (6,7), and SCI3 (6,7) modules.
303 unsigned char PortDirectionP; ///< @see PortDirectionB This port is associated with the PWM (0-7) module.
304 unsigned char PortDirectionS; ///< @see PortDirectionB This port is associated with the SCI0 (0,1), SCI1 (2,3), and SPI0 (4-7) modules. Primary communication is over SCI0, therefore the control bits for those pins are overridden to ensure correct operation, and have no effect.
305 unsigned char PortDirectionT; ///< @see PortDirectionB This port is associated with the ECT (0-7) module. Currently this setting is ignored. TODO Make it take effect on unused port T pins.
306 } inputOutputSetting;
309 #define userTextFieldArrayLength1 (flashSectorSize - (sizeof(engineSetting) + sizeof(serialSetting) + sizeof(coarseBitBangSetting) + sizeof(schedulingSetting) + sizeof(cutAndLimiterSetting) + sizeof(simpleGPIOSetting)))
311 * One of two structs of fixed configuration data such as physical parameters etc.
313 * If you add something here, please ensure you update all of the following :
314 * - Default values in the initial definitions in FixedConfig1.c and FixedConfig2.c
315 * - The lookupBlockDetails() function in blockDetailsLookup.c
316 * - The JSON data map and other related firmware interface definition files
318 typedef struct {
319 engineSetting engineSettings; ///< @see engineSetting
320 serialSetting serialSettings; ///< @see serialSetting
321 coarseBitBangSetting coarseBitBangSettings; ///< @see coarseBitBangSetting
322 schedulingSetting schedulingSettings; ///< @see schedulingSetting
323 cutAndLimiterSetting cutAndLimiterSettings; ///< @see cutAndLimiterSetting
324 simpleGPIOSetting simpleGPIOSettings; ///< @see simpleGPIOSetting
325 unsigned char userTextField[userTextFieldArrayLength1]; ///< For on-board meta-data such as which vehicle the unit is from, put your personal tuning notes here!
326 } fixedConfig1;
329 #define userTextFieldArrayLength2 (flashSectorSize - (sizeof(sensorSource) + sizeof(sensorPreset) + sizeof(sensorRange) + sizeof(sensorSetting) + sizeof(algorithmSetting) + sizeof(inputOutputSetting) + sizeof(decoderSetting)))
330 /** @copydoc fixedConfig1 */
331 typedef struct {
332 sensorSource sensorSources; ///< @see sensorSource
333 sensorPreset sensorPresets; ///< @see sensorPreset
334 sensorRange sensorRanges; ///< @see sensorRange
335 sensorSetting sensorSettings; ///< @see sensorSetting
336 algorithmSetting algorithmSettings; ///< @see algorithmSetting
337 inputOutputSetting inputOutputSettings; ///< @see inputOutputSetting
338 decoderSetting decoderSettings; ///< @see decoderSetting
339 unsigned char userTextField2[userTextFieldArrayLength2]; ///< For on-board meta-data such as which vehicle the unit is from, put your personal tuning notes here!
340 } fixedConfig2;
343 #else
344 /* let us know if we are being untidy with headers */
345 #warning "Header file FIXED_CONFIGS_H seen before, sort it out!"
346 /* end of the wrapper ifdef from the very top */
347 #endif