rename cpuXXX_t to cpu_XXX_t
[bertos.git] / bertos / cpu / types.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-specific type definitions.
35  *
36  * \author Giovanni Bajo <rasky@develer.com>
37  * \author Bernie Innocenti <bernie@codewiz.org>
38  * \author Stefano Fedrigo <aleph@develer.com>
39  * \author Francesco Sacchi <batt@develer.com>
40  */
41 #ifndef CPU_TYPES_H
42 #define CPU_TYPES_H
43
44 #include "detect.h"
45 #include "attr.h"
46 #include <cfg/compiler.h> /* for uintXX_t */
47
48 #if CPU_I196
49
50         typedef uint16_t cpu_flags_t; // FIXME
51         typedef unsigned int cpu_stack_t;
52         typedef unsigned int cpu_atomic_t;
53         #warning Verify following constant
54         #define SIZEOF_CPUSTACK_T 2
55
56 #elif CPU_X86
57
58         /* Get cpu_flags_t definition from the hosting environment. */
59         #include <cfg/os.h>
60         #if OS_EMBEDDED
61                 typedef uint32_t cpu_flags_t; // FIXME
62         #endif /* OS_EMBEDDED */
63
64         typedef uint32_t cpu_atomic_t;
65
66         #if CPU_X86_64
67                 typedef uint64_t cpu_stack_t;
68                 #define SIZEOF_CPUSTACK_T 8
69         #else
70                 typedef uint32_t cpu_stack_t;
71                 #define SIZEOF_CPUSTACK_T 4
72         #endif
73
74 #elif CPU_ARM
75
76         typedef uint32_t cpu_flags_t;
77         typedef uint32_t cpu_atomic_t;
78         typedef uint32_t cpu_stack_t;
79         #define SIZEOF_CPUSTACK_T 4
80
81 #elif CPU_PPC
82
83         /* Get cpu_flags_t definition from the hosting environment. */
84         #include <cfg/os.h>
85         #if OS_EMBEDDED
86                 typedef uint32_t cpu_flags_t;
87         #endif
88
89         typedef uint32_t cpu_atomic_t;
90         typedef uint32_t cpu_stack_t;
91         #define SIZEOF_CPUSTACK_T 4
92
93 #elif CPU_DSP56K
94
95         typedef uint16_t cpu_flags_t;
96         typedef uint16_t cpu_atomic_t;
97         typedef unsigned int cpu_stack_t;
98         #warning Verify following costant
99         #define SIZEOF_CPUSTACK_T 2
100
101 #elif CPU_AVR
102
103         typedef uint8_t cpu_flags_t;
104         typedef uint8_t cpu_atomic_t;
105         typedef uint8_t cpu_stack_t;
106         #define SIZEOF_CPUSTACK_T 1
107
108 #else
109         #error No CPU_... defined.
110 #endif
111
112 /**
113  * \name Default type sizes.
114  *
115  * These defaults are reasonable for most 16/32bit machines.
116  * Some of these macros may be overridden by CPU-specific code above.
117  *
118  * ANSI C requires that the following equations be true:
119  * \code
120  *   sizeof(char) <= sizeof(short) <= sizeof(int) <= sizeof(long)
121  *   sizeof(float) <= sizeof(double)
122  *   CPU_BITS_PER_CHAR  >= 8
123  *   CPU_BITS_PER_SHORT >= 8
124  *   CPU_BITS_PER_INT   >= 16
125  *   CPU_BITS_PER_LONG  >= 32
126  * \endcode
127  * \{
128  */
129 #ifndef SIZEOF_CHAR
130 #define SIZEOF_CHAR  1
131 #endif
132
133 #ifndef SIZEOF_SHORT
134 #define SIZEOF_SHORT  2
135 #endif
136
137 #ifndef SIZEOF_INT
138 #if CPU_REG_BITS < 32
139         #define SIZEOF_INT  2
140 #else
141         #define SIZEOF_INT  4
142 #endif
143 #endif /* !SIZEOF_INT */
144
145 #ifndef SIZEOF_LONG
146 #if CPU_REG_BITS > 32
147         #define SIZEOF_LONG  8
148 #else
149         #define SIZEOF_LONG  4
150 #endif
151 #endif
152
153 #ifndef SIZEOF_PTR
154 #if CPU_REG_BITS < 32
155         #define SIZEOF_PTR   2
156 #elif CPU_REG_BITS == 32
157         #define SIZEOF_PTR   4
158 #else /* CPU_REG_BITS > 32 */
159         #define SIZEOF_PTR   8
160 #endif
161 #endif
162
163 #ifndef CPU_BITS_PER_CHAR
164 #define CPU_BITS_PER_CHAR   (SIZEOF_CHAR * 8)
165 #endif
166
167 #ifndef CPU_BITS_PER_SHORT
168 #define CPU_BITS_PER_SHORT  (SIZEOF_SHORT * CPU_BITS_PER_CHAR)
169 #endif
170
171 #ifndef CPU_BITS_PER_INT
172 #define CPU_BITS_PER_INT    (SIZEOF_INT * CPU_BITS_PER_CHAR)
173 #endif
174
175 #ifndef CPU_BITS_PER_LONG
176 #define CPU_BITS_PER_LONG   (SIZEOF_LONG * CPU_BITS_PER_CHAR)
177 #endif
178
179 #ifndef CPU_BITS_PER_PTR
180 #define CPU_BITS_PER_PTR    (SIZEOF_PTR * CPU_BITS_PER_CHAR)
181 #endif
182
183
184 /*\}*/
185
186 /* Sanity checks for the above definitions */
187 STATIC_ASSERT(sizeof(char) == SIZEOF_CHAR);
188 STATIC_ASSERT(sizeof(short) == SIZEOF_SHORT);
189 STATIC_ASSERT(sizeof(long) == SIZEOF_LONG);
190 STATIC_ASSERT(sizeof(int) == SIZEOF_INT);
191 STATIC_ASSERT(sizeof(void *) == SIZEOF_PTR);
192 STATIC_ASSERT(sizeof(int8_t) * CPU_BITS_PER_CHAR == 8);
193 STATIC_ASSERT(sizeof(uint8_t) * CPU_BITS_PER_CHAR == 8);
194 STATIC_ASSERT(sizeof(int16_t) * CPU_BITS_PER_CHAR == 16);
195 STATIC_ASSERT(sizeof(uint16_t) * CPU_BITS_PER_CHAR == 16);
196 STATIC_ASSERT(sizeof(int32_t) * CPU_BITS_PER_CHAR == 32);
197 STATIC_ASSERT(sizeof(uint32_t) * CPU_BITS_PER_CHAR == 32);
198 #ifdef __HAS_INT64_T__
199 STATIC_ASSERT(sizeof(int64_t) * CPU_BITS_PER_CHAR == 64);
200 STATIC_ASSERT(sizeof(uint64_t) * CPU_BITS_PER_CHAR == 64);
201 #endif
202 STATIC_ASSERT(sizeof(cpu_stack_t) == SIZEOF_CPUSTACK_T);
203
204
205 #endif /* CPU_TYPES_H */