Contiki 2.6
|
00001 /* This file has been prepared for Doxygen automatic documentation generation.*/ 00002 /*! \file ********************************************************************* 00003 * 00004 * \brief This file includes the correct compiler definitions for the different 00005 * architectures. 00006 * 00007 * \par Documentation 00008 * For comprehensive code documentation, supported compilers, compiler 00009 * settings and supported devices see readme.html 00010 * 00011 * \author 00012 * Atmel Corporation: http://www.atmel.com \n 00013 * Support email: avr@atmel.com 00014 * 00015 * $Name: $ 00016 * $Revision: 1.1 $ 00017 * $RCSfile: compiler.h,v $ 00018 * $Date: 2008/10/14 20:16:36 $ \n 00019 * 00020 * Copyright (c) 2008, Atmel Corporation All rights reserved. 00021 * 00022 * Redistribution and use in source and binary forms, with or without 00023 * modification, are permitted provided that the following conditions are met: 00024 * 00025 * 1. Redistributions of source code must retain the above copyright notice, 00026 * this list of conditions and the following disclaimer. 00027 * 00028 * 2. Redistributions in binary form must reproduce the above copyright notice, 00029 * this list of conditions and the following disclaimer in the documentation 00030 * and/or other materials provided with the distribution. 00031 * 00032 * 3. The name of ATMEL may not be used to endorse or promote products derived 00033 * from this software without specific prior written permission. 00034 * 00035 * THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED 00036 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00037 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND 00038 * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, 00039 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00040 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00041 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00042 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00043 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 00044 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00045 ******************************************************************************/ 00046 00047 #ifndef _COMPILER_H_ 00048 #define _COMPILER_H_ 00049 00050 /*_____ I N C L U D E S ____________________________________________________*/ 00051 00052 00053 /*_____ D E C L A R A T I O N S ____________________________________________*/ 00054 #define LITTLE_ENDIAN 00055 00056 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file 00057 typedef float Float16; 00058 00059 typedef unsigned char U8 ; 00060 typedef unsigned short U16; 00061 typedef unsigned long U32; 00062 typedef signed char S8 ; 00063 typedef signed short S16; 00064 typedef long S32; 00065 #if (defined __C51__) 00066 typedef bit Bool; // Shall be used with _MEM_TYPE_BIT_ to optimize the memory. 00067 #else 00068 typedef unsigned char Bool; 00069 #endif 00070 00071 typedef U8 Status; 00072 typedef Bool Status_bool; 00073 #define PASS 0 00074 #define FAIL 1 00075 00076 00077 00078 #if (defined __C51__) 00079 # define _MEM_TYPE_BIT_ bdata // Used for bit accesses 00080 # define _MEM_TYPE_FAST_ data 00081 # define _MEM_TYPE_MEDFAST_ idata 00082 # define _MEM_TYPE_MEDSLOW_ pdata 00083 # define _MEM_TYPE_SLOW_ xdata 00084 #else 00085 # define _MEM_TYPE_BIT_ 00086 # define _MEM_TYPE_FAST_ 00087 # define _MEM_TYPE_MEDFAST_ 00088 # define _MEM_TYPE_MEDSLOW_ 00089 # define _MEM_TYPE_SLOW_ 00090 #endif 00091 00092 typedef unsigned char Uchar; 00093 00094 00095 typedef unsigned char Uint8; 00096 typedef unsigned int Uint16; 00097 typedef unsigned long int Uint32; 00098 00099 typedef char Int8; 00100 typedef int Int16; 00101 typedef long int Int32; 00102 00103 typedef unsigned char Byte; 00104 typedef unsigned int Word; 00105 typedef unsigned long int DWord; 00106 00107 typedef union 00108 { 00109 Uint32 dw; // l changed in dw (double word) because l is used for signed long... 00110 Uint16 w[2]; 00111 Uint8 b[4]; 00112 } Union32; 00113 00114 typedef union 00115 { 00116 Uint16 w; 00117 Uint8 b[2]; 00118 } Union16; 00119 00120 #ifdef __IAR_SYSTEMS_ICC__ 00121 typedef char bit; 00122 typedef int p_uart_ptchar; 00123 typedef int r_uart_ptchar; 00124 #endif 00125 #ifdef __CODEVISIONAVR__ 00126 typedef char bit; 00127 typedef int p_uart_ptchar; 00128 typedef char r_uart_ptchar; 00129 #endif 00130 #if !defined(__IAR_SYSTEMS_ICC__) && !defined(___ICC__) 00131 typedef char p_uart_ptchar; 00132 typedef char r_uart_ptchar; 00133 #endif 00134 00135 #endif 00136 00137 /**********************************************************************************/ 00138 /* codevision COMPILER (__CODEVISIONAVR__) */ 00139 /**********************************************************************************/ 00140 #ifdef __ICC__ 00141 #define _ConstType_ lit 00142 #define _MemType_ 00143 #define _GenericType_ __generic 00144 #define FLASH lit 00145 #define XDATA 00146 #define IDATA 00147 #define DATA 00148 #endif 00149 /**********************************************************************************/ 00150 /* IAR COMPILER (__IAR_SYSTEMS_ICC__) */ 00151 /**********************************************************************************/ 00152 #ifdef __IAR_SYSTEMS_ICC__ 00153 #include "inavr.h" 00154 #define _ConstType_ __flash 00155 #define _MemType_ 00156 #define _GenericType_ __generic 00157 #define FLASH __flash 00158 #define FARFLASH __farflash 00159 #define XDATA 00160 #define IDATA 00161 #define DATA 00162 #define At(x) @ x 00163 #define PDATA 00164 #define BDATA 00165 // Memory Type Location 00166 #ifndef _CONST_TYPE_ 00167 # define _CONST_TYPE_ code 00168 #endif 00169 00170 #define Enable_interrupt() __enable_interrupt() 00171 #define Disable_interrupt() __disable_interrupt() 00172 00173 #include <iomacro.h> 00174 #define SFR_W_EXT(a,b) SFR_W_R(b,a) 00175 #endif 00176 00177 00178 /* General purpose defines */ 00179 /*#define _ConstType_ __farflash 00180 #define _MemType_ 00181 #define _GenericType_ __generic 00182 #define code __farflash 00183 #define xdata 00184 #define idata 00185 #define data*/ 00186 00187 00188 00189 00190 /*_____ M A C R O S ________________________________________________________*/ 00191 /* little-big endian management */ 00192 #define INTEL_ALIGNMENT LITTLE_ENDIAN 00193 #define MOTOROLA_ALIGNMENT BIG_ENDIAN 00194 00195 // U16/U32 endian handlers 00196 #ifdef LITTLE_ENDIAN // => 16bit: (LSB,MSB), 32bit: (LSW,MSW) or (LSB0,LSB1,LSB2,LSB3) or (MSB3,MSB2,MSB1,MSB0) 00197 # define MSB(u16) (((U8* )&u16)[1]) 00198 # define LSB(u16) (((U8* )&u16)[0]) 00199 # define MSW(u32) (((U16*)&u32)[1]) 00200 # define LSW(u32) (((U16*)&u32)[0]) 00201 # define MSB0(u32) (((U8* )&u32)[3]) 00202 # define MSB1(u32) (((U8* )&u32)[2]) 00203 # define MSB2(u32) (((U8* )&u32)[1]) 00204 # define MSB3(u32) (((U8* )&u32)[0]) 00205 # define LSB0(u32) MSB3(u32) 00206 # define LSB1(u32) MSB2(u32) 00207 # define LSB2(u32) MSB1(u32) 00208 # define LSB3(u32) MSB0(u32) 00209 #else // BIG_ENDIAN => 16bit: (MSB,LSB), 32bit: (MSW,LSW) or (LSB3,LSB2,LSB1,LSB0) or (MSB0,MSB1,MSB2,MSB3) 00210 # define MSB(u16) (((U8* )&u16)[0]) 00211 # define LSB(u16) (((U8* )&u16)[1]) 00212 # define MSW(u32) (((U16*)&u32)[0]) 00213 # define LSW(u32) (((U16*)&u32)[1]) 00214 # define MSB0(u32) (((U8* )&u32)[0]) 00215 # define MSB1(u32) (((U8* )&u32)[1]) 00216 # define MSB2(u32) (((U8* )&u32)[2]) 00217 # define MSB3(u32) (((U8* )&u32)[3]) 00218 # define LSB0(u32) MSB3(u32) 00219 # define LSB1(u32) MSB2(u32) 00220 # define LSB2(u32) MSB1(u32) 00221 # define LSB3(u32) MSB0(u32) 00222 #endif 00223 00224 // Endian converters 00225 #define Le16(b) \ 00226 ( ((U16)( (b) & 0xFF) << 8) \ 00227 | ( ((U16)(b) & 0xFF00) >> 8) \ 00228 ) 00229 #define Le32(b) \ 00230 ( ((U32)( (b) & 0xFF) << 24) \ 00231 | ((U32)((U16)(b) & 0xFF00) << 8) \ 00232 | ( ((U32)(b) & 0xFF0000) >> 8) \ 00233 | ( ((U32)(b) & 0xFF000000) >> 24) \ 00234 ) 00235 00236 // host to network conversion: used for Intel HEX format, TCP/IP, ... 00237 // Convert a 16-bit value from host-byte order to network-byte order 00238 // Standard Unix, POSIX 1003.1g (draft) 00239 00240 /* 00241 #ifdef LITTLE_ENDIAN 00242 # define htons(a) Le16(a) 00243 #define ntohs(a) htons(a) 00244 # define htonl(a) Le32(a) 00245 #define ntohl(a) htonl(a) 00246 #else 00247 #define htons(a) (a) 00248 #define ntohs(a) (a) 00249 #define htonl(a) (a) 00250 #define ntohl(a) (a) 00251 #endif 00252 */ 00253 00254 // Constants 00255 #define ENABLE 1 00256 #define ENABLED 1 00257 #define DISABLED 0 00258 #define DISABLE 0 00259 #define FALSE (0==1) 00260 #define TRUE (1==1) 00261 00262 #define KO 0 00263 #define OK 1 00264 #define OFF 0 00265 #define ON 1 00266 #ifndef NULL 00267 #define NULL 0 00268 #endif 00269 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file 00270 #define CLR 0 00271 #define SET 1 00272 #endif 00273 00274 /* Bit and bytes manipulations */ 00275 #define LOW(U16) ((Uchar)U16) 00276 #define HIGH(U16) ((Uchar)(U16>>8)) 00277 #define TST_BIT_X(addrx,mask) (*addrx & mask) 00278 #define SET_BIT_X(addrx,mask) (*addrx = (*addrx | mask)) 00279 #define CLR_BIT_X(addrx,mask) (*addrx = (*addrx & ~mask)) 00280 #define OUT_X(addrx,value) (*addrx = value) 00281 #define IN_X(addrx) (*addrx) 00282 00283 # define Max(a, b) ( (a)>(b) ? (a) : (b) ) // Take the max between a and b 00284 # define Min(a, b) ( (a)<(b) ? (a) : (b) ) // Take the min between a and b 00285 00286 // Align on the upper value <val> on a <n> boundary 00287 // i.e. Upper(0, 4)= 4 00288 // Upper(1, 4)= 4 00289 // Upper(2, 4)= 4 00290 // Upper(3, 4)= 4 00291 // Upper(4, 4)= 8 00292 // ../.. 00293 # define Upper(val, n) ( ((val)+(n)) & ~((n)-1) ) 00294 00295 // Align up <val> on a <n> boundary 00296 // i.e. Align_up(0, 4)= 0 00297 // Align_up(1, 4)= 4 00298 // Align_up(2, 4)= 4 00299 // Align_up(3, 4)= 4 00300 // Align_up(4, 4)= 4 00301 // ../.. 00302 # define Align_up(val, n) ( ((val)+(n)-1) & ~((n)-1) ) 00303 00304 // Align down <val> on a <n> boundary 00305 // i.e. Align_down(0, 4)= 0 00306 // Align_down(1, 4)= 0 00307 // Align_down(2, 4)= 0 00308 // Align_down(3, 4)= 0 00309 // Align_down(4, 4)= 4 00310 // ../.. 00311 # define Align_down(val, n) ( (val) & ~((n)-1) ) 00312 00313 /* {For Langdoc} */ 00314 00315 /*********************************************************** 00316 SET_SFR_BIT macro 00317 parameters 00318 sfr_reg : defined value in include file for sfr register 00319 bit_pos : defined value B_XX in include file for particular 00320 bit of sfr register 00321 bit_val : CLR / SET 00322 ************************************************************/ 00323 #define SET_SFR_BIT(sfr_reg, bit_pos, bit_val) { sfr_reg &= ~(1<<(bit_pos)); sfr_reg |= ((bit_val)<<(bit_pos));} 00324 00325 #define TID_GUARD(proc) ((__TID__ & 0x7FF0) != ((90 << 8) | ((proc) << 4))) 00326 00327 /******************************************************************************/ 00328 /* GCC COMPILER */ 00329 /******************************************************************************/ 00330 #ifdef AVRGCC 00331 #define _CONST_TYPE_ 00332 #define _ConstType_ __flash 00333 #define _MemType_ 00334 #define _GenericType_ __generic 00335 #define FLASH const PROGMEM 00336 #define XDATA 00337 #define IDATA 00338 #define DATA 00339 #define At(x) @ x 00340 #define PDATA 00341 #define BDATA 00342 #define bit U8 00343 //#include <avr/sfr_defs.h> 00344 #include <avr/interrupt.h> 00345 #include <avr/pgmspace.h> 00346 #define Enable_interrupt() sei() 00347 #define Disable_interrupt() cli() 00348 00349 #endif 00350 #endif /* _COMPILER_H_ */ 00351