compiler.h

Go to the documentation of this file.
00001 /*H**************************************************************************
00002 * NAME:         compiler.h
00003 *----------------------------------------------------------------------------
00004 * Copyright (c) 2006 Atmel.
00005 *----------------------------------------------------------------------------
00006 * RELEASE:      at90usb162-cdc-1_0_1
00007 * FILE_REV:     1.13.2.28
00008 *----------------------------------------------------------------------------
00009 * PURPOSE:
00010 * This file redefines dedicated IAR AVR
00011 * keywords in order to ensure that any source file can be processed by
00012 * these compilers.
00013 *****************************************************************************/
00014 
00015 #ifndef _COMPILER_H_
00016 #define _COMPILER_H_
00017 
00018 /*_____ I N C L U D E S ____________________________________________________*/
00019 
00020 
00021 /*_____ D E C L A R A T I O N S ____________________________________________*/
00022 #define LITTLE_ENDIAN
00023 
00024 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file
00025 typedef float               Float16;
00026 
00027 typedef unsigned char       U8 ;
00028 typedef unsigned short      U16;
00029 typedef unsigned long       U32;
00030 typedef signed char         S8 ;
00031 typedef signed short        S16;
00032 typedef long                S32;
00033 #if (defined __C51__)
00034 typedef bit                 Bool;    // Shall be used with _MEM_TYPE_BIT_ to optimize the memory.
00035 #else
00036 typedef unsigned char       Bool;
00037 #endif
00038 
00039 typedef U8                  Status;
00040 typedef Bool                Status_bool;
00041 #define PASS 0
00042 #define FAIL 1
00043 
00044 
00045 
00046 #if (defined __C51__)
00047 #  define _MEM_TYPE_BIT_              bdata  // Used for bit accesses
00048 #  define _MEM_TYPE_FAST_              data
00049 #  define _MEM_TYPE_MEDFAST_          idata
00050 #  define _MEM_TYPE_MEDSLOW_          pdata
00051 #  define _MEM_TYPE_SLOW_             xdata
00052 #else
00053 #  define _MEM_TYPE_BIT_
00054 #  define _MEM_TYPE_FAST_
00055 #  define _MEM_TYPE_MEDFAST_
00056 #  define _MEM_TYPE_MEDSLOW_
00057 #  define _MEM_TYPE_SLOW_
00058 #endif
00059 
00060 typedef unsigned char       Uchar;
00061 
00062 
00063 typedef unsigned char       Uint8;
00064 typedef unsigned int        Uint16;
00065 typedef unsigned long int   Uint32;
00066 
00067 typedef char                Int8;
00068 typedef int                 Int16;
00069 typedef long int            Int32;
00070 
00071 typedef unsigned char       Byte;
00072 typedef unsigned int        Word;
00073 typedef unsigned long int   DWord;
00074 
00075 typedef union
00076 {
00077   Uint32 dw; // l changed in dw (double word) because l is used for signed long...
00078   Uint16 w[2];
00079   Uint8  b[4];
00080 } Union32;
00081 
00082 typedef union
00083 {
00084   Uint16 w;
00085   Uint8  b[2];
00086 } Union16;
00087 
00088 #ifdef __IAR_SYSTEMS_ICC__
00089 typedef char     bit;
00090 typedef int      p_uart_ptchar;
00091 typedef int      r_uart_ptchar;
00092 #endif
00093 #ifdef __CODEVISIONAVR__
00094 typedef char     bit;
00095 typedef int      p_uart_ptchar;
00096 typedef char     r_uart_ptchar;
00097 #endif
00098 #if !defined(__IAR_SYSTEMS_ICC__) && !defined(___ICC__)
00099 typedef char      p_uart_ptchar;
00100 typedef char      r_uart_ptchar;
00101 #endif
00102 
00103 #endif
00104 
00105 /**********************************************************************************/
00106 /* codevision COMPILER (__CODEVISIONAVR__)                                                 */
00107 /**********************************************************************************/
00108 #ifdef __ICC__
00109 #define _ConstType_  lit
00110 #define _MemType_
00111 #define _GenericType_ __generic
00112 #define code lit
00113 #define xdata
00114 #define idata
00115 #define data
00116 #endif
00117 /**********************************************************************************/
00118 /* IAR COMPILER (__IAR_SYSTEMS_ICC__)                                             */
00119 /**********************************************************************************/
00120 #ifdef __IAR_SYSTEMS_ICC__
00121 #include "inavr.h"
00122 #define _ConstType_  __flash
00123 #define _MemType_
00124 #define _GenericType_ __generic
00125 #define code __flash
00126 #define farcode __farflash
00127 #define xdata
00128 #define idata
00129 #define data
00130 #define At(x) @ x
00131 #define pdata
00132 #define bdata
00133 // Memory Type Location
00134 #ifndef _CONST_TYPE_
00135 #  define _CONST_TYPE_ code
00136 #endif
00137 
00138 #define Enable_interrupt() __enable_interrupt()
00139 #define Disable_interrupt() __disable_interrupt()
00140 #endif
00141 
00142 
00143 /* General purpose defines */
00144 /*#define _ConstType_   __farflash
00145 #define _MemType_
00146 #define _GenericType_ __generic
00147 #define code __farflash
00148 #define xdata
00149 #define idata
00150 #define data*/
00151 
00152 
00153 
00154 
00155 /*_____ M A C R O S ________________________________________________________*/
00156 /* little-big endian management */
00157 #define INTEL_ALIGNMENT     LITTLE_ENDIAN
00158 #define MOTOROLA_ALIGNMENT  BIG_ENDIAN
00159 
00160 // U16/U32 endian handlers
00161 #ifdef LITTLE_ENDIAN     // => 16bit: (LSB,MSB), 32bit: (LSW,MSW) or (LSB0,LSB1,LSB2,LSB3) or (MSB3,MSB2,MSB1,MSB0)
00162 #  define MSB(u16)        (((U8* )&u16)[1])
00163 #  define LSB(u16)        (((U8* )&u16)[0])
00164 #  define MSW(u32)        (((U16*)&u32)[1])
00165 #  define LSW(u32)        (((U16*)&u32)[0])
00166 #  define MSB0(u32)       (((U8* )&u32)[3])
00167 #  define MSB1(u32)       (((U8* )&u32)[2])
00168 #  define MSB2(u32)       (((U8* )&u32)[1])
00169 #  define MSB3(u32)       (((U8* )&u32)[0])
00170 #  define LSB0(u32)       MSB3(u32)
00171 #  define LSB1(u32)       MSB2(u32)
00172 #  define LSB2(u32)       MSB1(u32)
00173 #  define LSB3(u32)       MSB0(u32)
00174 #else // BIG_ENDIAN         => 16bit: (MSB,LSB), 32bit: (MSW,LSW) or (LSB3,LSB2,LSB1,LSB0) or (MSB0,MSB1,MSB2,MSB3)
00175 #  define MSB(u16)        (((U8* )&u16)[0])
00176 #  define LSB(u16)        (((U8* )&u16)[1])
00177 #  define MSW(u32)        (((U16*)&u32)[0])
00178 #  define LSW(u32)        (((U16*)&u32)[1])
00179 #  define MSB0(u32)       (((U8* )&u32)[0])
00180 #  define MSB1(u32)       (((U8* )&u32)[1])
00181 #  define MSB2(u32)       (((U8* )&u32)[2])
00182 #  define MSB3(u32)       (((U8* )&u32)[3])
00183 #  define LSB0(u32)       MSB3(u32)
00184 #  define LSB1(u32)       MSB2(u32)
00185 #  define LSB2(u32)       MSB1(u32)
00186 #  define LSB3(u32)       MSB0(u32)
00187 #endif
00188 
00189 // Endian converters
00190 #define Le16(b)                        \
00191    (  ((U16)(     (b) &   0xFF) << 8)  \
00192    |  (     ((U16)(b) & 0xFF00) >> 8)  \
00193    )
00194 #define Le32(b)                             \
00195    (  ((U32)(     (b) &       0xFF) << 24)  \
00196    |  ((U32)((U16)(b) &     0xFF00) <<  8)  \
00197    |  (     ((U32)(b) &   0xFF0000) >>  8)  \
00198    |  (     ((U32)(b) & 0xFF000000) >> 24)  \
00199    )
00200 
00201 // host to network conversion: used for Intel HEX format, TCP/IP, ...
00202 // Convert a 16-bit value from host-byte order to network-byte order
00203 // Standard Unix, POSIX 1003.1g (draft)
00204 
00205 #ifdef LITTLE_ENDIAN
00206 #  define htons(a)    Le16(a)
00207 #define ntohs(a)    htons(a)
00208 #  define htonl(a)    Le32(a)
00209 #define ntohl(a)    htonl(a)
00210 #else
00211 #define htons(a)    (a)
00212 #define ntohs(a)    (a)
00213 #define htonl(a)    (a)
00214 #define ntohl(a)    (a)
00215 #endif
00216 
00217 
00218 // Constants
00219 #define ENABLE   1
00220 #define ENABLED  1
00221 #define DISABLED 0
00222 #define DISABLE  0
00223 #define FALSE   (0==1)
00224 #define TRUE    (1==1)
00225 
00226 #define KO      0
00227 #define OK      1
00228 #define OFF     0
00229 #define ON      1
00230 #ifndef NULL
00231 #define NULL    0
00232 #endif
00233 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file
00234 #define CLR     0
00235 #define SET     1
00236 #endif
00237 
00238 /* Bit and bytes manipulations */
00239 #define LOW(U16)                ((Uchar)U16)
00240 #define HIGH(U16)               ((Uchar)(U16>>8))
00241 #define TST_BIT_X(addrx,mask)   (*addrx & mask)
00242 #define SET_BIT_X(addrx,mask)   (*addrx = (*addrx | mask))
00243 #define CLR_BIT_X(addrx,mask)   (*addrx = (*addrx & ~mask))
00244 #define OUT_X(addrx,value)      (*addrx = value)
00245 #define IN_X(addrx)             (*addrx)
00246 
00247 #  define Max(a, b)            ( (a)>(b) ? (a) : (b) )       // Take the max between a and b
00248 #  define Min(a, b)            ( (a)<(b) ? (a) : (b) )       // Take the min between a and b
00249 
00250 // Align on the upper value <val> on a <n> boundary
00251 // i.e. Upper(0, 4)= 4
00252 //      Upper(1, 4)= 4
00253 //      Upper(2, 4)= 4
00254 //      Upper(3, 4)= 4
00255 //      Upper(4, 4)= 8
00256 //      ../..
00257 #  define Upper(val, n)        ( ((val)+(n)) & ~((n)-1) )
00258 
00259 // Align up <val> on a <n> boundary
00260 // i.e. Align_up(0, 4)= 0
00261 //      Align_up(1, 4)= 4
00262 //      Align_up(2, 4)= 4
00263 //      Align_up(3, 4)= 4
00264 //      Align_up(4, 4)= 4
00265 //      ../..
00266 #  define Align_up(val, n)     ( ((val)+(n)-1) & ~((n)-1) )
00267 
00268 // Align down <val> on a <n> boundary
00269 // i.e. Align_down(0, 4)= 0
00270 //      Align_down(1, 4)= 0
00271 //      Align_down(2, 4)= 0
00272 //      Align_down(3, 4)= 0
00273 //      Align_down(4, 4)= 4
00274 //      ../..
00275 #  define Align_down(val, n)   (  (val)        & ~((n)-1) )
00276 
00277 /*M**************************************************************************
00278 * NAME: Long_call
00279 *----------------------------------------------------------------------------
00280 * PARAMS:
00281 * addr: address of the routine to call
00282 *----------------------------------------------------------------------------
00283 * PURPOSE:
00284 * Call the routine at address addr: generate an Assembly LCALL addr opcode.
00285 *----------------------------------------------------------------------------
00286 * EXAMPLE:
00287 * Long_call(0); // Software reset (if no IT used before)
00288 *----------------------------------------------------------------------------
00289 * NOTE:
00290 * May be used as a long jump opcode in some special cases
00291 *****************************************************************************/
00292 #define Long_call(addr)         ((*(void (_ConstType_*)(void))(addr))())
00293 
00294 /* {For Langdoc} */
00295 
00296 /***********************************************************
00297  SET_SFR_BIT macro
00298   parameters
00299     sfr_reg : defined value in include file for sfr register
00300     bit_pos : defined value B_XX in include file for particular
00301               bit of sfr register
00302     bit_val : CLR / SET
00303 ************************************************************/
00304 #define SET_SFR_BIT(sfr_reg, bit_pos, bit_val) { sfr_reg &= ~(1<<(bit_pos)); sfr_reg |= ((bit_val)<<(bit_pos));}
00305 
00306 /***********************************************************
00307  bit_is_clear macro
00308   parameters
00309     PORT     : defined value in include file for sfr register
00310     POSITION : defined value in include file for particular
00311               bit of sfr register
00312   example : if (bit_is_clear(PORTB,PORTB3)) ...
00313 ************************************************************/
00314 #define bit_is_clear(PORT,POSITION) ((PORT & (1<<POSITION)) == 0 )
00315 
00316 /***********************************************************
00317  bit_is_set macro
00318   parameters
00319     PORT     : defined value in include file for sfr register
00320     POSITION : defined value in include file for particular
00321               bit of sfr register
00322   example : if (bit_is_set(PORTB,PORTB3)) ...
00323 ************************************************************/
00324 #define bit_is_set(PORT,POSITION) ((PORT & (1<<POSITION)) != 0 )
00325 
00326 
00327 
00328 /******************************************************************************/
00329 /* IAR COMPILER                                                               */
00330 /******************************************************************************/
00331 
00332 #define __IOMACRO_H
00333 
00334 #define TID_GUARD(proc) ((__TID__ & 0x7FF0) != ((90 << 8) | ((proc) << 4)))
00335 
00336 
00337 /*----------------------------------------------------------------------------*/
00338 #ifdef __IAR_SYSTEMS_ASM__
00339 /*----------------------------------------------------------------------------*/
00340 
00341 /* Byte sized SFRs */
00342 #define SFR_B_BITS(_NAME,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
00343    sfrb  _NAME = _ADDR
00344 #define SFR_B_BITS_EXT(_NAME,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
00345    sfrb  _NAME = _ADDR
00346 #define SFR_B2_BITS(_NAME1,_NAME2,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
00347    ASMSFRB2 _NAME1, _NAME2, _ADDR
00348 
00349 ASMSFRB2 MACRO
00350    sfrb  \1 = \3
00351    sfrb  \2 = \3
00352    ENDM
00353 
00354 
00355 /* Word sized SFRs, needs to be expanded into an assembler macro first. */
00356 #define SFR_W_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P)\
00357    ASMSFRW  _NAME, _ADDR
00358 
00359 #define SFR_W_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P)\
00360    ASMSFRW  _NAME, _ADDR
00361 
00362 ASMSFRW  MACRO
00363    sfrw  \1  = \2
00364    sfrb  \1L = (\2+0)
00365    sfrb  \1H = (\2+1)
00366    ENDM
00367 
00368 #endif /* __IAR_SYSTEMS_ASM__ */
00369 
00370 /*----------------------------------------------------------------------------*/
00371 #ifdef __ICCAVR__
00372 /*----------------------------------------------------------------------------*/
00373 #define __BYTEBITS(_NAME,_A,_B,_C,_D,_E,_F,_G,_H) \
00374 unsigned char _NAME ## _ ## _A:1, \
00375               _NAME ## _ ## _B:1, \
00376               _NAME ## _ ## _C:1, \
00377               _NAME ## _ ## _D:1, \
00378               _NAME ## _ ## _E:1, \
00379               _NAME ## _ ## _F:1, \
00380               _NAME ## _ ## _G:1, \
00381               _NAME ## _ ## _H:1;
00382 
00383 #define SFR_B_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
00384     __io union { \
00385       unsigned char   _NAME;           /* The sfrb as 1 byte */ \
00386       struct {                        /* The sfrb as 8 bits */ \
00387         __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) \
00388       };  \
00389     } @ _ADDR;
00390 #define SFR_B2_BITS(_NAME1, _NAME2, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
00391     __io union { \
00392       unsigned char   _NAME1;           /* The sfrb as 1 byte */ \
00393       unsigned char   _NAME2;           /* The sfrb as 1 byte */ \
00394       struct {                        /* The sfrb as 8 bits */ \
00395         __BYTEBITS(_NAME1, _A,_B,_C,_D,_E,_F,_G,_H) \
00396       };  \
00397       struct {                        /* The sfrb as 8 bits */ \
00398         __BYTEBITS(_NAME2, _A,_B,_C,_D,_E,_F,_G,_H) \
00399       };  \
00400     } @ _ADDR;
00401 #define SFR_B_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
00402     __tiny __no_init volatile union { \
00403       unsigned char   _NAME;           /* The sfrb as 1 byte */ \
00404       struct {                        /* The sfrb as 8 bits */ \
00405         __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) \
00406       };  \
00407     } @ _ADDR;
00408 
00409 #define SFR_W_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P) \
00410     __io union { \
00411       unsigned short  _NAME;  /* The sfrw as 1 short */ \
00412       struct {                /* The sfrw as 16 bits */ \
00413         __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H)   /* Bit names defined by user */  \
00414         __BYTEBITS(_NAME, _I,_J,_K,_L,_M,_N,_O,_P)   /* Bit names defined by user */  \
00415       };  \
00416       struct { /* The sfrw as 2 bytes */ \
00417         unsigned char _NAME ## L; \
00418         unsigned char _NAME ## H; \
00419       };  \
00420       struct {                          /* The sfrw as 2 x 8 bits */ \
00421         __BYTEBITS(_NAME ## L, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)  /* Bit names hard coded to 0-7 */ \
00422         __BYTEBITS(_NAME ## H, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)  /* Bit names hard coded to 0-7 */ \
00423       };  \
00424     } @ _ADDR;
00425 
00426 #define SFR_W_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P) \
00427    __io union { \
00428     unsigned short  _NAME;   \
00429      struct {                /* The sfrw_ext as 16 bits */ \
00430         __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H)   /* Bit names defined by user */  \
00431         __BYTEBITS(_NAME, _I,_J,_K,_L,_M,_N,_O,_P)   /* Bit names defined by user */  \
00432       };  \
00433       struct { /* The sfrw _ext as 2 bytes */ \
00434         unsigned char _NAME ## L; \
00435         unsigned char _NAME ## H; \
00436       };  \
00437       struct {                          /* The sfrw_ext as 2 x 8 bits */ \
00438         __BYTEBITS(_NAME ## L, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)  /* Bit names hard coded to 0-7 */ \
00439         __BYTEBITS(_NAME ## H, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)  /* Bit names hard coded to 0-7 */ \
00440       };  \
00441     } @ _ADDR;
00442 
00443 #endif
00444 
00445 #define SFR_B(_NAME, _ADDR) SFR_B_BITS(_NAME, _ADDR, \
00446                                     Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
00447 #define SFR_B2(_NAME1, _NAME2, _ADDR) SFR_B2_BITS(_NAME1, _NAME2, _ADDR, \
00448                                     Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
00449 #define SFR_B_EXT(_NAME, _ADDR) SFR_B_BITS_EXT(_NAME, _ADDR, \
00450                                     Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
00451 
00452 #define SFR_W(_NAME, _ADDR)  SFR_W_BITS(_NAME, _ADDR, \
00453                                     Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7, \
00454                                     Bit8,Bit9,Bit10,Bit11,Bit12,Bit13,Bit14,Bit15)
00455 
00456 #define SFR_W_EXT(_NAME, _ADDR)  SFR_W_BITS_EXT(_NAME, _ADDR, \
00457                                     Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7, \
00458                                     Bit8,Bit9,Bit10,Bit11,Bit12,Bit13,Bit14,Bit15)
00459 
00460 /******************************************************************************/
00461 /* GCC COMPILER                                                               */
00462 /******************************************************************************/
00463    #ifdef AVRGCC
00464 #define _CONST_TYPE_
00465 #define _ConstType_  __flash
00466 #define _MemType_
00467 #define _GenericType_ __generic
00468 #define code PROGMEM
00469 #define xdata
00470 #define idata
00471 #define data
00472 #define At(x) @ x
00473 #define pdata
00474 #define bdata
00475 #define bit U8
00476 #define bool U8
00477    //#include <avr/sfr_defs.h>
00478    #include <avr/interrupt.h>
00479    #include <avr/pgmspace.h>
00480    #define Enable_interrupt() sei()
00481    #define Disable_interrupt() cli()
00482 
00483    #endif
00484 #endif /* _COMPILER_H_ */
00485 

Generated on Fri Jun 15 14:15:32 2007 for Atmel by  doxygen 1.5.1-p1