1 /* FreeEMS - the open source engine management system
3 * Copyright 2008-2014 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 email them upstream to
21 * us at admin(at)diyefi(dot)org or, even better, fork the code on github.com!
23 * Thank you for choosing FreeEMS to run your engine!
29 * @ingroup dataInitialisers
31 * @brief Global constant values
33 * All global constants values are, and should be, defined here.
37 #define GLOBAL_CONSTANTS_C
38 #define NO_CONST_ARRAYS
39 #include "inc/freeEMS.h"
43 /* &&&&&&&&&& WARNING &&&&&&&&&& These need to be changed if the timer period is changed at all!! &&&&&&&&&& WARNING &&&&&&&&&& */
44 /* 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. */
47 const unsigned char interfaceVersion
[INTERFACE_VERSION_LENGTH
] = { INTERFACE_VERSION
}; ///< @copydoc interfaceVersion TODO change spec to not have numerics and to parse from string, maybe pull from somewhere?
48 const unsigned char firmwareVersion
[FIRMWARE_VERSION_LENGTH
] = { FIRMWARE_VERSION
"-" BUILD_CONFIG
}; ///< @copydoc firmwareVersion
49 const unsigned char buildTimeAndDate
[FIRMWARE_BUILD_DATE_LENGTH
] = { FIRMWARE_BUILD_DATE
}; ///< @copydoc buildTimeAndDate
50 const unsigned char compilerVersion
[COMPILER_VERSION_LENGTH
] = { __VERSION__
}; ///< @copydoc compilerVersion
51 const unsigned char operatingSystem
[OPERATING_SYSTEM_LENGTH
] = { OPERATING_SYSTEM
}; ///< @copydoc operatingSystem
52 const unsigned char builtByName
[BUILT_BY_NAME_LENGTH
] = { BUILT_BY_NAME
}; ///< @copydoc builtByName
53 const unsigned char supportEmail
[SUPPORT_EMAIL_LENGTH
] = { SUPPORT_EMAIL
}; ///< @copydoc supportEmail
55 /** Divisors and untunable physical constants combined into a single master fuel constant
57 * const unsigned short molarMassOfAir = 2897; // in grams per 100 moles, so divide by 100 to get gm/mol
58 * const unsigned short msToTicks = 1250; // constant to bring ms into 0.8us chunks
59 * const unsigned short universalGasConstant = 34056; // 8.314472 * 4096, so divide by 4096 to get real number
61 * hash define injectorFlowDivisor 1024
62 * hash define injectorFlowUnitDivisor 1000 - to get it into litres/second
63 * hash define injectorFlowTotalDivisor 1024000
64 * hash define stoichiometricAFRDivisor 1024
65 * hash define universalGasConstantDivisor 4096
66 * hash define molarMassOfAirDivisor 100
67 * hash define perCylinderVolumeDivisor 32768
69 * TODO hash define the fuel constant for different clock tick setups (msToTicks will vary)
71 * master = (msToTicks * molarMassOfAir * universalGasConstantDivisor * stoichiometricAFRDivisor * injectorFlowTotalDivisor) / (universalGasConstant * molarMassOfAirDivisor * perCylinderVolumeDivisor);
72 * master = (1250 * 2897 * 4096 * 1024 * 1024000 ) / (34056 * 100 * 32768 );
73 * http://duckduckgo.com/?q=%28%281250+*+2897+*+4096+*+1024+*+1024000%29+%2F+%2834056+*++100+*+32768%29
75 * ((1250 * 2897 * 4096 * 1024 * 1024000) / (34056 * 100 * 32768) = 139371764
77 const unsigned long masterFuelConstant
= 139371764;
81 * @todo TODO Determine what the value of MAF fuel constant should be
83 const unsigned long MAFFuelConstant
= 0;
85 /// @todo TODO Move these to decoder interface, and make set by each decoder where appropriate
87 /* The number of timer units it takes for the switch on scheduling code to run + latencies */
88 const unsigned short ectSwitchOnCodeTime
= 250; /* Used to set min pw in output ISR. 250 is based on worst of decoders causing latencies. */
89 /* The number of timer units it takes for the switch off scheduling code to run + latencies */
90 const unsigned short ectSwitchOffCodeTime
= 250; /* Used to see if we should set self sched or not. 250 is based on worst of decoders causing latencies. */
92 // TODO put these where they belong, just dumped from other file for now...
93 /* Main injector channel bit masks and registers for use in both injection_isrs.c and engine_position_isrs.c */
94 /* Masks for setting mainOn flags and checking state of pin and therefore which change of state just occured */
95 /* Masks for clearing mainOn flags */
96 /* Masks for setting mainOn flags and checking state of pin and therefore which change of state just occured */
97 /* Masks to be used with |= to switch a channel to "turn on compare" mode */
98 /* Masks to be used dissable with &= to switch a channel to "turn off compare" mode */
99 /* Masks to be used with |= to switch a channel to "turn on on compare" mode from "turn off on compare" mode */
100 /* Masks to be used with &= to switch a channel to "turn off on compare" mode from "turn on on compare" mode */
101 /* Ignition channel bit masks for use in both PIT timer ISRs and engine_position_isrs.c */
102 /* Masks for setting ignition status bits and turning on the channels themselves */
103 /* Masks for clearing ignition status bits and turning off the channels themselves */
106 /* Injection masks */
108 // To be used with flag vars and TIE and TFLG
109 const unsigned char ectMainOnMasks
[ECT_CHANNELS
] = {BIT2
, BIT3
, BIT4
, BIT5
, BIT6
, BIT7
};
110 const unsigned char ectMainOffMasks
[ECT_CHANNELS
] = {NBIT2
, NBIT3
, NBIT4
, NBIT5
, NBIT6
, NBIT7
};
112 // To be used in conjunction with injectorMainControlRegisters
113 const unsigned char ectMainActiveMasks
[ECT_CHANNELS
] = {BIT5
, BIT7
, BIT1
, BIT3
, BIT5
, BIT7
}; // Is this enabled for go high OR go low?
114 const unsigned char ectMainEnableMasks
[ECT_CHANNELS
] = {0x30, 0xC0, 0x03, 0x0C, 0x30, 0xC0}; // Regardless of state, mask to enable and cause to go high
115 const unsigned char ectMainDisableMasks
[ECT_CHANNELS
] = {0xCF, 0x3F, 0xFC, 0xF3, 0xCF, 0x3F}; // Regardless of state, mask to disable completely
116 const unsigned char ectMainGoHighMasks
[ECT_CHANNELS
] = {BIT4
, BIT6
, BIT0
, BIT2
, BIT4
, BIT6
}; // Already enabled, mask to change from go low to go high
117 const unsigned char ectMainGoLowMasks
[ECT_CHANNELS
] = {NBIT4
, NBIT6
, NBIT0
, NBIT2
, NBIT4
, NBIT6
}; // Already enabled, mask to change from go high to go low