compiler.h

Go to the documentation of this file.
00001 /*H**************************************************************************
00002 * NAME:         compiler.h
00003 *----------------------------------------------------------------------------
00004 * Copyright (c) 2004 Atmel.
00005 *----------------------------------------------------------------------------
00006 * RELEASE:      at90usb128-demo-hidgen-1_0_0
00007 * FILE_REV:     1.13.2.23
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 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 xdata
00127 #define idata
00128 #define data
00129 #define At(x) @ x
00130 #define pdata
00131 #define bdata
00132 
00133 #define Enable_interrupt() __enable_interrupt()
00134 #define Disable_interrupt() __disable_interrupt()
00135 #endif
00136 
00137 
00138 /* General purpose defines */
00139 /*#define _ConstType_   __farflash
00140 #define _MemType_
00141 #define _GenericType_ __generic
00142 #define code __farflash
00143 #define xdata
00144 #define idata
00145 #define data*/
00146 
00147 
00148 
00149 
00150 /*_____ M A C R O S ________________________________________________________*/
00151 /* little-big endian management */
00152 #define INTEL_ALIGNMENT     LITTLE_ENDIAN
00153 #define MOTOROLA_ALIGNMENT  BIG_ENDIAN
00154 
00155 // U16/U32 endian handlers
00156 #ifdef LITTLE_ENDIAN     // => 16bit: (LSB,MSB), 32bit: (LSW,MSW) or (LSB0,LSB1,LSB2,LSB3) or (MSB3,MSB2,MSB1,MSB0)
00157 #  define MSB(u16)        (((U8* )&u16)[1])
00158 #  define LSB(u16)        (((U8* )&u16)[0])
00159 #  define MSW(u32)        (((U16*)&u32)[1])
00160 #  define LSW(u32)        (((U16*)&u32)[0])
00161 #  define MSB0(u32)       (((U8* )&u32)[3])
00162 #  define MSB1(u32)       (((U8* )&u32)[2])
00163 #  define MSB2(u32)       (((U8* )&u32)[1])
00164 #  define MSB3(u32)       (((U8* )&u32)[0])
00165 #  define LSB0(u32)       MSB3(u32)
00166 #  define LSB1(u32)       MSB2(u32)
00167 #  define LSB2(u32)       MSB1(u32)
00168 #  define LSB3(u32)       MSB0(u32)
00169 #else // BIG_ENDIAN         => 16bit: (MSB,LSB), 32bit: (MSW,LSW) or (LSB3,LSB2,LSB1,LSB0) or (MSB0,MSB1,MSB2,MSB3)
00170 #  define MSB(u16)        (((U8* )&u16)[0])
00171 #  define LSB(u16)        (((U8* )&u16)[1])
00172 #  define MSW(u32)        (((U16*)&u32)[0])
00173 #  define LSW(u32)        (((U16*)&u32)[1])
00174 #  define MSB0(u32)       (((U8* )&u32)[0])
00175 #  define MSB1(u32)       (((U8* )&u32)[1])
00176 #  define MSB2(u32)       (((U8* )&u32)[2])
00177 #  define MSB3(u32)       (((U8* )&u32)[3])
00178 #  define LSB0(u32)       MSB3(u32)
00179 #  define LSB1(u32)       MSB2(u32)
00180 #  define LSB2(u32)       MSB1(u32)
00181 #  define LSB3(u32)       MSB0(u32)
00182 #endif
00183 
00184 // Endian converters
00185 #define Le16(b)                        \
00186    (  ((U16)(     (b) &   0xFF) << 8)  \
00187    |  (     ((U16)(b) & 0xFF00) >> 8)  \
00188    )
00189 #define Le32(b)                             \
00190    (  ((U32)(     (b) &       0xFF) << 24)  \
00191    |  ((U32)((U16)(b) &     0xFF00) <<  8)  \
00192    |  (     ((U32)(b) &   0xFF0000) >>  8)  \
00193    |  (     ((U32)(b) & 0xFF000000) >> 24)  \
00194    )
00195 
00196 // host to network conversion: used for Intel HEX format, TCP/IP, ...
00197 // Convert a 16-bit value from host-byte order to network-byte order
00198 // Standard Unix, POSIX 1003.1g (draft)
00199 
00200 #ifdef LITTLE_ENDIAN
00201 #  define htons(a)    Le16(a)
00202 #define ntohs(a)    htons(a)
00203 #  define htonl(a)    Le32(a)
00204 #define ntohl(a)    htonl(a)
00205 #else
00206 #define htons(a)    (a)
00207 #define ntohs(a)    (a)
00208 #define htonl(a)    (a)
00209 #define ntohl(a)    (a)
00210 #endif
00211 
00212 
00213 // Constants
00214 #define ENABLE   1
00215 #define ENABLED  1
00216 #define DISABLED 0
00217 #define DISABLE  0
00218 #define FALSE   (0==1)
00219 #define TRUE    (1==1)
00220 
00221 #define KO      0
00222 #define OK      1
00223 #define OFF     0
00224 #define ON      1
00225 #define NULL    0
00226 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file
00227 #define CLR     0
00228 #define SET     1
00229 #endif
00230 
00231 /* Bit and bytes manipulations */
00232 #define LOW(U16)                ((Uchar)U16)
00233 #define HIGH(U16)               ((Uchar)(U16>>8))
00234 #define TST_BIT_X(addrx,mask)   (*addrx & mask)
00235 #define SET_BIT_X(addrx,mask)   (*addrx = (*addrx | mask))
00236 #define CLR_BIT_X(addrx,mask)   (*addrx = (*addrx & ~mask))
00237 #define OUT_X(addrx,value)      (*addrx = value)
00238 #define IN_X(addrx)             (*addrx)
00239 
00240 #  define Max(a, b)            ( (a)>(b) ? (a) : (b) )       // Take the max between a and b
00241 #  define Min(a, b)            ( (a)<(b) ? (a) : (b) )       // Take the min between a and b
00242 
00243 // Align on the upper value <val> on a <n> boundary
00244 // i.e. Upper(0, 4)= 4
00245 //      Upper(1, 4)= 4
00246 //      Upper(2, 4)= 4
00247 //      Upper(3, 4)= 4
00248 //      Upper(4, 4)= 8
00249 //      ../..
00250 #  define Upper(val, n)        ( ((val)+(n)) & ~((n)-1) )
00251 
00252 // Align up <val> on a <n> boundary
00253 // i.e. Align_up(0, 4)= 0
00254 //      Align_up(1, 4)= 4
00255 //      Align_up(2, 4)= 4
00256 //      Align_up(3, 4)= 4
00257 //      Align_up(4, 4)= 4
00258 //      ../..
00259 #  define Align_up(val, n)     ( ((val)+(n)-1) & ~((n)-1) )
00260 
00261 // Align down <val> on a <n> boundary
00262 // i.e. Align_down(0, 4)= 0
00263 //      Align_down(1, 4)= 0
00264 //      Align_down(2, 4)= 0
00265 //      Align_down(3, 4)= 0
00266 //      Align_down(4, 4)= 4
00267 //      ../..
00268 #  define Align_down(val, n)   (  (val)        & ~((n)-1) )
00269 
00270 /*M**************************************************************************
00271 * NAME: Long_call
00272 *----------------------------------------------------------------------------
00273 * PARAMS:
00274 * addr: address of the routine to call
00275 *----------------------------------------------------------------------------
00276 * PURPOSE:
00277 * Call the routine at address addr: generate an Assembly LCALL addr opcode.
00278 *----------------------------------------------------------------------------
00279 * EXAMPLE:
00280 * Long_call(0); // Software reset (if no IT used before)
00281 *----------------------------------------------------------------------------
00282 * NOTE:
00283 * May be used as a long jump opcode in some special cases
00284 *****************************************************************************/
00285 #define Long_call(addr)         ((*(void (_ConstType_*)(void))(addr))())
00286 
00287 /* {For Langdoc} */
00288 
00289 /***********************************************************
00290  SET_SFR_BIT macro
00291   parameters
00292     sfr_reg : defined value in include file for sfr register
00293     bit_pos : defined value B_XX in include file for particular
00294               bit of sfr register
00295     bit_val : CLR / SET
00296 ************************************************************/
00297 #define SET_SFR_BIT(sfr_reg, bit_pos, bit_val) { sfr_reg &= ~(1<<(bit_pos)); sfr_reg |= ((bit_val)<<(bit_pos));}
00298 
00299 /***********************************************************
00300  bit_is_clear macro
00301   parameters
00302     PORT     : defined value in include file for sfr register
00303     POSITION : defined value in include file for particular
00304               bit of sfr register
00305   example : if (bit_is_clear(PORTB,PORTB3)) ...
00306 ************************************************************/
00307 #define bit_is_clear(PORT,POSITION) ((PORT & (1<<POSITION)) == 0 )
00308 
00309 /***********************************************************
00310  bit_is_set macro
00311   parameters
00312     PORT     : defined value in include file for sfr register
00313     POSITION : defined value in include file for particular
00314               bit of sfr register
00315   example : if (bit_is_set(PORTB,PORTB3)) ...
00316 ************************************************************/
00317 #define bit_is_set(PORT,POSITION) ((PORT & (1<<POSITION)) != 0 )
00318 
00319 
00320 
00321 /******************************************************************************/
00322 /* IAR COMPILER                                                               */
00323 /******************************************************************************/
00324 
00325 #define __IOMACRO_H
00326 
00327 #define TID_GUARD(proc) ((__TID__ & 0x7FF0) != ((90 << 8) | ((proc) << 4)))
00328 
00329 
00330 /*----------------------------------------------------------------------------*/
00331 #ifdef __IAR_SYSTEMS_ASM__
00332 /*----------------------------------------------------------------------------*/
00333 
00334 /* Byte sized SFRs */
00335 #define SFR_B_BITS(_NAME,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
00336    sfrb  _NAME = _ADDR
00337 #define SFR_B_BITS_EXT(_NAME,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
00338    sfrb  _NAME = _ADDR
00339 #define SFR_B2_BITS(_NAME1,_NAME2,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
00340    ASMSFRB2 _NAME1, _NAME2, _ADDR
00341 
00342 ASMSFRB2 MACRO
00343    sfrb  \1 = \3
00344    sfrb  \2 = \3
00345    ENDM
00346 
00347 
00348 /* Word sized SFRs, needs to be expanded into an assembler macro first. */
00349 #define SFR_W_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P)\
00350    ASMSFRW  _NAME, _ADDR
00351 
00352 #define SFR_W_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P)\
00353    ASMSFRW  _NAME, _ADDR
00354 
00355 ASMSFRW  MACRO
00356    sfrw  \1  = \2
00357    sfrb  \1L = (\2+0)
00358    sfrb  \1H = (\2+1)
00359    ENDM
00360 
00361 #endif /* __IAR_SYSTEMS_ASM__ */
00362 
00363 /*----------------------------------------------------------------------------*/
00364 #ifdef __ICCAVR__
00365 /*----------------------------------------------------------------------------*/
00366 #define __BYTEBITS(_NAME,_A,_B,_C,_D,_E,_F,_G,_H) \
00367 unsigned char _NAME ## _ ## _A:1, \
00368               _NAME ## _ ## _B:1, \
00369               _NAME ## _ ## _C:1, \
00370               _NAME ## _ ## _D:1, \
00371               _NAME ## _ ## _E:1, \
00372               _NAME ## _ ## _F:1, \
00373               _NAME ## _ ## _G:1, \
00374               _NAME ## _ ## _H:1;
00375 
00376 #define SFR_B_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
00377     __io union { \
00378       unsigned char   _NAME;           /* The sfrb as 1 byte */ \
00379       struct {                        /* The sfrb as 8 bits */ \
00380         __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) \
00381       };  \
00382     } @ _ADDR;
00383 #define SFR_B2_BITS(_NAME1, _NAME2, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
00384     __io union { \
00385       unsigned char   _NAME1;           /* The sfrb as 1 byte */ \
00386       unsigned char   _NAME2;           /* The sfrb as 1 byte */ \
00387       struct {                        /* The sfrb as 8 bits */ \
00388         __BYTEBITS(_NAME1, _A,_B,_C,_D,_E,_F,_G,_H) \
00389       };  \
00390       struct {                        /* The sfrb as 8 bits */ \
00391         __BYTEBITS(_NAME2, _A,_B,_C,_D,_E,_F,_G,_H) \
00392       };  \
00393     } @ _ADDR;
00394 #define SFR_B_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
00395     __tiny __no_init volatile union { \
00396       unsigned char   _NAME;           /* The sfrb as 1 byte */ \
00397       struct {                        /* The sfrb as 8 bits */ \
00398         __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) \
00399       };  \
00400     } @ _ADDR;
00401 
00402 #define SFR_W_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P) \
00403     __io union { \
00404       unsigned short  _NAME;  /* The sfrw as 1 short */ \
00405       struct {                /* The sfrw as 16 bits */ \
00406         __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H)   /* Bit names defined by user */  \
00407         __BYTEBITS(_NAME, _I,_J,_K,_L,_M,_N,_O,_P)   /* Bit names defined by user */  \
00408       };  \
00409       struct { /* The sfrw as 2 bytes */ \
00410         unsigned char _NAME ## L; \
00411         unsigned char _NAME ## H; \
00412       };  \
00413       struct {                          /* The sfrw as 2 x 8 bits */ \
00414         __BYTEBITS(_NAME ## L, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)  /* Bit names hard coded to 0-7 */ \
00415         __BYTEBITS(_NAME ## H, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)  /* Bit names hard coded to 0-7 */ \
00416       };  \
00417     } @ _ADDR;
00418 
00419 #define SFR_W_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P) \
00420    __io union { \
00421     unsigned short  _NAME;   \
00422      struct {                /* The sfrw_ext as 16 bits */ \
00423         __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H)   /* Bit names defined by user */  \
00424         __BYTEBITS(_NAME, _I,_J,_K,_L,_M,_N,_O,_P)   /* Bit names defined by user */  \
00425       };  \
00426       struct { /* The sfrw _ext as 2 bytes */ \
00427         unsigned char _NAME ## L; \
00428         unsigned char _NAME ## H; \
00429       };  \
00430       struct {                          /* The sfrw_ext as 2 x 8 bits */ \
00431         __BYTEBITS(_NAME ## L, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)  /* Bit names hard coded to 0-7 */ \
00432         __BYTEBITS(_NAME ## H, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)  /* Bit names hard coded to 0-7 */ \
00433       };  \
00434     } @ _ADDR;
00435 
00436 #endif
00437 
00438 #define SFR_B(_NAME, _ADDR) SFR_B_BITS(_NAME, _ADDR, \
00439                                     Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
00440 #define SFR_B2(_NAME1, _NAME2, _ADDR) SFR_B2_BITS(_NAME1, _NAME2, _ADDR, \
00441                                     Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
00442 #define SFR_B_EXT(_NAME, _ADDR) SFR_B_BITS_EXT(_NAME, _ADDR, \
00443                                     Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
00444 
00445 #define SFR_W(_NAME, _ADDR)  SFR_W_BITS(_NAME, _ADDR, \
00446                                     Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7, \
00447                                     Bit8,Bit9,Bit10,Bit11,Bit12,Bit13,Bit14,Bit15)
00448 
00449 #define SFR_W_EXT(_NAME, _ADDR)  SFR_W_BITS_EXT(_NAME, _ADDR, \
00450                                     Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7, \
00451                                     Bit8,Bit9,Bit10,Bit11,Bit12,Bit13,Bit14,Bit15)
00452 
00453 /******************************************************************************/
00454 /* GCC COMPILER                                                               */
00455 /******************************************************************************/
00456    #ifdef AVRGCC
00457 #define _ConstType_  __flash
00458 #define _MemType_
00459 #define _GenericType_ __generic
00460 #define code PROGMEM
00461 #define xdata
00462 #define idata
00463 #define data
00464 #define At(x) @ x
00465 #define pdata
00466 #define bdata
00467 #define bit U8
00468 #define bool U8
00469    //#include <avr/sfr_defs.h>
00470    #include <avr/interrupt.h>
00471    #include <avr/pgmspace.h>
00472    #define Enable_interrupt() sei()
00473    #define Disable_interrupt() cli()
00474 
00475    #endif
00476 #endif /* _COMPILER_H_ */
00477 

Generated on Fri Mar 17 16:02:03 2006 for Atmel by  doxygen 1.4.6-NO