00001 /* FreeEMS - the open source engine management system 00002 * 00003 * Copyright 2008, 2009, 2010 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 00038 #define GLOBAL_CONSTANTS_C 00039 #define NO_CONST_ARRAYS 00040 #include "inc/freeEMS.h" 00041 00042 00043 /* Types summary 00044 * 00045 * BEWARE : Be explicit!! 00046 * 00047 * char 8 bit (defaults to unsigned, but always specify signed/unsigned anyway) 00048 * short 16 bit (defaults to signed, but always specify signed/unsigned anyway) 00049 * int 16 bit DO NOT USE! (current compile flags make this 16 bits, but a change of flags could will change your program if you use this because they will all be 32 bit all of a sudden) 00050 * long 32 bit (defaults to signed, but always specify signed/unsigned anyway) 00051 * long long 64 bit (inefficient, avoid these, if using : defaults to signed, but always specify signed/unsigned anyway) 00052 * float 32 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math) 00053 * double 64 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math) 00054 */ 00055 00056 00057 const unsigned short maxBasicDatalogLength = sizeof(CoreVar) + sizeof(DerivedVar) + sizeof(ADCArray); 00058 00059 00060 /* Constants */ 00061 /* &&&&&&&&&& WARNING &&&&&&&&&& These need to be changed if the timer period is changed at all!! &&&&&&&&&& WARNING &&&&&&&&&& */ 00062 /* TODO It may be better to make these actual times and calculate the number of timer units such that a change in time base of the timer doesn't affect the code. */ 00063 00071 const unsigned char interfaceVersionAndType[20] = {0,0,0,'I','F','r','e','e','E','M','S',' ','V','a','n','i','l','l','a',0}; 00072 00077 const unsigned char firmwareVersion[29] = {"FreeEMS Vanilla 0.1.1 XGATED"}; 00078 00101 const unsigned long masterFuelConstant = 139371764; 00102 00107 const unsigned long MAFFuelConstant = 0; 00108 00109 /* Injection limits */ 00110 /* The number of timer units it takes for the switch on scheduling code to run */ 00111 const unsigned short injectorSwitchOnCodeTime = 100; /* Measured 4 timer cycles, going on the safe side by a lot, and limiting minimum pulse to 0.02ms which is well below any dead time I've heard of */ 00112 00113 /* The number of timer units it takes for the switch off scheduling code to run */ 00114 const unsigned short injectorSwitchOffCodeTime = 100; /* This is actually shorter than the switch on time above as measured between 0.0.8 and 0.0.9 */ 00115 00116 /* The maximum a requested pulsewidth can be before it is truncated to this amount */ 00117 const unsigned short injectorMaximumPulseWidth = 0xF424; /* 62500 clock cycles, = exactly 50ms, which is an arbitrary limit but I like round numbers :-) */ 00118 00119 /* The minimum a requested pulsewidth can be before it is not switched on at all */ 00120 const unsigned short injectorMinimumPulseWidth = 100; 00121 00122 00123 /* Ignition limits */ 00124 /* Ignition maximum dwell in timer units */ 00125 const unsigned short ignitionMaximumDwell = 50000; /* meaningless us value for now, currently unused */ 00126 00127 /* Ignition minimum dwell in timer units */ 00128 const unsigned short ignitionMinimumDwell = 500; /* meaningless us value for now, currently unused */ 00129 00130 /* Ignition maximum delay post schedule tooth in timer units */ 00131 const unsigned short ignitionMaximumDelayToDwellStartAfterTooth = 50000; /* (max retard) meaningless us value for now, currently unused */ 00132 00133 /* Ignition maximum delay post schedule tooth in timer units */ 00134 const unsigned short ignitionMinimumDelayToDwellStartAfterTooth = 500; /* (max advance) meaningless us value for now, currently unused */ 00135 00136 00137 /* Engine position/RPM decoder limits */ 00138 /* */ 00139 const unsigned short leadingEdgePrimaryRPMInputCodeTime = 100; /* random large safe value */ 00140 00141 /* */ 00142 const unsigned short trailingEdgePrimaryRPMInputCodeTime = 100; /* random large safe value */ 00143 00144 /* */ 00145 const unsigned short leadingEdgeSecondaryRPMInputCodeTime = 100; /* random large safe value */ 00146 00147 /* */ 00148 const unsigned short trailingEdgeSecondaryRPMInputCodeTime = 100; /* random large safe value */ 00149 00150 // TODO put these where they belong, just dumped from other file for now... 00151 /* Main injector channel bit masks and registers for use in both injection_isrs.c and engine_position_isrs.c */ 00152 /* Masks for setting mainOn flags and checking state of pin and therefore which change of state just occured */ 00153 /* Masks for clearing mainOn flags */ 00154 /* Masks for setting mainOn flags and checking state of pin and therefore which change of state just occured */ 00155 /* Masks to be used with |= to switch a channel to "turn on compare" mode */ 00156 /* Masks to be used dissable with &= to switch a channel to "turn off compare" mode */ 00157 /* Masks to be used with |= to switch a channel to "turn on on compare" mode from "turn off on compare" mode */ 00158 /* Masks to be used with &= to switch a channel to "turn off on compare" mode from "turn on on compare" mode */ 00159 /* Ignition channel bit masks for use in both PIT timer ISRs and engine_position_isrs.c */ 00160 /* Masks for setting ignition status bits and turning on the channels themselves */ 00161 /* Masks for clearing ignition status bits and turning off the channels themselves */ 00162 00163 00164 /* Dwell masks { CYL1 B0, CYL2 B1, CYL3 B2, CYL4 B3, CYL5 B4, CYL6 B5, CYL7 B6, CYL8 B7, CYL9 A0,CYL10 A1,CYL11 A2,CYL12 A3}; */ 00165 const unsigned short dwellStartMasks[IGNITION_CHANNELS] = { BIT8_16, BIT9_16, BIT10_16, BIT11_16, BIT12_16, BIT13_16, BIT14_16, BIT15_16, BIT0_16, BIT1_16, BIT2_16, BIT3_16}; /* Set of masks such that a cylinder can be dwelled with a single line of code */ 00166 const unsigned short ignitionMasks[IGNITION_CHANNELS] = {NBIT8_16,NBIT9_16,NBIT10_16,NBIT11_16,NBIT12_16,NBIT13_16,NBIT14_16,NBIT15_16,NBIT0_16,NBIT1_16,NBIT2_16,NBIT3_16}; /* Set of masks such that a cylinder can be fired with a single line of code */ 00167 00168 /* Injection masks */ 00169 const unsigned char injectorMainOnMasks[INJECTION_CHANNELS] = {BIT2, BIT3, BIT4, BIT5, BIT6, BIT7}; 00170 const unsigned char injectorMainOffMasks[INJECTION_CHANNELS] = {NBIT2, NBIT3, NBIT4, NBIT5, NBIT6, NBIT7}; 00171 const unsigned char injectorMainEnableMasks[INJECTION_CHANNELS] = {0x30, 0xC0, 0x03, 0x0C, 0x30, 0xC0}; 00172 const unsigned char injectorMainDisableMasks[INJECTION_CHANNELS] = {0xCF, 0x3F, 0xFC, 0xF3, 0xCF, 0x3F}; 00173 const unsigned char injectorMainGoHighMasks[INJECTION_CHANNELS] = {BIT4, BIT6, BIT0, BIT2, BIT4, BIT6}; 00174 const unsigned char injectorMainGoLowMasks[INJECTION_CHANNELS] = {NBIT4, NBIT6, NBIT0, NBIT2, NBIT4, NBIT6};