compiler.h

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

Generated on Mon May 5 15:57:54 2008 for ATMEL by  doxygen 1.5.1-p1