types.h
Go to the documentation of this file.
00001 00041 #ifndef CPU_TYPES_H 00042 #define CPU_TYPES_H 00043 00044 #include "detect.h" 00045 #include "attr.h" 00046 #include <limits.h> 00047 #include <cfg/compiler.h> /* for uintXX_t */ 00048 00049 #if CPU_I196 00050 00051 typedef uint16_t cpu_flags_t; // FIXME 00052 typedef unsigned int cpu_stack_t; 00053 typedef cpu_stack_t cpu_aligned_stack_t; 00054 typedef unsigned int cpu_atomic_t; 00055 #warning Verify following constant 00056 #define SIZEOF_CPUSTACK_T 2 00057 #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T 00058 00059 #elif CPU_X86 00060 00061 /* Get cpu_flags_t definition from the hosting environment. */ 00062 #include <cfg/os.h> 00063 #if OS_EMBEDDED 00064 typedef uint32_t cpu_flags_t; // FIXME 00065 #endif /* OS_EMBEDDED */ 00066 00067 typedef uint32_t cpu_atomic_t; 00068 00069 #if CPU_X86_64 00070 typedef uint64_t cpu_stack_t; 00071 typedef cpu_stack_t cpu_aligned_stack_t; 00072 #define SIZEOF_CPUSTACK_T 8 00073 #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T 00074 #else 00075 typedef uint32_t cpu_stack_t; 00076 typedef cpu_stack_t cpu_aligned_stack_t; 00077 #define SIZEOF_CPUSTACK_T 4 00078 #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T 00079 #endif 00080 00081 #elif CPU_ARM || CPU_CM3 00082 00083 typedef uint32_t cpu_flags_t; 00084 typedef uint32_t cpu_atomic_t; 00085 typedef uint32_t cpu_stack_t; 00086 #define SIZEOF_CPUSTACK_T 4 00087 00088 typedef uint64_t cpu_aligned_stack_t; 00089 #define SIZEOF_CPUALIGNED_T 8 00090 00091 #elif CPU_PPC 00092 00093 /* Get cpu_flags_t definition from the hosting environment. */ 00094 #include <cfg/os.h> 00095 #if OS_EMBEDDED 00096 typedef uint32_t cpu_flags_t; 00097 #endif 00098 00099 typedef uint32_t cpu_atomic_t; 00100 typedef uint32_t cpu_stack_t; 00101 typedef cpu_stack_t cpu_aligned_stack_t; 00102 #define SIZEOF_CPUSTACK_T 4 00103 #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T 00104 00105 #elif CPU_DSP56K 00106 00107 typedef uint16_t cpu_flags_t; 00108 typedef uint16_t cpu_atomic_t; 00109 typedef unsigned int cpu_stack_t; 00110 typedef cpu_stack_t cpu_aligned_stack_t; 00111 #warning Verify following costant 00112 #define SIZEOF_CPUSTACK_T 2 00113 #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T 00114 00115 #elif CPU_AVR 00116 00117 typedef uint8_t cpu_flags_t; 00118 typedef uint8_t cpu_atomic_t; 00119 typedef uint8_t cpu_stack_t; 00120 typedef cpu_stack_t cpu_aligned_stack_t; 00121 #define SIZEOF_CPUSTACK_T 1 00122 #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T 00123 00124 #elif CPU_MSP430 00125 00126 typedef uint16_t cpu_flags_t; 00127 typedef uint16_t cpu_stack_t; 00128 typedef cpu_stack_t cpu_aligned_stack_t; 00129 #define SIZEOF_CPUSTACK_T 2 00130 #define SIZEOF_CPUALIGNED_T SIZEOF_CPUSTACK_T 00131 00132 #else 00133 #error No CPU_... defined. 00134 #endif 00135 00153 #ifndef SIZEOF_CHAR 00154 #define SIZEOF_CHAR 1 00155 #endif 00156 00157 #ifndef SIZEOF_SHORT 00158 #define SIZEOF_SHORT 2 00159 #endif 00160 00161 #ifndef SIZEOF_INT 00162 #if CPU_REG_BITS < 32 00163 #define SIZEOF_INT 2 00164 #else 00165 #define SIZEOF_INT 4 00166 #endif 00167 #endif /* !SIZEOF_INT */ 00168 00169 #ifndef SIZEOF_LONG 00170 #if CPU_REG_BITS > 32 00171 #define SIZEOF_LONG 8 00172 #else 00173 #define SIZEOF_LONG 4 00174 #endif 00175 #endif 00176 00177 #ifndef SIZEOF_PTR 00178 #if CPU_REG_BITS < 32 00179 #define SIZEOF_PTR 2 00180 #elif CPU_REG_BITS == 32 00181 #define SIZEOF_PTR 4 00182 #else /* CPU_REG_BITS > 32 */ 00183 #define SIZEOF_PTR 8 00184 #endif 00185 #endif 00186 00187 /* 00188 * GCC doesn't provide an appropriate macro for [u]intptr_t 00189 * For now, use __PTRDIFF_TYPE__ 00190 */ 00191 #if !defined(__PTRDIFF_TYPE__) 00192 /* 00193 * uintptr_t: unsigned integer type large exactly as a pointer. 00194 */ 00195 #if SIZEOF_PTR == 2 00196 typedef uint16_t uintptr_t; 00197 #elif SIZEOF_PTR == 4 00198 typedef uint32_t uintptr_t; 00199 #elif SIZEOF_PTR == 8 00200 typedef uint64_t uintptr_t; 00201 #else 00202 #error "SIZEOF_PTR size not supported." 00203 #endif 00204 #endif 00205 00206 #ifndef SIZEOF_SIZE_T 00207 #if CPU_REG_BITS < 32 00208 #define SIZEOF_SIZE_T 2 00209 #elif CPU_REG_BITS == 32 00210 #define SIZEOF_SIZE_T 4 00211 #else /* CPU_REG_BITS > 32 */ 00212 #define SIZEOF_SIZE_T 8 00213 #endif 00214 #endif 00215 00216 #ifndef CPU_BITS_PER_CHAR 00217 #define CPU_BITS_PER_CHAR (SIZEOF_CHAR * 8) 00218 #endif 00219 00220 #ifndef CPU_BITS_PER_SHORT 00221 #define CPU_BITS_PER_SHORT (SIZEOF_SHORT * CPU_BITS_PER_CHAR) 00222 #endif 00223 00224 #ifndef CPU_BITS_PER_INT 00225 #define CPU_BITS_PER_INT (SIZEOF_INT * CPU_BITS_PER_CHAR) 00226 #endif 00227 00228 #ifndef CPU_BITS_PER_LONG 00229 #define CPU_BITS_PER_LONG (SIZEOF_LONG * CPU_BITS_PER_CHAR) 00230 #endif 00231 00232 #ifndef CPU_BITS_PER_PTR 00233 #define CPU_BITS_PER_PTR (SIZEOF_PTR * CPU_BITS_PER_CHAR) 00234 #endif 00235 00238 #ifndef INT_MAX 00239 #define INT_MAX ((int)((unsigned int)~0 >> 1)) 00240 #define INT_MIN (-INT_MAX - 1) 00241 #endif 00242 00243 /* Sanity checks for the above definitions */ 00244 STATIC_ASSERT(sizeof(char) == SIZEOF_CHAR); 00245 STATIC_ASSERT(sizeof(short) == SIZEOF_SHORT); 00246 STATIC_ASSERT(sizeof(long) == SIZEOF_LONG); 00247 STATIC_ASSERT(sizeof(int) == SIZEOF_INT); 00248 STATIC_ASSERT(sizeof(void *) == SIZEOF_PTR); 00249 STATIC_ASSERT(sizeof(int8_t) * CPU_BITS_PER_CHAR == 8); 00250 STATIC_ASSERT(sizeof(uint8_t) * CPU_BITS_PER_CHAR == 8); 00251 STATIC_ASSERT(sizeof(int16_t) * CPU_BITS_PER_CHAR == 16); 00252 STATIC_ASSERT(sizeof(uint16_t) * CPU_BITS_PER_CHAR == 16); 00253 STATIC_ASSERT(sizeof(int32_t) * CPU_BITS_PER_CHAR == 32); 00254 STATIC_ASSERT(sizeof(uint32_t) * CPU_BITS_PER_CHAR == 32); 00255 #ifdef __HAS_INT64_T__ 00256 STATIC_ASSERT(sizeof(int64_t) * CPU_BITS_PER_CHAR == 64); 00257 STATIC_ASSERT(sizeof(uint64_t) * CPU_BITS_PER_CHAR == 64); 00258 #endif 00259 STATIC_ASSERT(sizeof(cpu_stack_t) == SIZEOF_CPUSTACK_T); 00260 STATIC_ASSERT(sizeof(cpu_aligned_stack_t) == SIZEOF_CPUALIGNED_T); 00261 STATIC_ASSERT(sizeof(size_t) == SIZEOF_SIZE_T); 00262 00263 00267 /*\{*/ 00268 #define HWREG(x) (*((reg32_t *)(x))) 00269 #define HWREGH(x) (*((reg16_t *)(x))) 00270 #define HWREGB(x) (*((reg8_t *)(x))) 00271 /*\}*/ 00272 00273 #endif /* CPU_TYPES_H */
![(please configure the [header_logo] section in trac.ini)](/chrome/site/bertos_logo.png)