BeRTOS
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 #ifndef SIZEOF_SIZE_T
00188 #if CPU_REG_BITS < 32
00189     #define SIZEOF_SIZE_T   2
00190 #elif CPU_REG_BITS == 32
00191     #define SIZEOF_SIZE_T   4
00192 #else /* CPU_REG_BITS > 32 */
00193     #define SIZEOF_SIZE_T   8
00194 #endif
00195 #endif
00196 
00197 #ifndef CPU_BITS_PER_CHAR
00198 #define CPU_BITS_PER_CHAR   (SIZEOF_CHAR * 8)
00199 #endif
00200 
00201 #ifndef CPU_BITS_PER_SHORT
00202 #define CPU_BITS_PER_SHORT  (SIZEOF_SHORT * CPU_BITS_PER_CHAR)
00203 #endif
00204 
00205 #ifndef CPU_BITS_PER_INT
00206 #define CPU_BITS_PER_INT    (SIZEOF_INT * CPU_BITS_PER_CHAR)
00207 #endif
00208 
00209 #ifndef CPU_BITS_PER_LONG
00210 #define CPU_BITS_PER_LONG   (SIZEOF_LONG * CPU_BITS_PER_CHAR)
00211 #endif
00212 
00213 #ifndef CPU_BITS_PER_PTR
00214 #define CPU_BITS_PER_PTR    (SIZEOF_PTR * CPU_BITS_PER_CHAR)
00215 #endif
00216 
00217 
00218 /*\}*/
00219 
00220 #ifndef INT_MAX
00221     #define INT_MAX ((int)((unsigned int)~0 >> 1))
00222     #define INT_MIN (-INT_MAX - 1)
00223 #endif
00224 
00225 /* Sanity checks for the above definitions */
00226 STATIC_ASSERT(sizeof(char) == SIZEOF_CHAR);
00227 STATIC_ASSERT(sizeof(short) == SIZEOF_SHORT);
00228 STATIC_ASSERT(sizeof(long) == SIZEOF_LONG);
00229 STATIC_ASSERT(sizeof(int) == SIZEOF_INT);
00230 STATIC_ASSERT(sizeof(void *) == SIZEOF_PTR);
00231 STATIC_ASSERT(sizeof(int8_t) * CPU_BITS_PER_CHAR == 8);
00232 STATIC_ASSERT(sizeof(uint8_t) * CPU_BITS_PER_CHAR == 8);
00233 STATIC_ASSERT(sizeof(int16_t) * CPU_BITS_PER_CHAR == 16);
00234 STATIC_ASSERT(sizeof(uint16_t) * CPU_BITS_PER_CHAR == 16);
00235 STATIC_ASSERT(sizeof(int32_t) * CPU_BITS_PER_CHAR == 32);
00236 STATIC_ASSERT(sizeof(uint32_t) * CPU_BITS_PER_CHAR == 32);
00237 #ifdef __HAS_INT64_T__
00238 STATIC_ASSERT(sizeof(int64_t) * CPU_BITS_PER_CHAR == 64);
00239 STATIC_ASSERT(sizeof(uint64_t) * CPU_BITS_PER_CHAR == 64);
00240 #endif
00241 STATIC_ASSERT(sizeof(cpu_stack_t) == SIZEOF_CPUSTACK_T);
00242 STATIC_ASSERT(sizeof(cpu_aligned_stack_t) == SIZEOF_CPUALIGNED_T);
00243 STATIC_ASSERT(sizeof(size_t) == SIZEOF_SIZE_T);
00244 
00245 
00249 /*\{*/
00250 #define HWREG(x)   (*((reg32_t *)(x)))
00251 #define HWREGH(x)  (*((reg16_t *)(x)))
00252 #define HWREGB(x)  (*((reg8_t *)(x)))
00253 /*\}*/
00254 
00255 #endif /* CPU_TYPES_H */