Contiki 2.5
compiler.h
Go to the documentation of this file.
1 /* This file has been prepared for Doxygen automatic documentation generation.*/
2 /*! \file *********************************************************************
3  *
4  * \brief This file includes the correct compiler definitions for the different
5  * architectures.
6  *
7  * \par Documentation
8  * For comprehensive code documentation, supported compilers, compiler
9  * settings and supported devices see readme.html
10  *
11  * \author
12  * Atmel Corporation: http://www.atmel.com \n
13  * Support email: avr@atmel.com
14  *
15  * $Name: $
16  * $Revision: 1.1 $
17  * $RCSfile: compiler.h,v $
18  * $Date: 2008/10/14 20:16:36 $ \n
19  *
20  * Copyright (c) 2008, Atmel Corporation All rights reserved.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions are met:
24  *
25  * 1. Redistributions of source code must retain the above copyright notice,
26  * this list of conditions and the following disclaimer.
27  *
28  * 2. Redistributions in binary form must reproduce the above copyright notice,
29  * this list of conditions and the following disclaimer in the documentation
30  * and/or other materials provided with the distribution.
31  *
32  * 3. The name of ATMEL may not be used to endorse or promote products derived
33  * from this software without specific prior written permission.
34  *
35  * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
36  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
37  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
38  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
39  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
41  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
42  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
43  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
44  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  ******************************************************************************/
46 
47 #ifndef _COMPILER_H_
48 #define _COMPILER_H_
49 
50 /*_____ I N C L U D E S ____________________________________________________*/
51 
52 
53 /*_____ D E C L A R A T I O N S ____________________________________________*/
54 #define LITTLE_ENDIAN
55 
56 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file
57 typedef float Float16;
58 
59 typedef unsigned char U8 ;
60 typedef unsigned short U16;
61 typedef unsigned long U32;
62 typedef signed char S8 ;
63 typedef signed short S16;
64 typedef long S32;
65 #if (defined __C51__)
66 typedef bit Bool; // Shall be used with _MEM_TYPE_BIT_ to optimize the memory.
67 #else
68 typedef unsigned char Bool;
69 #endif
70 
71 typedef U8 Status;
72 typedef Bool Status_bool;
73 #define PASS 0
74 #define FAIL 1
75 
76 
77 
78 #if (defined __C51__)
79 # define _MEM_TYPE_BIT_ bdata // Used for bit accesses
80 # define _MEM_TYPE_FAST_ data
81 # define _MEM_TYPE_MEDFAST_ idata
82 # define _MEM_TYPE_MEDSLOW_ pdata
83 # define _MEM_TYPE_SLOW_ xdata
84 #else
85 # define _MEM_TYPE_BIT_
86 # define _MEM_TYPE_FAST_
87 # define _MEM_TYPE_MEDFAST_
88 # define _MEM_TYPE_MEDSLOW_
89 # define _MEM_TYPE_SLOW_
90 #endif
91 
92 typedef unsigned char Uchar;
93 
94 
95 typedef unsigned char Uint8;
96 typedef unsigned int Uint16;
97 typedef unsigned long int Uint32;
98 
99 typedef char Int8;
100 typedef int Int16;
101 typedef long int Int32;
102 
103 typedef unsigned char Byte;
104 typedef unsigned int Word;
105 typedef unsigned long int DWord;
106 
107 typedef union
108 {
109  Uint32 dw; // l changed in dw (double word) because l is used for signed long...
110  Uint16 w[2];
111  Uint8 b[4];
112 } Union32;
113 
114 typedef union
115 {
116  Uint16 w;
117  Uint8 b[2];
118 } Union16;
119 
120 #ifdef __IAR_SYSTEMS_ICC__
121 typedef char bit;
122 typedef int p_uart_ptchar;
123 typedef int r_uart_ptchar;
124 #endif
125 #ifdef __CODEVISIONAVR__
126 typedef char bit;
127 typedef int p_uart_ptchar;
128 typedef char r_uart_ptchar;
129 #endif
130 #if !defined(__IAR_SYSTEMS_ICC__) && !defined(___ICC__)
131 typedef char p_uart_ptchar;
132 typedef char r_uart_ptchar;
133 #endif
134 
135 #endif
136 
137 /**********************************************************************************/
138 /* codevision COMPILER (__CODEVISIONAVR__) */
139 /**********************************************************************************/
140 #ifdef __ICC__
141 #define _ConstType_ lit
142 #define _MemType_
143 #define _GenericType_ __generic
144 #define FLASH lit
145 #define XDATA
146 #define IDATA
147 #define DATA
148 #endif
149 /**********************************************************************************/
150 /* IAR COMPILER (__IAR_SYSTEMS_ICC__) */
151 /**********************************************************************************/
152 #ifdef __IAR_SYSTEMS_ICC__
153 #include "inavr.h"
154 #define _ConstType_ __flash
155 #define _MemType_
156 #define _GenericType_ __generic
157 #define FLASH __flash
158 #define FARFLASH __farflash
159 #define XDATA
160 #define IDATA
161 #define DATA
162 #define At(x) @ x
163 #define PDATA
164 #define BDATA
165 // Memory Type Location
166 #ifndef _CONST_TYPE_
167 # define _CONST_TYPE_ code
168 #endif
169 
170 #define Enable_interrupt() __enable_interrupt()
171 #define Disable_interrupt() __disable_interrupt()
172 
173 #include <iomacro.h>
174 #define SFR_W_EXT(a,b) SFR_W_R(b,a)
175 #endif
176 
177 
178 /* General purpose defines */
179 /*#define _ConstType_ __farflash
180 #define _MemType_
181 #define _GenericType_ __generic
182 #define code __farflash
183 #define xdata
184 #define idata
185 #define data*/
186 
187 
188 
189 
190 /*_____ M A C R O S ________________________________________________________*/
191 /* little-big endian management */
192 #define INTEL_ALIGNMENT LITTLE_ENDIAN
193 #define MOTOROLA_ALIGNMENT BIG_ENDIAN
194 
195 // U16/U32 endian handlers
196 #ifdef LITTLE_ENDIAN // => 16bit: (LSB,MSB), 32bit: (LSW,MSW) or (LSB0,LSB1,LSB2,LSB3) or (MSB3,MSB2,MSB1,MSB0)
197 # define MSB(u16) (((U8* )&u16)[1])
198 # define LSB(u16) (((U8* )&u16)[0])
199 # define MSW(u32) (((U16*)&u32)[1])
200 # define LSW(u32) (((U16*)&u32)[0])
201 # define MSB0(u32) (((U8* )&u32)[3])
202 # define MSB1(u32) (((U8* )&u32)[2])
203 # define MSB2(u32) (((U8* )&u32)[1])
204 # define MSB3(u32) (((U8* )&u32)[0])
205 # define LSB0(u32) MSB3(u32)
206 # define LSB1(u32) MSB2(u32)
207 # define LSB2(u32) MSB1(u32)
208 # define LSB3(u32) MSB0(u32)
209 #else // BIG_ENDIAN => 16bit: (MSB,LSB), 32bit: (MSW,LSW) or (LSB3,LSB2,LSB1,LSB0) or (MSB0,MSB1,MSB2,MSB3)
210 # define MSB(u16) (((U8* )&u16)[0])
211 # define LSB(u16) (((U8* )&u16)[1])
212 # define MSW(u32) (((U16*)&u32)[0])
213 # define LSW(u32) (((U16*)&u32)[1])
214 # define MSB0(u32) (((U8* )&u32)[0])
215 # define MSB1(u32) (((U8* )&u32)[1])
216 # define MSB2(u32) (((U8* )&u32)[2])
217 # define MSB3(u32) (((U8* )&u32)[3])
218 # define LSB0(u32) MSB3(u32)
219 # define LSB1(u32) MSB2(u32)
220 # define LSB2(u32) MSB1(u32)
221 # define LSB3(u32) MSB0(u32)
222 #endif
223 
224 // Endian converters
225 #define Le16(b) \
226  ( ((U16)( (b) & 0xFF) << 8) \
227  | ( ((U16)(b) & 0xFF00) >> 8) \
228  )
229 #define Le32(b) \
230  ( ((U32)( (b) & 0xFF) << 24) \
231  | ((U32)((U16)(b) & 0xFF00) << 8) \
232  | ( ((U32)(b) & 0xFF0000) >> 8) \
233  | ( ((U32)(b) & 0xFF000000) >> 24) \
234  )
235 
236 // host to network conversion: used for Intel HEX format, TCP/IP, ...
237 // Convert a 16-bit value from host-byte order to network-byte order
238 // Standard Unix, POSIX 1003.1g (draft)
239 
240 /*
241 #ifdef LITTLE_ENDIAN
242 # define htons(a) Le16(a)
243 #define ntohs(a) htons(a)
244 # define htonl(a) Le32(a)
245 #define ntohl(a) htonl(a)
246 #else
247 #define htons(a) (a)
248 #define ntohs(a) (a)
249 #define htonl(a) (a)
250 #define ntohl(a) (a)
251 #endif
252 */
253 
254 // Constants
255 #define ENABLE 1
256 #define ENABLED 1
257 #define DISABLED 0
258 #define DISABLE 0
259 #define FALSE (0==1)
260 #define TRUE (1==1)
261 
262 #define KO 0
263 #define OK 1
264 #define OFF 0
265 #define ON 1
266 #ifndef NULL
267 #define NULL 0
268 #endif
269 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file
270 #define CLR 0
271 #define SET 1
272 #endif
273 
274 /* Bit and bytes manipulations */
275 #define LOW(U16) ((Uchar)U16)
276 #define HIGH(U16) ((Uchar)(U16>>8))
277 #define TST_BIT_X(addrx,mask) (*addrx & mask)
278 #define SET_BIT_X(addrx,mask) (*addrx = (*addrx | mask))
279 #define CLR_BIT_X(addrx,mask) (*addrx = (*addrx & ~mask))
280 #define OUT_X(addrx,value) (*addrx = value)
281 #define IN_X(addrx) (*addrx)
282 
283 # define Max(a, b) ( (a)>(b) ? (a) : (b) ) // Take the max between a and b
284 # define Min(a, b) ( (a)<(b) ? (a) : (b) ) // Take the min between a and b
285 
286 // Align on the upper value <val> on a <n> boundary
287 // i.e. Upper(0, 4)= 4
288 // Upper(1, 4)= 4
289 // Upper(2, 4)= 4
290 // Upper(3, 4)= 4
291 // Upper(4, 4)= 8
292 // ../..
293 # define Upper(val, n) ( ((val)+(n)) & ~((n)-1) )
294 
295 // Align up <val> on a <n> boundary
296 // i.e. Align_up(0, 4)= 0
297 // Align_up(1, 4)= 4
298 // Align_up(2, 4)= 4
299 // Align_up(3, 4)= 4
300 // Align_up(4, 4)= 4
301 // ../..
302 # define Align_up(val, n) ( ((val)+(n)-1) & ~((n)-1) )
303 
304 // Align down <val> on a <n> boundary
305 // i.e. Align_down(0, 4)= 0
306 // Align_down(1, 4)= 0
307 // Align_down(2, 4)= 0
308 // Align_down(3, 4)= 0
309 // Align_down(4, 4)= 4
310 // ../..
311 # define Align_down(val, n) ( (val) & ~((n)-1) )
312 
313 /* {For Langdoc} */
314 
315 /***********************************************************
316  SET_SFR_BIT macro
317  parameters
318  sfr_reg : defined value in include file for sfr register
319  bit_pos : defined value B_XX in include file for particular
320  bit of sfr register
321  bit_val : CLR / SET
322 ************************************************************/
323 #define SET_SFR_BIT(sfr_reg, bit_pos, bit_val) { sfr_reg &= ~(1<<(bit_pos)); sfr_reg |= ((bit_val)<<(bit_pos));}
324 
325 #define TID_GUARD(proc) ((__TID__ & 0x7FF0) != ((90 << 8) | ((proc) << 4)))
326 
327 /******************************************************************************/
328 /* GCC COMPILER */
329 /******************************************************************************/
330  #ifdef AVRGCC
331 #define _CONST_TYPE_
332 #define _ConstType_ __flash
333 #define _MemType_
334 #define _GenericType_ __generic
335 #define FLASH PROGMEM
336 #define XDATA
337 #define IDATA
338 #define DATA
339 #define At(x) @ x
340 #define PDATA
341 #define BDATA
342 #define bit U8
343  //#include <avr/sfr_defs.h>
344  #include <avr/interrupt.h>
345  #include <avr/pgmspace.h>
346  #define Enable_interrupt() sei()
347  #define Disable_interrupt() cli()
348 
349  #endif
350 #endif /* _COMPILER_H_ */
351