Initial commit of 0.0.18 just as it was released!
[freeems-vanilla.git] / src / globalConstants.c
blob18c927f23fcdd4378eb05f126df07fa69cb9095c
1 /* globalConstants.c
3 Copyright 2008 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 send them upstream to us at admin@diyefi.org
22 Thank you for choosing FreeEMS to run your engine! */
25 #define NO_CONST_ARRAYS
26 #include "inc/freeEMS.h"
28 /* Types summary
30 * BEWARE : Be explicit!!
32 * char 8 bit (defaults to unsigned, but always specify signed/unsigned anyway)
33 * short 16 bit (defaults to signed, but always specify signed/unsigned anyway)
34 * 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)
35 * long 32 bit (defaults to signed, but always specify signed/unsigned anyway)
36 * long long 64 bit (inefficient, avoid these, if using : defaults to signed, but always specify signed/unsigned anyway)
37 * float 32 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math)
38 * double 64 bit IEEE floating point numbers (inefficient, avoid these, used fixed point math)
41 const unsigned short memdumplength = 0x100;
42 const unsigned short maxBasicDatalogLength = sizeof(CoreVar) + sizeof(DerivedVar) + sizeof(ADCArray);
45 /* Constants */
46 /* &&&&&&&&&& WARNING &&&&&&&&&& These need to be changed if the timer period is changed at all!! &&&&&&&&&& WARNING &&&&&&&&&& */
47 /* 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. */
49 /* Serial interface unique identifier */
50 const unsigned char interfaceVersionAndType[20] = {0,0,2,'I','F','r','e','e','E','M','S',' ','V','a','n','i','l','l','a',0};
51 /* This should only change when the serial interface changes (even a little) */
52 /* This field consists of 3 chars for a 3 part version number and a free form string. For any unique string the version
53 * number is also unique. In this way tools can easily support a range of versions for a specific unique string ID */
55 /* Displayable firmware version identifier */
56 const unsigned char firmwareVersion[47] = {"FreeEMS Vanilla 0.0.18 JackTheRipper pre-alpha"};
57 /* This should change everytime the code is changed at all (even a little) before each release. */
59 /* divisors and untunable physical constants combined into a single master fuel constant
61 * const unsigned short molarMassOfAir = 2897; // in grams per 100 moles, so divide by 100 to get gm/mol
62 * const unsigned short msToTicks = 1250; // constant to bring ms into 0.8us chunks
63 * const unsigned short universalGasConstant = 34056; // 8.314472 * 4096, so divide by 4096 to get real number
65 * #define injectorFlowDivisor 1024
66 * #define injectorFlowUnitDivisor 1000 - to get it into litres/second
67 * #define injectorFlowTotalDivisor 1024000
68 * #define stoichiometricAFRDivisor 1024
69 * #define universalGasConstantDivisor 4096
70 * #define molarMassOfAirDivisor 100
71 * #define perCylinderVolumeDivisor 32768
73 * master = (msToTicks * molarMassOfAir * universalGasConstantDivisor * stoichiometricAFRDivisor * injectorFlowTotalDivisor) / (universalGasConstant * molarMassOfAirDivisor * perCylinderVolumeDivisor);
74 * master = (1250 * 2897 * 4096 * 1024 * 1024000 ) / (34056 * 100 * 32768 );
75 * http://www.google.com/search?hl=en&safe=off&q=((1250+*+2897+*+4096+*+1024+*+1024000)+%2F+(34056+*++100+*+32768)&btnG=Search */
76 const unsigned long masterFuelConstant = 139371764; /* ((1250 * 2897 * 4096 * 1024 * 1024000) / (34056 * 100 * 32768) */
78 /* Yet to be determined */
79 const unsigned long MAFFuelConstant = 0;
81 /* Injection limits */
82 /* The number of timer units it takes for the switch on scheduling code to run */
83 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 */
85 /* The number of timer units it takes for the switch off scheduling code to run */
86 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 */
88 /* The maximum a requested pulsewidth can be before it is truncated to this amount */
89 const unsigned short injectorMaximumPulseWidth = 0xF424; /* 62500 clock cycles, = exactly 50ms, which is an arbitrary limit but I like round numbers :-) */
91 /* The minimum a requested pulsewidth can be before it is not switched on at all */
92 const unsigned short injectorMinimumPulseWidth = 100;
95 /* Ignition limits */
96 /* Ignition maximum dwell in timer units */
97 const unsigned short ignitionMaximumDwell = 50000; /* meaningless us value for now, currently unused */
99 /* Ignition minimum dwell in timer units */
100 const unsigned short ignitionMinimumDwell = 500; /* meaningless us value for now, currently unused */
102 /* Ignition maximum delay post schedule tooth in timer units */
103 const unsigned short ignitionMaximumDelayToDwellStartAfterTooth = 50000; /* (max retard) meaningless us value for now, currently unused */
105 /* Ignition maximum delay post schedule tooth in timer units */
106 const unsigned short ignitionMinimumDelayToDwellStartAfterTooth = 500; /* (max advance) meaningless us value for now, currently unused */
109 /* Engine position/RPM decoder limits */
110 /* */
111 const unsigned short leadingEdgePrimaryRPMInputCodeTime = 100; /* random large safe value */
113 /* */
114 const unsigned short trailingEdgePrimaryRPMInputCodeTime = 100; /* random large safe value */
116 /* */
117 const unsigned short leadingEdgeSecondaryRPMInputCodeTime = 100; /* random large safe value */
119 /* */
120 const unsigned short trailingEdgeSecondaryRPMInputCodeTime = 100; /* random large safe value */
122 // TODO put these where they belong, just dumped from other file for now...
123 /* Main injector channel bit masks and registers for use in both injection_isrs.c and engine_position_isrs.c */
124 /* Masks for setting mainOn flags and checking state of pin and therefore which change of state just occured */
125 /* Masks for clearing mainOn flags */
126 /* Masks for setting mainOn flags and checking state of pin and therefore which change of state just occured */
127 /* Masks to be used with |= to switch a channel to "turn on compare" mode */
128 /* Masks to be used dissable with &= to switch a channel to "turn off compare" mode */
129 /* Masks to be used with |= to switch a channel to "turn on on compare" mode from "turn off on compare" mode */
130 /* Masks to be used with &= to switch a channel to "turn off on compare" mode from "turn on on compare" mode */
131 /* Ignition channel bit masks for use in both PIT timer ISRs and engine_position_isrs.c */
132 /* Masks for setting ignition status bits and turning on the channels themselves */
133 /* Masks for clearing ignition status bits and turning off the channels themselves */
136 /* 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}; */
137 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 */
138 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 */
140 /* Injection masks */
141 const unsigned char injectorMainOnMasks[INJECTION_CHANNELS] = {BIT2, BIT3, BIT4, BIT5, BIT6, BIT7};
142 const unsigned char injectorMainOffMasks[INJECTION_CHANNELS] = {NBIT2, NBIT3, NBIT4, NBIT5, NBIT6, NBIT7};
143 const unsigned char injectorMainEnableMasks[INJECTION_CHANNELS] = {0x30, 0xC0, 0x03, 0x0C, 0x30, 0xC0};
144 const unsigned char injectorMainDisableMasks[INJECTION_CHANNELS] = {0xCF, 0x3F, 0xFC, 0xF3, 0xCF, 0x3F};
145 const unsigned char injectorMainGoHighMasks[INJECTION_CHANNELS] = {BIT4, BIT6, BIT0, BIT2, BIT4, BIT6};
146 const unsigned char injectorMainGoLowMasks[INJECTION_CHANNELS] = {NBIT4, NBIT6, NBIT0, NBIT2, NBIT4, NBIT6};