3af28a1e575824a89a9d059e0e21a4cdd24f6226
[bertos.git] / cfg / cpu_detect.h
1 /**
2  * \file
3  * <!--
4  * Copyright 2004, 2005 Develer S.r.l. (http://www.develer.com/)
5  * Copyright 2004 Giovanni Bajo
6  * This file is part of DevLib - See README.devlib for information.
7  * -->
8  *
9  * \brief CPU detection through special preprocessor macros
10  *
11  */
12
13 /*#*
14  *#* $Log$
15  *#* Revision 1.6  2007/06/07 14:42:54  batt
16  *#* Merge from project_ks.
17  *#*
18  *#* Revision 1.5  2007/01/27 20:48:36  batt
19  *#* Add support for ATMEGA1281.
20  *#*
21  *#* Revision 1.4  2006/07/19 12:56:25  bernie
22  *#* Convert to new Doxygen style.
23  *#*
24  *#* Revision 1.3  2006/02/10 12:37:37  bernie
25  *#* Add support for ARM on IAR.
26  *#*
27  *#* Revision 1.2  2005/06/14 06:15:10  bernie
28  *#* Add X86_64 support.
29  *#*
30  *#* Revision 1.1  2005/04/11 19:04:13  bernie
31  *#* Move top-level headers to cfg/ subdir.
32  *#*
33  *#* Revision 1.4  2005/02/16 20:33:24  bernie
34  *#* Preliminary PPC support.
35  *#*
36  *#* Revision 1.3  2004/12/31 17:39:26  bernie
37  *#* Use C89 comments only.
38  *#*
39  *#* Revision 1.2  2004/08/25 14:12:08  rasky
40  *#* Aggiornato il comment block dei log RCS
41  *#*
42  *#* Revision 1.1  2004/07/30 17:14:49  rasky
43  *#* File sfuggito al commit precedente (nuova gestione unificata del detect della CPU
44  *#*
45  *#* Revision 1.2  2004/07/30 10:31:07  rasky
46  *#* Aggiunto detect per ATmega128
47  *#*/
48
49 #ifndef CPU_DETECT_H
50 #define CPU_DETECT_H
51
52 #if defined(__arm__) /* GCC */ \
53         || defined(__ARM4TM__) /* IAR: defined for all cores >= 4tm */
54         #define CPU_ARM                 1
55         #define CPU_ID                  arm
56 #else
57         #define CPU_ARM                 0
58 #endif
59
60 #if (defined(__IAR_SYSTEMS_ICC__) || defined(__IAR_SYSTEMS_ICC)) \
61         && !defined(__ARM4TM__) /* IAR: if not ARM assume I196 */
62         #define CPU_I196                1
63         #define CPU_ID                  i196
64 #else
65         #define CPU_I196                0
66 #endif
67
68 #if defined(__i386__) /* GCC */ \
69         || (defined(_M_IX86) && !defined(_WIN64)) /* MSVC */
70         #define CPU_X86                 1
71         #define CPU_X86_32              1
72         #define CPU_X86_64              0
73         #define CPU_ID                  x86
74 #elif defined(__x86_64__) /* GCC */ \
75         || (defined(_M_IX86) && defined(_WIN64)) /* MSVC */
76         #define CPU_X86                 1
77         #define CPU_X86_32              0
78         #define CPU_X86_64              1
79         #define CPU_ID                  x86
80 #else
81         #define CPU_X86                 0
82         #define CPU_I386                0
83         #define CPU_X86_64              0
84 #endif
85
86 #if defined (_ARCH_PPC) || defined(_ARCH_PPC64)
87         #define CPU_PPC                 1
88         #define CPU_ID                  ppc
89         #if defined(_ARCH_PPC)
90                 #define CPU_PPC32       1
91         #else
92                 #define CPU_PPC32       0
93         #endif
94         #if defined(_ARCH_PPC64)
95                 #define CPU_PPC64       1
96         #else
97                 #define CPU_PPC64       0
98         #endif
99 #else
100         #define CPU_PPC                 0
101         #define CPU_PPC32               0
102         #define CPU_PPC64               0
103 #endif
104
105 #if defined(__m56800E__) || defined(__m56800__)
106         #define CPU_DSP56K              1
107         #define CPU_ID                  dsp56k
108 #else
109         #define CPU_DSP56K              0
110 #endif
111
112 #if defined (__AVR__)
113         #define CPU_AVR                 1
114         #define CPU_ID                  avr
115
116         #if defined(__AVR_ATmega64__)
117                 #define CPU_AVR_ATMEGA64    1
118         #else
119                 #define CPU_AVR_ATMEGA64    0
120         #endif
121
122         #if defined(__AVR_ATmega103__)
123                 #define CPU_AVR_ATMEGA103   1
124         #else
125                 #define CPU_AVR_ATMEGA103   0
126         #endif
127
128         #if defined(__AVR_ATmega128__)
129                 #define CPU_AVR_ATMEGA128   1
130         #else
131                 #define CPU_AVR_ATMEGA128   0
132         #endif
133
134         #if defined(__AVR_ATmega8__)
135                 #define CPU_AVR_ATMEGA8     1
136         #else
137                 #define CPU_AVR_ATMEGA8     0
138         #endif
139
140         #if defined(__AVR_ATmega168__)
141                 #define CPU_AVR_ATMEGA168   1
142         #else
143                 #define CPU_AVR_ATMEGA168   0
144         #endif
145
146         #if defined(__AVR_ATmega1281__)
147                 #define CPU_AVR_ATMEGA1281  1
148         #else
149                 #define CPU_AVR_ATMEGA1281  0
150         #endif
151 #else
152         #define CPU_AVR                 0
153         #define CPU_AVR_ATMEGA8         0
154         #define CPU_AVR_ATMEGA168       0
155         #define CPU_AVR_ATMEGA64        0
156         #define CPU_AVR_ATMEGA103       0
157         #define CPU_AVR_ATMEGA128       0
158         #define CPU_AVR_ATMEGA1281      0
159 #endif
160
161
162 /* Self-check for the detection: only one CPU must be detected */
163 #if CPU_ARM + CPU_I196 + CPU_X86 + CPU_PPC + CPU_DSP56K + CPU_AVR == 0
164         #error Unknown CPU
165 #elif !defined(CPU_ID)
166         #error CPU_ID not defined
167 #elif CPU_ARM + CPU_I196 + CPU_X86 + CPU_PPC + CPU_DSP56K + CPU_AVR != 1
168         #error Internal CPU configuration error
169 #endif
170
171
172 #endif /* CPU_DETECT_H */