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