FreeEMS  0.2.0-SNAPSHOT-285-g028e24c
globalDefines.h
Go to the documentation of this file.
1 /* FreeEMS - the open source engine management system
2  *
3  * Copyright 2008-2012 Fred Cooke
4  *
5  * This file is part of the FreeEMS project.
6  *
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.
11  *
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.
16  *
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/
19  *
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!
22  *
23  * Thank you for choosing FreeEMS to run your engine!
24  */
25 
26 
27 /** @file
28  *
29  * @ingroup allHeaders
30  * @ingroup globalHeaders
31  *
32  * @brief Global hash define literal replacements
33  *
34  * This holds general purpose hash defined constants and literals.
35  *
36  * @todo TODO Some investigation as to whether it is best to use consts or defines is required
37  */
38 
39 
40 /* Header file multiple inclusion protection courtesy eclipse Header Template */
41 /* and http://gcc.gnu.org/onlinedocs/gcc-3.1.1/cpp/ C pre processor manual */
42 #ifndef FILE_GLOBALDEFINES_H_SEEN
43 #define FILE_GLOBALDEFINES_H_SEEN
44 
45 
46 /* TODO perhaps configure various ports and pins etc to have names such that the
47  * code can stay untouched when being ported and just the header changed to suit?
48  * definitely a good idea, but we'll see what karsten says before putting time
49  * into it. something like : #define RPM_IN_MAIN IC0 etc etc
50  */
51 
52 
53 /* Definitions for functions used across the project TODO these are unused! */
54 /* http://www.seattlerobotics.org/encoder/200109/encoder.htm section Assembly */
55 #define INLINE_ASSEMBLY(code) __asm__ __volatile__ (code)
56 #define ALWAYS_INLINE __attribute__((always_inline))
57 
58 /* Common macro definitions across the project */
59 /* Booleans from http://c2.com/cgi/wiki?CeePreprocessorStatements */
60 #define FALSE (0!=0) // Note, this evaluates to 0 on this platform
61 #define TRUE !FALSE // Note, this evaluates to 1 on this platform
62 
63 /* 8 bit values */
64 #define ZEROS 0x00
65 #define ONES 0xFF
66 
67 /* 16 bit values */
68 #define ZEROS16 0x0000
69 #define ONES16 0xFFFF
70 
71 /* Halves and Maxes */
72 #define LONGHALF 0x80000000UL /* 2147483648 */ // Ned IS awesome! ;-)
73 #define LONGMAX 0xFFFFFFFFUL /* 4294967295 */
74 #define SHORT4TH 0x4000 /* 16384 */
75 #define SHORTHALF 0x8000 /* 32768 */
76 #define SHORTMAX 0xFFFF /* 65535 */
77 
78 /* 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 */
79 #define BIT0 0x01 /* 1st bit = 1 */
80 #define BIT1 0x02 /* 2nd bit = 2 */
81 #define BIT2 0x04 /* 3rd bit = 4 */
82 #define BIT3 0x08 /* 4th bit = 8 */
83 #define BIT4 0x10 /* 5th bit = 16 */
84 #define BIT5 0x20 /* 6th bit = 32 */
85 #define BIT6 0x40 /* 7th bit = 64 */
86 #define BIT7 0x80 /* 8th bit = 128 */
87 
88 #define BIT0_16 0x0001 /* 1st bit = 1 */
89 #define BIT1_16 0x0002 /* 2nd bit = 2 */
90 #define BIT2_16 0x0004 /* 3rd bit = 4 */
91 #define BIT3_16 0x0008 /* 4th bit = 8 */
92 #define BIT4_16 0x0010 /* 5th bit = 16 */
93 #define BIT5_16 0x0020 /* 6th bit = 32 */
94 #define BIT6_16 0x0040 /* 7th bit = 64 */
95 #define BIT7_16 0x0080 /* 8th bit = 128 */
96 
97 #define BIT8_16 0x0100 /* 9th bit = 256 */
98 #define BIT9_16 0x0200 /* 10th bit = 512 */
99 #define BIT10_16 0x0400 /* 11th bit = 1024 */
100 #define BIT11_16 0x0800 /* 12th bit = 2048 */
101 #define BIT12_16 0x1000 /* 13th bit = 4096 */
102 #define BIT13_16 0x2000 /* 14th bit = 8192 */
103 #define BIT14_16 0x4000 /* 15th bit = 16384 */
104 #define BIT15_16 0x8000 /* 16th bit = 32768 */
105 
106 /* Individual bits NOTTED : http://supp.iar.com/Support/?note=12582&from=search+result */
107 #define NBIT0 0xFE /* 1st bit = 1 */
108 #define NBIT1 0xFD /* 2nd bit = 2 */
109 #define NBIT2 0xFB /* 3rd bit = 4 */
110 #define NBIT3 0xF7 /* 4th bit = 8 */
111 #define NBIT4 0xEF /* 5th bit = 16 */
112 #define NBIT5 0xDF /* 6th bit = 32 */
113 #define NBIT6 0xBF /* 7th bit = 64 */
114 #define NBIT7 0x7F /* 8th bit = 128 */
115 
116 #define NBIT0_16 0xFFFE /* 1st bit = 1 */
117 #define NBIT1_16 0xFFFD /* 2nd bit = 2 */
118 #define NBIT2_16 0xFFFB /* 3rd bit = 4 */
119 #define NBIT3_16 0xFFF7 /* 4th bit = 8 */
120 #define NBIT4_16 0xFFEF /* 5th bit = 16 */
121 #define NBIT5_16 0xFFDF /* 6th bit = 32 */
122 #define NBIT6_16 0xFFBF /* 7th bit = 64 */
123 #define NBIT7_16 0xFF7F /* 8th bit = 128 */
124 
125 #define NBIT8_16 0xFEFF /* 9th bit = 256 */
126 #define NBIT9_16 0xFDFF /* 10th bit = 512 */
127 #define NBIT10_16 0xFBFF /* 11th bit = 1024 */
128 #define NBIT11_16 0xF7FF /* 12th bit = 2048 */
129 #define NBIT12_16 0xEFFF /* 13th bit = 4096 */
130 #define NBIT13_16 0xDFFF /* 14th bit = 8192 */
131 #define NBIT14_16 0xBFFF /* 15th bit = 16384 */
132 #define NBIT15_16 0x7FFF /* 16th bit = 32768 */
133 
134 
135 #else
136  /* let us know if we are being untidy with headers */
137  #warning "Header file GLOBALDEFINES_H seen before, sort it out!"
138 /* end of the wrapper ifdef from the very top */
139 #endif