globalDefines.h

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

Generated on Mon Dec 22 21:29:18 2008 for freeems by  doxygen 1.5.2