Fix Luminary LM3S detection.
[bertos.git] / bertos / cpu / detect.h
1 /**
2  * \file
3  * <!--
4  * This file is part of BeRTOS.
5  *
6  * Bertos is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  * As a special exception, you may use this file as part of a free software
21  * library without restriction.  Specifically, if other files instantiate
22  * templates or use macros or inline functions from this file, or you compile
23  * this file and link it with other files to produce an executable, this
24  * file does not by itself cause the resulting executable to be covered by
25  * the GNU General Public License.  This exception does not however
26  * invalidate any other reasons why the executable file might be covered by
27  * the GNU General Public License.
28  *
29  * Copyright 2004, 2005, 2006, 2007 Develer S.r.l. (http://www.develer.com/)
30  * Copyright 2004 Giovanni Bajo
31  *
32  * -->
33  *
34  * \brief CPU detection through special preprocessor macros
35  */
36 #ifndef CPU_DETECT_H
37 #define CPU_DETECT_H
38
39 #if defined(__arm__) /* GCC */ \
40         || defined(__ARM4TM__) /* IAR: defined for all cores >= 4tm */
41         #define CPU_ARM                 1
42         #define CPU_ID                  arm
43
44         // AT91SAM7S core family
45         #if defined(__ARM_AT91SAM7S32__)
46                 #define CPU_ARM_AT91         1
47                 #define CPU_ARM_AT91SAM7S32  1
48         #else
49                 #define CPU_ARM_AT91SAM7S32  0
50         #endif
51
52         #if defined(__ARM_AT91SAM7S64__)
53                 #define CPU_ARM_AT91         1
54                 #define CPU_ARM_AT91SAM7S64  1
55         #else
56                 #define CPU_ARM_AT91SAM7S64  0
57         #endif
58
59         #if defined(__ARM_AT91SAM7S128__)
60                 #define CPU_ARM_AT91         1
61                 #define CPU_ARM_AT91SAM7S128 1
62         #else
63                 #define CPU_ARM_AT91SAM7S128 0
64         #endif
65
66         #if defined(__ARM_AT91SAM7S256__)
67                 #define CPU_ARM_AT91         1
68                 #define CPU_ARM_AT91SAM7S256 1
69         #else
70                 #define CPU_ARM_AT91SAM7S256 0
71         #endif
72
73         // AT91SAM7X core family
74         #if defined(__ARM_AT91SAM7X128__)
75                 #define CPU_ARM_AT91         1
76                 #define CPU_ARM_AT91SAM7X128 1
77         #else
78                 #define CPU_ARM_AT91SAM7X128 0
79         #endif
80
81         #if defined(__ARM_AT91SAM7X256__)
82                 #define CPU_ARM_AT91         1
83                 #define CPU_ARM_AT91SAM7X256 1
84         #else
85                 #define CPU_ARM_AT91SAM7X256 0
86         #endif
87
88         #if defined (__ARM_LM3S1968__)
89                 #define CPU_ARM_LM3S        1
90                 #define CPU_ARM_LM3S1968    1
91         #else
92                 #define CPU_ARM_LM3S1968    0
93         #endif
94
95
96
97         #if defined(CPU_ARM_AT91)
98                 #if CPU_ARM_AT91SAM7S32 + CPU_ARM_AT91SAM7S64 \
99                 + CPU_ARM_AT91SAM7S128 + CPU_ARM_AT91SAM7S256 \
100                 + CPU_ARM_AT91SAM7X128 + CPU_ARM_AT91SAM7X256 != 1
101                         #error ARM CPU configuration error
102                 #endif
103                 #define CPU_ARM_LM3S        0
104
105         #elif defined (CPU_ARM_LM3S)
106                 #if CPU_ARM_LM3S1968 + 0 != 1
107                         #error Luminary ARM CPU configuration error
108                 #endif
109                 #define CPU_ARM_AT91        0
110         /* #elif Add other ARM families here */
111         #else
112                 #define CPU_ARM_AT91        0
113                 #define CPU_ARM_LM3S        0
114         #endif
115
116
117         #if CPU_ARM_AT91 + CPU_ARM_LM3S + 0 /* Add other ARM families here */ != 1
118                 #error ARM CPU configuration error
119         #endif
120 #else
121         #define CPU_ARM                 0
122
123         /* ARM Families */
124         #define CPU_ARM_AT91            0
125         #define CPU_ARM_LM3S            0
126
127         /* ARM CPUs */
128         #define CPU_ARM_AT91SAM7S32     0
129         #define CPU_ARM_AT91SAM7S64     0
130         #define CPU_ARM_AT91SAM7S128    0
131         #define CPU_ARM_AT91SAM7S256    0
132         #define CPU_ARM_AT91SAM7X128    0
133         #define CPU_ARM_AT91SAM7X256    0
134
135         #define CPU_ARM_LM3S1968        0
136 #endif
137
138 #if (defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)) \
139         && !defined(__ARM4TM__) /* IAR: if not ARM assume I196 */
140         #warning Assuming CPU is I196
141         #define CPU_I196                1
142         #define CPU_ID                  i196
143 #else
144         #define CPU_I196                0
145 #endif
146
147 #if defined(__i386__) /* GCC */ \
148         || (defined(_M_IX86) && !defined(_WIN64)) /* MSVC */
149         #define CPU_X86                 1
150         #define CPU_X86_32              1
151         #define CPU_X86_64              0
152         #define CPU_ID                  x86
153 #elif defined(__x86_64__) /* GCC */ \
154         || (defined(_M_IX86) && defined(_WIN64)) /* MSVC */
155         #define CPU_X86                 1
156         #define CPU_X86_32              0
157         #define CPU_X86_64              1
158         #define CPU_ID                  x86
159 #else
160         #define CPU_X86                 0
161         #define CPU_I386                0
162         #define CPU_X86_64              0
163 #endif
164
165 #if defined (_ARCH_PPC) || defined(_ARCH_PPC64)
166         #define CPU_PPC                 1
167         #define CPU_ID                  ppc
168         #if defined(_ARCH_PPC)
169                 #define CPU_PPC32       1
170         #else
171                 #define CPU_PPC32       0
172         #endif
173         #if defined(_ARCH_PPC64)
174                 #define CPU_PPC64       1
175         #else
176                 #define CPU_PPC64       0
177         #endif
178 #else
179         #define CPU_PPC                 0
180         #define CPU_PPC32               0
181         #define CPU_PPC64               0
182 #endif
183
184 #if defined(__m56800E__) || defined(__m56800__)
185         #define CPU_DSP56K              1
186         #define CPU_ID                  dsp56k
187 #else
188         #define CPU_DSP56K              0
189 #endif
190
191 #if defined (__AVR__)
192         #define CPU_AVR                 1
193         #define CPU_ID                  avr
194
195         #if defined(__AVR_ATmega32__)
196                 #define CPU_AVR_ATMEGA32    1
197         #else
198                 #define CPU_AVR_ATMEGA32    0
199         #endif
200
201         #if defined(__AVR_ATmega64__)
202                 #define CPU_AVR_ATMEGA64    1
203         #else
204                 #define CPU_AVR_ATMEGA64    0
205         #endif
206
207         #if defined(__AVR_ATmega103__)
208                 #define CPU_AVR_ATMEGA103   1
209         #else
210                 #define CPU_AVR_ATMEGA103   0
211         #endif
212
213         #if defined(__AVR_ATmega128__)
214                 #define CPU_AVR_ATMEGA128   1
215         #else
216                 #define CPU_AVR_ATMEGA128   0
217         #endif
218
219         #if defined(__AVR_ATmega8__)
220                 #define CPU_AVR_ATMEGA8     1
221         #else
222                 #define CPU_AVR_ATMEGA8     0
223         #endif
224
225         #if defined(__AVR_ATmega168__)
226                 #define CPU_AVR_ATMEGA168   1
227         #else
228                 #define CPU_AVR_ATMEGA168   0
229         #endif
230
231         #if defined(__AVR_ATmega1281__)
232                 #define CPU_AVR_ATMEGA1281  1
233         #else
234                 #define CPU_AVR_ATMEGA1281  0
235         #endif
236
237         #if CPU_AVR_ATMEGA32 + CPU_AVR_ATMEGA64 + CPU_AVR_ATMEGA103 + CPU_AVR_ATMEGA128 \
238           + CPU_AVR_ATMEGA8 + CPU_AVR_ATMEGA168 + CPU_AVR_ATMEGA1281 != 1
239                 #error AVR CPU configuration error
240         #endif
241 #else
242         #define CPU_AVR                 0
243         #define CPU_AVR_ATMEGA8         0
244         #define CPU_AVR_ATMEGA168       0
245         #define CPU_AVR_ATMEGA32        0
246         #define CPU_AVR_ATMEGA64        0
247         #define CPU_AVR_ATMEGA103       0
248         #define CPU_AVR_ATMEGA128       0
249         #define CPU_AVR_ATMEGA1281      0
250 #endif
251
252
253 /* Self-check for the detection: only one CPU must be detected */
254 #if CPU_ARM + CPU_I196 + CPU_X86 + CPU_PPC + CPU_DSP56K + CPU_AVR == 0
255         #error Unknown CPU
256 #elif !defined(CPU_ID)
257         #error CPU_ID not defined
258 #elif CPU_ARM + CPU_I196 + CPU_X86 + CPU_PPC + CPU_DSP56K + CPU_AVR != 1
259         #error Internal CPU configuration error
260 #endif
261
262
263 #endif /* CPU_DETECT_H */