1 /** @file globalDefines.h
3 Copyright 2008 Fred Cooke
5 Currently this holds most hash defined constants and literals.
7 @todo TODO Some investigation as to whether it is best to use consts or defines is required
8 @todo TODO Break this up into smaller chunks that are included into this file
10 This file is part of the FreeEMS project.
12 FreeEMS software is free software: you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation, either version 3 of the License, or
15 (at your option) any later version.
17 FreeEMS software is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with any FreeEMS software. If not, see http://www.gnu.org/licenses/
25 We ask that if you make any changes to this file you send them upstream to us at admin@diyefi.org
27 Thank you for choosing FreeEMS to run your engine! */
30 /* Header file multiple inclusion protection courtesy eclipse Header Template */
31 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */
32 #ifndef FILE_GLOBALDEFINES_H_SEEN
33 #define FILE_GLOBALDEFINES_H_SEEN
36 /* TODO perhaps configure various ports and pins etc to have names such that the
37 * code can stay untouched when being ported and just the header changed to suit?
38 * definitely a good idea, but we'll see what karsten says before putting time
39 * into it. something like : #define RPM_IN_MAIN IC0 etc etc
43 /* Definitions for functions used across the project */
44 /* http://www.seattlerobotics.org/encoder/200109/encoder.htm section Assembly */
45 #define INLINE_ASSEMBLY(code) __asm__ __volatile__ (code)
46 #define ALWAYS_INLINE __attribute__((always_inline))
48 /* Common macro definitions across the project */
51 #define TRUE !FALSE /* http://c2.com/cgi/wiki?CeePreprocessorStatements */
58 #define ZEROS16 0x0000
61 /* Halves and Maxes */
62 #define LONGHALF 0x80000000 /* 2147483648 */
63 #define LONGMAX 0xFFFFFFFF /* 4294967295*/
64 #define SHORTHALF 0x8000 /* 32768 */
65 #define SHORTMAX 0xFFFF /* 65535 */
67 /* Individual bits WARNING, do not not these for notted versions, use the notted ones below instead : http://supp.iar.com/Support/?note=12582&from=search+result */
68 #define BIT0 0x01 /* 1st bit = 1 */
69 #define BIT1 0x02 /* 2nd bit = 2 */
70 #define BIT2 0x04 /* 3rd bit = 4 */
71 #define BIT3 0x08 /* 4th bit = 8 */
72 #define BIT4 0x10 /* 5th bit = 16 */
73 #define BIT5 0x20 /* 6th bit = 32 */
74 #define BIT6 0x40 /* 7th bit = 64 */
75 #define BIT7 0x80 /* 8th bit = 128 */
77 #define BIT0_16 0x0001 /* 1st bit = 1 */
78 #define BIT1_16 0x0002 /* 2nd bit = 2 */
79 #define BIT2_16 0x0004 /* 3rd bit = 4 */
80 #define BIT3_16 0x0008 /* 4th bit = 8 */
81 #define BIT4_16 0x0010 /* 5th bit = 16 */
82 #define BIT5_16 0x0020 /* 6th bit = 32 */
83 #define BIT6_16 0x0040 /* 7th bit = 64 */
84 #define BIT7_16 0x0080 /* 8th bit = 128 */
86 #define BIT8_16 0x0100 /* 9th bit = 256 */
87 #define BIT9_16 0x0200 /* 10th bit = 512 */
88 #define BIT10_16 0x0400 /* 11th bit = 1024 */
89 #define BIT11_16 0x0800 /* 12th bit = 2048 */
90 #define BIT12_16 0x1000 /* 13th bit = 4096 */
91 #define BIT13_16 0x2000 /* 14th bit = 8192 */
92 #define BIT14_16 0x4000 /* 15th bit = 16384 */
93 #define BIT15_16 0x8000 /* 16th bit = 32768 */
95 /* Individual bits NOTTED : http://supp.iar.com/Support/?note=12582&from=search+result */
96 #define NBIT0 0xFE /* 1st bit = 1 */
97 #define NBIT1 0xFD /* 2nd bit = 2 */
98 #define NBIT2 0xFB /* 3rd bit = 4 */
99 #define NBIT3 0xF7 /* 4th bit = 8 */
100 #define NBIT4 0xEF /* 5th bit = 16 */
101 #define NBIT5 0xDF /* 6th bit = 32 */
102 #define NBIT6 0xBF /* 7th bit = 64 */
103 #define NBIT7 0x7F /* 8th bit = 128 */
105 #define NBIT0_16 0xFFFE /* 1st bit = 1 */
106 #define NBIT1_16 0xFFFD /* 2nd bit = 2 */
107 #define NBIT2_16 0xFFFB /* 3rd bit = 4 */
108 #define NBIT3_16 0xFFF7 /* 4th bit = 8 */
109 #define NBIT4_16 0xFFEF /* 5th bit = 16 */
110 #define NBIT5_16 0xFFDF /* 6th bit = 32 */
111 #define NBIT6_16 0xFFBF /* 7th bit = 64 */
112 #define NBIT7_16 0xFF7F /* 8th bit = 128 */
114 #define NBIT8_16 0xFEFF /* 9th bit = 256 */
115 #define NBIT9_16 0xFDFF /* 10th bit = 512 */
116 #define NBIT10_16 0xFBFF /* 11th bit = 1024 */
117 #define NBIT11_16 0xF7FF /* 12th bit = 2048 */
118 #define NBIT12_16 0xEFFF /* 13th bit = 4096 */
119 #define NBIT13_16 0xDFFF /* 14th bit = 8192 */
120 #define NBIT14_16 0xBFFF /* 15th bit = 16384 */
121 #define NBIT15_16 0x7FFF /* 16th bit = 32768 */
124 /* Serial Comms Stuff */
125 #define ESCAPE_BYTE 0xBB
126 #define START_BYTE 0xAA
127 #define STOP_BYTE 0xCC
128 #define ESCAPED_ESCAPE_BYTE 0x44
129 #define ESCAPED_START_BYTE 0x55
130 #define ESCAPED_STOP_BYTE 0x33
131 #define flashSectorSize 1024
132 #define flashSectorSizeInWords 512 /* 512 words to a 1k flash sector */
136 #define MAP_FACTOR 100
137 #define TPS_FACTOR 640
138 #define BRV_FACTOR 1000
139 #define TEMP_FACTOR 100
140 #define EGO_FACTOR 32768
143 #define idleManifoldPressure 3000 /* 30 kPa */
144 #define seaLevelKPa 10000 /* 100 kPa */
145 #define maxExpectedBoost 30000 /* 300 kPa */
147 #define freezingPoint 27315 /* 0 Celcius */
148 #define roomTemperature 29315 /* 20 Celcius */
149 #define runningTemperature 35815 /* 85 Celcius */
151 #define halfThrottle 32768 /* 50% throttle */
152 #define runningVoltage 14400 /* 14.4 Volts */
153 #define idlePulseWidth 2000 /* ~1.5ms */
154 #define idleAirFlow 1500 /* guessed */
156 #define typicalCylinderSize 16384 /* 500cc per cylinder */
157 #define typicalInjectorSize 9387 /* 550cc per minute */
159 #define densityOfOctane 22496 /* 703 grams per litre */
160 #define stoichiometricLambda 32768 /* Lambda = 1.0 */
162 /* Generated with http://www.diyefi.org/calculators.htm#stoich */
163 #define stoichiometricAFRMethane 17245 /* 17.245 AFR */
164 #define stoichiometricAFRPropane 15685 /* 15.685 AFR */
165 #define stoichiometricAFRLPG 15599 /* 15.599 AFR */
166 #define stoichiometricAFRButane 15469 /* 15.469 AFR */
167 #define stoichiometricAFROctane 15137 /* 15.137 AFR */
168 #define stoichiometricAFRGasoline 14700 /* 14.700 AFR */
169 #define stoichiometricAFRXylene 13681 /* 13.681 AFR */
170 #define stoichiometricAFRToluene 13512 /* 13.512 AFR */
171 #define stoichiometricAFRBenzene 13282 /* 13.282 AFR */
172 #define stoichiometricAFRE85 9862 /* 9.862 AFR */
173 #define stoichiometricAFREthanol 9008 /* 9.008 AFR */
174 #define stoichiometricAFRMethanol 6475 /* 6.475 AFR */
176 #define batteryVoltageMin 0 /* Voltage read at lowest ADC reading */
177 #define batteryVoltageRange 24500 /* Voltage difference between lowest and highest ADC reading */
179 #define LC1LambdaMin 16384 /* Lambda read at lowest ADC reading */
180 #define LC1LambdaMax 49152 /* Lambda read at highest ADC reading */
181 #define LC1LambdaRange 32768 /* Lambda difference between lowest and highest ADC reading */
183 #define AFR1020LambdaMin 16384 /* Lambda read at lowest ADC reading */
184 #define AFR1020LambdaMax 49152 /* Lambda read at highest ADC reading */
185 #define AFR1020LambdaRange 32768 /* Lambda difference between lowest and highest ADC reading */
188 /* MAP Sensor Data Explanation
190 * Motorola/Freescale pressure sensor data obtained from the
191 * data sheets by extrapolation of the "typical" line to the
192 * borders of the transfer function chart. This gives us the
193 * correct values in the middle despite not being able to
194 * reach the ends of the scale.
196 * By min and max I mean the OV and 5V pressures that aren't
197 * attainable, but that give the correct function in between.
201 /* www.freescale.com/files/sensors/doc/data_sheet/MPX4100A.pdf */
202 #define MPX4100AMin 1400 /* Pressure read at lowest ADC reading */
203 #define MPX4100AMax 10750 /* Pressure read at highest ADC reading */
204 #define MPX4100ARange 9350 /* Pressure difference between lowest and highest ADC readings */
206 /* www.freescale.com/files/sensors/doc/data_sheet/MPX4250A.pdf */
207 #define MPX4250AMin 800 /* Pressure read at lowest ADC reading */
208 #define MPX4250AMax 26000 /* Pressure read at highest ADC reading */
209 #define MPX4250ARange 25200 /* Pressure difference between lowest and highest ADC readings */
211 #define MPXH6300AMin 1200 /* Pressure read at lowest ADC reading */
212 #define MPXH6300AMax 32000 /* Pressure read at highest ADC reading */
213 #define MPXH6300ARange 30800 /* Pressure difference between lowest and highest ADC readings */
215 #define MPXH6400AMin 1200 /* Pressure read at lowest ADC reading */
216 #define MPXH6400AMax 42000 /* Pressure read at highest ADC reading */
217 #define MPXH6400ARange 40800 /* Pressure difference between lowest and highest ADC readings */
219 #define TPSDefaultMin 255 /* ADC reading at lowest throttle position */
220 #define TPSDefaultMax 767 /* ADC reading at highest throttle position */
222 #define offIdleMAP 3000 /* 30kPa just above where MAP would be with closed throttle at idle */
223 #define nearlyWOTMAP 9500 /* 95kPa just below where MAP would be at WOT */
225 #define ticksPerCycleAtOneRPMx2 300000000 /* twice how many 0.8us ticks there are in between engine cycles at 1 RPM */
226 #define ticksPerCycleAtOneRPM 150000000 /* how many 0.8us ticks there are in between engine cycles at 1 RPM */
227 #define tachoTickFactor4at50 6 /* Provides for a 4 cylinder down to 50 RPM */
228 /*efine tachoEdgesPerCycle4at50 8 / 8 events per cycle for a typical 4 cylinder tacho, 4 on, 4 off */
229 #define tachoTotalFactor4at50 48 /* http://www.google.com/search?hl=en&safe=off&q=((150000000+%2F+6)+%2F++8+)+%2F+50&btnG=Search */
230 //#define ticksForFiftyRPM 3000000 /* ticksPerCycleAtOneRPM / 50 */
232 //#define lookedUpVEDivisor 512
233 //#define VEpercentageDivisor 100
234 #define oneHundredPercentVE 51200
236 //#define densityOfFuelDivisor 32
237 //#define densityOfFuelUnitDivisor 1000
238 #define densityOfFuelTotalDivisor 32000
240 #define userTextFieldArrayLength1 966 /* Arbitrary field length to avoid wasting excess space on flash */
241 #define userTextFieldArrayLength2 1004 /* Arbitrary field length to avoid wasting excess space on flash */
242 #define divisorFor115200bps 22 /* (40MHz / (16*115.2kHz)) = 21.7013889 */
243 /* http://www.google.com/search?hl=en&safe=off&q=22%2F%28%2840000000%2F16%29%2F115200%29&btnG=Search 1.376% error in speed */
244 /* http://www.google.com/search?hl=en&safe=off&q=40MHz%2F%2816*22%29&btnG=Search 113.636 kHz */
246 /* Not 1024, the number of gaps between them */
247 #define ADC_DIVISIONS 1023
249 #define IGNITION_CHANNELS 12 /* How many ignition channels the code should support */
250 #define INJECTION_CHANNELS 6 /* How many injection channels the code should support */
252 /* Ignition defines */
253 #define DWELL_ENABLE BIT0
254 #define DWELL_DISABLE NBIT0
255 #define IGNITION_ENABLE BIT1
256 #define IGNITION_DISABLE NBIT1
258 /* Valid RPAGE values :
268 /* The reset value of RPAGE is 0xFD */
269 /* The other 8k of linear RAM space is accessible */
270 /* through the RPAGE window with 0xFE and 0xFF */
271 /* 0xFE refers to the 0x2000 to 0x3000 region */
272 /* 0xFF refers to the 0x3000 to 0x4000 region */
273 #define RPAGE_TUNE_ONE 0xF8
274 #define RPAGE_TUNE_TWO 0xF9
275 #define RPAGE_FUEL_ONE 0xFA
276 #define RPAGE_FUEL_TWO 0xFB
277 #define RPAGE_TIME_ONE 0xFC
278 #define RPAGE_TIME_TWO 0xFD
281 /* The TX and RX buffers are slightly larger than 2k because the RX buffer */
282 /* needs to also receive a header, checksum and attributes for the data */
283 /* involved and the TX buffer needs to handle all of those two fold. */
284 #define TX_BUFFER_SIZE 0x0820
285 #define RX_BUFFER_SIZE 0x0810
286 #define TransferTableSize 2048
290 /* let us know if we are being untidy with headers */
291 #warning "Header file GLOBALDEFINES_H seen before, sort it out!"
292 /* end of the wrapper ifdef from the very top */