00001 /* FreeEMS - the open source engine management system 00002 * 00003 * Copyright 2008, 2009 Fred Cooke 00004 * 00005 * This file is part of the FreeEMS project. 00006 * 00007 * FreeEMS software is free software: you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation, either version 3 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * FreeEMS software is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with any FreeEMS software. If not, see http://www.gnu.org/licenses/ 00019 * 00020 * We ask that if you make any changes to this file you email them upstream to 00021 * us at admin(at)diyefi(dot)org or, even better, fork the code on github.com! 00022 * 00023 * Thank you for choosing FreeEMS to run your engine! 00024 */ 00025 00026 00042 /* Header file multiple inclusion protection courtesy eclipse Header Template */ 00043 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */ 00044 #ifndef FILE_GLOBALDEFINES_H_SEEN 00045 #define FILE_GLOBALDEFINES_H_SEEN 00046 00047 00048 /* TODO perhaps configure various ports and pins etc to have names such that the 00049 * code can stay untouched when being ported and just the header changed to suit? 00050 * definitely a good idea, but we'll see what karsten says before putting time 00051 * into it. something like : #define RPM_IN_MAIN IC0 etc etc 00052 */ 00053 00054 00055 /* Definitions for functions used across the project */ 00056 /* http://www.seattlerobotics.org/encoder/200109/encoder.htm section Assembly */ 00057 #define INLINE_ASSEMBLY(code) __asm__ __volatile__ (code) 00058 #define ALWAYS_INLINE __attribute__((always_inline)) 00059 00060 /* Common macro definitions across the project */ 00061 /* Boolean */ 00062 #define FALSE 0 00063 #define TRUE !FALSE /* http://c2.com/cgi/wiki?CeePreprocessorStatements */ 00064 00065 /* 8 bit values */ 00066 #define ZEROS 0x00 00067 #define ONES 0xFF 00068 00069 /* 16 bit values */ 00070 #define ZEROS16 0x0000 00071 #define ONES16 0xFFFF 00072 00073 /* Halves and Maxes */ 00074 #define LONGHALF 0x80000000 /* 2147483648 */ 00075 #define LONGMAX 0xFFFFFFFF /* 4294967295*/ 00076 #define SHORTHALF 0x8000 /* 32768 */ 00077 #define SHORTMAX 0xFFFF /* 65535 */ 00078 00079 /* 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 */ 00080 #define BIT0 0x01 /* 1st bit = 1 */ 00081 #define BIT1 0x02 /* 2nd bit = 2 */ 00082 #define BIT2 0x04 /* 3rd bit = 4 */ 00083 #define BIT3 0x08 /* 4th bit = 8 */ 00084 #define BIT4 0x10 /* 5th bit = 16 */ 00085 #define BIT5 0x20 /* 6th bit = 32 */ 00086 #define BIT6 0x40 /* 7th bit = 64 */ 00087 #define BIT7 0x80 /* 8th bit = 128 */ 00088 00089 #define BIT0_16 0x0001 /* 1st bit = 1 */ 00090 #define BIT1_16 0x0002 /* 2nd bit = 2 */ 00091 #define BIT2_16 0x0004 /* 3rd bit = 4 */ 00092 #define BIT3_16 0x0008 /* 4th bit = 8 */ 00093 #define BIT4_16 0x0010 /* 5th bit = 16 */ 00094 #define BIT5_16 0x0020 /* 6th bit = 32 */ 00095 #define BIT6_16 0x0040 /* 7th bit = 64 */ 00096 #define BIT7_16 0x0080 /* 8th bit = 128 */ 00097 00098 #define BIT8_16 0x0100 /* 9th bit = 256 */ 00099 #define BIT9_16 0x0200 /* 10th bit = 512 */ 00100 #define BIT10_16 0x0400 /* 11th bit = 1024 */ 00101 #define BIT11_16 0x0800 /* 12th bit = 2048 */ 00102 #define BIT12_16 0x1000 /* 13th bit = 4096 */ 00103 #define BIT13_16 0x2000 /* 14th bit = 8192 */ 00104 #define BIT14_16 0x4000 /* 15th bit = 16384 */ 00105 #define BIT15_16 0x8000 /* 16th bit = 32768 */ 00106 00107 /* Individual bits NOTTED : http://supp.iar.com/Support/?note=12582&from=search+result */ 00108 #define NBIT0 0xFE /* 1st bit = 1 */ 00109 #define NBIT1 0xFD /* 2nd bit = 2 */ 00110 #define NBIT2 0xFB /* 3rd bit = 4 */ 00111 #define NBIT3 0xF7 /* 4th bit = 8 */ 00112 #define NBIT4 0xEF /* 5th bit = 16 */ 00113 #define NBIT5 0xDF /* 6th bit = 32 */ 00114 #define NBIT6 0xBF /* 7th bit = 64 */ 00115 #define NBIT7 0x7F /* 8th bit = 128 */ 00116 00117 #define NBIT0_16 0xFFFE /* 1st bit = 1 */ 00118 #define NBIT1_16 0xFFFD /* 2nd bit = 2 */ 00119 #define NBIT2_16 0xFFFB /* 3rd bit = 4 */ 00120 #define NBIT3_16 0xFFF7 /* 4th bit = 8 */ 00121 #define NBIT4_16 0xFFEF /* 5th bit = 16 */ 00122 #define NBIT5_16 0xFFDF /* 6th bit = 32 */ 00123 #define NBIT6_16 0xFFBF /* 7th bit = 64 */ 00124 #define NBIT7_16 0xFF7F /* 8th bit = 128 */ 00125 00126 #define NBIT8_16 0xFEFF /* 9th bit = 256 */ 00127 #define NBIT9_16 0xFDFF /* 10th bit = 512 */ 00128 #define NBIT10_16 0xFBFF /* 11th bit = 1024 */ 00129 #define NBIT11_16 0xF7FF /* 12th bit = 2048 */ 00130 #define NBIT12_16 0xEFFF /* 13th bit = 4096 */ 00131 #define NBIT13_16 0xDFFF /* 14th bit = 8192 */ 00132 #define NBIT14_16 0xBFFF /* 15th bit = 16384 */ 00133 #define NBIT15_16 0x7FFF /* 16th bit = 32768 */ 00134 00135 00136 /* Serial Comms Stuff */ 00137 #define ESCAPE_BYTE 0xBB 00138 #define START_BYTE 0xAA 00139 #define STOP_BYTE 0xCC 00140 #define ESCAPED_ESCAPE_BYTE 0x44 00141 #define ESCAPED_START_BYTE 0x55 00142 #define ESCAPED_STOP_BYTE 0x33 00143 #define flashSectorSize 1024 00144 #define flashSectorSizeInWords 512 /* 512 words to a 1k flash sector */ 00145 00146 00147 #define RPM_FACTOR 2 00148 #define MAP_FACTOR 100 00149 #define TPS_FACTOR 640 00150 #define BRV_FACTOR 1000 00151 #define TEMP_FACTOR 100 00152 #define EGO_FACTOR 32768 00153 00154 00155 #define idleManifoldPressure 3000 /* 30 kPa */ 00156 #define seaLevelKPa 10000 /* 100 kPa */ 00157 #define maxExpectedBoost 30000 /* 300 kPa */ 00158 00159 #define freezingPoint 27315 /* 0 Celcius */ 00160 #define roomTemperature 29315 /* 20 Celcius */ 00161 #define runningTemperature 35815 /* 85 Celcius */ 00162 00163 #define halfThrottle 32768 /* 50% throttle */ 00164 #define runningVoltage 14400 /* 14.4 Volts */ 00165 #define idlePulseWidth 2000 /* ~1.5ms */ 00166 #define idleAirFlow 1500 /* guessed */ 00167 00168 #define typicalCylinderSize 16384 /* 500cc per cylinder */ 00169 #define typicalInjectorSize 9387 /* 550cc per minute */ 00170 00171 #define densityOfOctane 22496 /* 703 grams per litre */ 00172 #define stoichiometricLambda 32768 /* Lambda = 1.0 */ 00173 00174 /* Generated with http://www.diyefi.org/calculators.htm#stoich */ 00175 #define stoichiometricAFRMethane 17245 /* 17.245 AFR */ 00176 #define stoichiometricAFRPropane 15685 /* 15.685 AFR */ 00177 #define stoichiometricAFRLPG 15599 /* 15.599 AFR */ 00178 #define stoichiometricAFRButane 15469 /* 15.469 AFR */ 00179 #define stoichiometricAFROctane 15137 /* 15.137 AFR */ 00180 #define stoichiometricAFRGasoline 14700 /* 14.700 AFR */ 00181 #define stoichiometricAFRXylene 13681 /* 13.681 AFR */ 00182 #define stoichiometricAFRToluene 13512 /* 13.512 AFR */ 00183 #define stoichiometricAFRBenzene 13282 /* 13.282 AFR */ 00184 #define stoichiometricAFRE85 9862 /* 9.862 AFR */ 00185 #define stoichiometricAFREthanol 9008 /* 9.008 AFR */ 00186 #define stoichiometricAFRMethanol 6475 /* 6.475 AFR */ 00187 00188 #define batteryVoltageMin 0 /* Voltage read at lowest ADC reading */ 00189 #define batteryVoltageRange 24500 /* Voltage difference between lowest and highest ADC reading */ 00190 00191 #define LC1LambdaMin 16384 /* Lambda read at lowest ADC reading */ 00192 #define LC1LambdaMax 49152 /* Lambda read at highest ADC reading */ 00193 #define LC1LambdaRange 32768 /* Lambda difference between lowest and highest ADC reading */ 00194 00195 #define AFR1020LambdaMin 16384 /* Lambda read at lowest ADC reading */ 00196 #define AFR1020LambdaMax 49152 /* Lambda read at highest ADC reading */ 00197 #define AFR1020LambdaRange 32768 /* Lambda difference between lowest and highest ADC reading */ 00198 00199 00200 /* MAP Sensor Data Explanation 00201 * 00202 * Motorola/Freescale pressure sensor data obtained from the 00203 * data sheets by extrapolation of the "typical" line to the 00204 * borders of the transfer function chart. This gives us the 00205 * correct values in the middle despite not being able to 00206 * reach the ends of the scale. 00207 * 00208 * By min and max I mean the OV and 5V pressures that aren't 00209 * attainable, but that give the correct function in between. 00210 */ 00211 00212 00213 /* www.freescale.com/files/sensors/doc/data_sheet/MPX4100A.pdf */ 00214 #define MPX4100AMin 1400 /* Pressure read at lowest ADC reading */ 00215 #define MPX4100AMax 10750 /* Pressure read at highest ADC reading */ 00216 #define MPX4100ARange 9350 /* Pressure difference between lowest and highest ADC readings */ 00217 00218 /* www.freescale.com/files/sensors/doc/data_sheet/MPX4250A.pdf */ 00219 #define MPX4250AMin 800 /* Pressure read at lowest ADC reading */ 00220 #define MPX4250AMax 26000 /* Pressure read at highest ADC reading */ 00221 #define MPX4250ARange 25200 /* Pressure difference between lowest and highest ADC readings */ 00222 00223 #define MPXH6300AMin 1200 /* Pressure read at lowest ADC reading */ 00224 #define MPXH6300AMax 32000 /* Pressure read at highest ADC reading */ 00225 #define MPXH6300ARange 30800 /* Pressure difference between lowest and highest ADC readings */ 00226 00227 #define MPXH6400AMin 1200 /* Pressure read at lowest ADC reading */ 00228 #define MPXH6400AMax 42000 /* Pressure read at highest ADC reading */ 00229 #define MPXH6400ARange 40800 /* Pressure difference between lowest and highest ADC readings */ 00230 00231 #define TPSDefaultMin 255 /* ADC reading at lowest throttle position */ 00232 #define TPSDefaultMax 767 /* ADC reading at highest throttle position */ 00233 00234 #define offIdleMAP 3000 /* 30kPa just above where MAP would be with closed throttle at idle */ 00235 #define nearlyWOTMAP 9500 /* 95kPa just below where MAP would be at WOT */ 00236 00237 #define ticksPerCycleAtOneRPMx2 300000000 /* twice how many 0.8us ticks there are in between engine cycles at 1 RPM */ 00238 #define ticksPerCycleAtOneRPM 150000000 /* how many 0.8us ticks there are in between engine cycles at 1 RPM */ 00239 #define tachoTickFactor4at50 6 /* Provides for a 4 cylinder down to 50 RPM */ 00240 /*efine tachoEdgesPerCycle4at50 8 / 8 events per cycle for a typical 4 cylinder tacho, 4 on, 4 off */ 00241 #define tachoTotalFactor4at50 48 /* http://www.google.com/search?hl=en&safe=off&q=((150000000+%2F+6)+%2F++8+)+%2F+50&btnG=Search */ 00242 //#define ticksForFiftyRPM 3000000 /* ticksPerCycleAtOneRPM / 50 */ 00243 00244 //#define lookedUpVEDivisor 512 00245 //#define VEpercentageDivisor 100 00246 #define oneHundredPercentVE 51200 00247 00248 //#define densityOfFuelDivisor 32 00249 //#define densityOfFuelUnitDivisor 1000 00250 #define densityOfFuelTotalDivisor 32000 00251 00252 #define divisorFor115200bps 22 /* (40MHz / (16*115.2kHz)) = 21.7013889 */ 00253 /* 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 */ 00254 /* http://www.google.com/search?hl=en&safe=off&q=40MHz%2F%2816*22%29&btnG=Search 113.636 kHz */ 00255 00256 /* Not 1024, the number of gaps between them */ 00257 #define ADC_DIVISIONS 1023 00258 00259 #define IGNITION_CHANNELS 12 /* How many ignition channels the code should support */ 00260 #define INJECTION_CHANNELS 6 /* How many injection channels the code should support */ 00261 00262 /* Ignition defines */ 00263 #define DWELL_ENABLE BIT0 00264 #define DWELL_DISABLE NBIT0 00265 #define IGNITION_ENABLE BIT1 00266 #define IGNITION_DISABLE NBIT1 00267 00268 /* Valid RPAGE values : 00269 * 0xFF - linear 00270 * 0xFE - linear 00271 * 0xFD - default 00272 * 0xFC 00273 * 0xFB 00274 * 0xFA 00275 * 0xF9 00276 * 0xF8 00277 */ 00278 /* The reset value of RPAGE is 0xFD */ 00279 /* The other 8k of linear RAM space is accessible */ 00280 /* through the RPAGE window with 0xFE and 0xFF */ 00281 /* 0xFE refers to the 0x2000 to 0x3000 region */ 00282 /* 0xFF refers to the 0x3000 to 0x4000 region */ 00283 #define RPAGE_TUNE_ONE 0xF8 00284 #define RPAGE_TUNE_TWO 0xF9 00285 #define RPAGE_FUEL_ONE 0xFA 00286 #define RPAGE_FUEL_TWO 0xFB 00287 #define RPAGE_TIME_ONE 0xFC 00288 #define RPAGE_TIME_TWO 0xFD 00289 #define RPAGE_MIN 0xF8 00290 #define PPAGE_MIN 0xE0 00291 #define EPAGE_MIN 0x?? // TODO 00292 00293 /* The TX and RX buffers are slightly larger than 2k because the RX buffer */ 00294 /* needs to also receive a header, checksum and attributes for the data */ 00295 /* involved and the TX buffer needs to handle all of those two fold. */ 00296 #define TX_BUFFER_SIZE 0x0820 00297 #define RX_BUFFER_SIZE 0x0810 00298 #define TransferTableSize 2048 00299 #define TX_MAX_PAYLOAD_SIZE 2048 00300 00301 00302 #else 00303 /* let us know if we are being untidy with headers */ 00304 #warning "Header file GLOBALDEFINES_H seen before, sort it out!" 00305 /* end of the wrapper ifdef from the very top */ 00306 #endif