compiler.h

Go to the documentation of this file.
00001 /*This file is prepared for Doxygen automatic documentation generation.*/
00014 
00015 /* Copyright (c) 2009 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, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 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 typedef unsigned char       Bool;
00061 
00062 
00063 typedef U8                  Status;
00064 typedef Bool                Status_bool;
00065 #define bool                Bool
00066 #define PASS 0
00067 #define FAIL 1
00068 
00069 
00070 
00071 #if (defined __C51__)
00072 #  define _MEM_TYPE_BIT_              bdata  // Used for bit accesses
00073 #  define _MEM_TYPE_FAST_              data
00074 #  define _MEM_TYPE_MEDFAST_          idata
00075 #  define _MEM_TYPE_MEDSLOW_          pdata
00076 #  define _MEM_TYPE_SLOW_             xdata
00077 #else
00078 #  define _MEM_TYPE_BIT_
00079 #  define _MEM_TYPE_FAST_
00080 #  define _MEM_TYPE_MEDFAST_
00081 #  define _MEM_TYPE_MEDSLOW_
00082 #  define _MEM_TYPE_SLOW_
00083 #endif
00084 
00085 typedef unsigned char       Uchar;
00086 
00087 
00088 typedef unsigned char       Uint8;
00089 typedef unsigned int        Uint16;
00090 typedef unsigned long int   Uint32;
00091 
00092 typedef char                Int8;
00093 typedef int                 Int16;
00094 typedef long int            Int32;
00095 
00096 typedef unsigned char       Byte;
00097 typedef unsigned int        Word;
00098 typedef unsigned long int   DWord;
00099 
00100 typedef union
00101 {
00102   Uint32 dw; // l changed in dw (double word) because l is used for signed long...
00103   Uint16 w[2];
00104   Uint8  b[4];
00105 } Union32;
00106 
00107 typedef union
00108 {
00109   Uint16 w;
00110   Uint8  b[2];
00111 } Union16;
00112 
00113 #ifdef __IAR_SYSTEMS_ICC__
00114 typedef char     bit;
00115 typedef int      p_uart_ptchar;
00116 typedef int      r_uart_ptchar;
00117 #endif
00118 #ifdef __CODEVISIONAVR__
00119 typedef char     bit;
00120 typedef int      p_uart_ptchar;
00121 typedef char     r_uart_ptchar;
00122 #endif
00123 #if !defined(__IAR_SYSTEMS_ICC__) && !defined(___ICC__)
00124 typedef char      p_uart_ptchar;
00125 typedef char      r_uart_ptchar;
00126 #endif
00127 
00128 #endif
00129 
00130 /**********************************************************************************/
00131 /* codevision COMPILER (__CODEVISIONAVR__)                                                 */
00132 /**********************************************************************************/
00133 #ifdef __ICC__
00134 #define _ConstType_  lit
00135 #define _MemType_
00136 #define _GenericType_ __generic
00137 #define code lit
00138 #define xdata
00139 #define idata
00140 #define data
00141 #endif
00142 /**********************************************************************************/
00143 /* IAR COMPILER (__IAR_SYSTEMS_ICC__)                                             */
00144 /**********************************************************************************/
00145 #ifdef __IAR_SYSTEMS_ICC__
00146 #include "inavr.h"
00147 #define _ConstType_  __flash
00148 #define _MemType_
00149 #define _GenericType_ __generic
00150 #ifdef __ICCAVR__
00151    #if (defined(__AT90USB1287__) || defined(__AT90USB1286__)) 
00152       #define code __farflash
00153       #define farcode __farflash
00154    #else
00155       #define code __flash
00156       #define farcode __flash
00157    #endif
00158 #elif defined __GNUC__
00159    #if (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__)) 
00160       #define code __farflash
00161       #define farcode __farflash
00162    #else
00163       #define code __flash
00164       #define farcode __flash
00165    #endif
00166 #endif
00167 #define xdata
00168 #define idata
00169 #define data
00170 #define At(x) @ x
00171 #define pdata
00172 #define bdata
00173 // Memory Type Location
00174 #ifndef _CONST_TYPE_
00175 #  define _CONST_TYPE_ code
00176 #endif
00177 
00178 #define Enable_interrupt() __enable_interrupt()
00179 #define Disable_interrupt() __disable_interrupt()
00180 #define Get_interrupt_state()       (SREG&0x80)
00181 
00182 #include <iomacro.h>
00183 #define SFR_W_EXT(a,b) SFR_W_R(b,a)
00184 
00185 
00186 #endif
00187 
00188 
00189 
00190 
00191 
00192 /*_____ M A C R O S ________________________________________________________*/
00193 /* little-big endian management */
00194 #define INTEL_ALIGNMENT     LITTLE_ENDIAN
00195 #define MOTOROLA_ALIGNMENT  BIG_ENDIAN
00196 
00197 // U16/U32 endian handlers
00198 #ifdef LITTLE_ENDIAN     // => 16bit: (LSB,MSB), 32bit: (LSW,MSW) or (LSB0,LSB1,LSB2,LSB3) or (MSB3,MSB2,MSB1,MSB0)
00199 #  define MSB(u16)        (((U8* )&u16)[1])
00200 #  define LSB(u16)        (((U8* )&u16)[0])
00201 #  define MSW(u32)        (((U16*)&u32)[1])
00202 #  define LSW(u32)        (((U16*)&u32)[0])
00203 #  define MSB0(u32)       (((U8* )&u32)[3])
00204 #  define MSB1(u32)       (((U8* )&u32)[2])
00205 #  define MSB2(u32)       (((U8* )&u32)[1])
00206 #  define MSB3(u32)       (((U8* )&u32)[0])
00207 #  define LSB0(u32)       MSB3(u32)
00208 #  define LSB1(u32)       MSB2(u32)
00209 #  define LSB2(u32)       MSB1(u32)
00210 #  define LSB3(u32)       MSB0(u32)
00211 #else // BIG_ENDIAN         => 16bit: (MSB,LSB), 32bit: (MSW,LSW) or (LSB3,LSB2,LSB1,LSB0) or (MSB0,MSB1,MSB2,MSB3)
00212 #  define MSB(u16)        (((U8* )&u16)[0])
00213 #  define LSB(u16)        (((U8* )&u16)[1])
00214 #  define MSW(u32)        (((U16*)&u32)[0])
00215 #  define LSW(u32)        (((U16*)&u32)[1])
00216 #  define MSB0(u32)       (((U8* )&u32)[0])
00217 #  define MSB1(u32)       (((U8* )&u32)[1])
00218 #  define MSB2(u32)       (((U8* )&u32)[2])
00219 #  define MSB3(u32)       (((U8* )&u32)[3])
00220 #  define LSB0(u32)       MSB3(u32)
00221 #  define LSB1(u32)       MSB2(u32)
00222 #  define LSB2(u32)       MSB1(u32)
00223 #  define LSB3(u32)       MSB0(u32)
00224 #endif
00225 
00226 // Endian converters
00227 #define Le16(b)                        \
00228    (  ((U16)(     (b) &   0xFF) << 8)  \
00229    |  (     ((U16)(b) & 0xFF00) >> 8)  \
00230    )
00231 #define Le32(b)                             \
00232    (  ((U32)(     (b) &       0xFF) << 24)  \
00233    |  ((U32)((U16)(b) &     0xFF00) <<  8)  \
00234    |  (     ((U32)(b) &   0xFF0000) >>  8)  \
00235    |  (     ((U32)(b) & 0xFF000000) >> 24)  \
00236    )
00237 
00238 // host to network conversion: used for Intel HEX format, TCP/IP, ...
00239 // Convert a 16-bit value from host-byte order to network-byte order
00240 // Standard Unix, POSIX 1003.1g (draft)
00241 
00242 #ifdef LITTLE_ENDIAN
00243 #  define htons(a)    Le16(a)
00244 #define ntohs(a)    htons(a)
00245 #  define htonl(a)    Le32(a)
00246 #define ntohl(a)    htonl(a)
00247 #else
00248 #define htons(a)    (a)
00249 #define ntohs(a)    (a)
00250 #define htonl(a)    (a)
00251 #define ntohl(a)    (a)
00252 #endif
00253 
00254 
00255 // Constants
00256 #define ENABLE   1
00257 #define ENABLED  1
00258 #define DISABLED 0
00259 #define DISABLE  0
00260 #define FALSE   (0==1)
00261 #define TRUE    (1==1)
00262 #define true    TRUE
00263 #define false   FALSE
00264 
00265 
00266 #define KO      0
00267 #define OK      1
00268 #define OFF     0
00269 #define ON      1
00270 #ifndef NULL
00271 #define NULL    0
00272 #endif
00273 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file
00274 #define CLR     0
00275 #define SET     1
00276 #endif
00277 
00278 /* Bit and bytes manipulations */
00279 #define LOW(U16)                ((Uchar)U16)
00280 #define HIGH(U16)               ((Uchar)(U16>>8))
00281 #define TST_BIT_X(addrx,mask)   (*addrx & mask)
00282 #define SET_BIT_X(addrx,mask)   (*addrx = (*addrx | mask))
00283 #define CLR_BIT_X(addrx,mask)   (*addrx = (*addrx & ~mask))
00284 #define OUT_X(addrx,value)      (*addrx = value)
00285 #define IN_X(addrx)             (*addrx)
00286 
00287 #  define Max(a, b)            ( (a)>(b) ? (a) : (b) )       // Take the max between a and b
00288 #  define Min(a, b)            ( (a)<(b) ? (a) : (b) )       // Take the min between a and b
00289 
00290 // Align on the upper value <val> on a <n> boundary
00291 // i.e. Upper(0, 4)= 4
00292 //      Upper(1, 4)= 4
00293 //      Upper(2, 4)= 4
00294 //      Upper(3, 4)= 4
00295 //      Upper(4, 4)= 8
00296 //      ../..
00297 #  define Upper(val, n)        ( ((val)+(n)) & ~((n)-1) )
00298 
00299 // Align up <val> on a <n> boundary
00300 // i.e. Align_up(0, 4)= 0
00301 //      Align_up(1, 4)= 4
00302 //      Align_up(2, 4)= 4
00303 //      Align_up(3, 4)= 4
00304 //      Align_up(4, 4)= 4
00305 //      ../..
00306 #  define Align_up(val, n)     ( ((val)+(n)-1) & ~((n)-1) )
00307 
00308 // Align down <val> on a <n> boundary
00309 // i.e. Align_down(0, 4)= 0
00310 //      Align_down(1, 4)= 0
00311 //      Align_down(2, 4)= 0
00312 //      Align_down(3, 4)= 0
00313 //      Align_down(4, 4)= 4
00314 //      ../..
00315 #  define Align_down(val, n)   (  (val)        & ~((n)-1) )
00316 
00317 /*M**************************************************************************
00318 * NAME: Long_call
00319 *----------------------------------------------------------------------------
00320 * PARAMS:
00321 * addr: address of the routine to call
00322 *----------------------------------------------------------------------------
00323 * PURPOSE:
00324 * Call the routine at address addr: generate an Assembly LCALL addr opcode.
00325 *----------------------------------------------------------------------------
00326 * EXAMPLE:
00327 * Long_call(0); // Software reset (if no IT used before)
00328 *----------------------------------------------------------------------------
00329 * NOTE:
00330 * May be used as a long jump opcode in some special cases
00331 *****************************************************************************/
00332 #define Long_call(addr)         ((*(void (_ConstType_*)(void))(addr))())
00333 
00334 /* {For Langdoc} */
00335 
00336 /***********************************************************
00337  SET_SFR_BIT macro
00338   parameters
00339     sfr_reg : defined value in include file for sfr register
00340     bit_pos : defined value B_XX in include file for particular
00341               bit of sfr register
00342     bit_val : CLR / SET
00343 ************************************************************/
00344 #define SET_SFR_BIT(sfr_reg, bit_pos, bit_val) { sfr_reg &= ~(1<<(bit_pos)); sfr_reg |= ((bit_val)<<(bit_pos));}
00345 
00346 /***********************************************************
00347  bit_is_clear macro
00348   parameters
00349     PORT     : defined value in include file for sfr register
00350     POSITION : defined value in include file for particular
00351               bit of sfr register
00352   example : if (bit_is_clear(PORTB,PORTB3)) ...
00353 ************************************************************/
00354 #define bit_is_clear(PORT,POSITION) ((PORT & (1<<POSITION)) == 0 )
00355 
00356 /***********************************************************
00357  bit_is_set macro
00358   parameters
00359     PORT     : defined value in include file for sfr register
00360     POSITION : defined value in include file for particular
00361               bit of sfr register
00362   example : if (bit_is_set(PORTB,PORTB3)) ...
00363 ************************************************************/
00364 #define bit_is_set(PORT,POSITION) ((PORT & (1<<POSITION)) != 0 )
00365 
00366 
00367 
00368 
00369 
00370 #define TID_GUARD(proc) ((__TID__ & 0x7FF0) != ((90 << 8) | ((proc) << 4)))
00371 
00372 
00373 
00374 /******************************************************************************/
00375 /* GCC COMPILER                                                               */
00376 /******************************************************************************/
00377    #ifdef __GNUC__
00378 #define _CONST_TYPE_
00379 #define _ConstType_  __flash
00380 #define _MemType_
00381 #define _GenericType_ __generic
00382 #define code PROGMEM
00383 #define xdata
00384 #define idata
00385 #define data
00386 #define At(x) @ x
00387 #define pdata
00388 #define bdata
00389 #define bit U8
00390 #include <avr/interrupt.h>
00391 #include <avr/pgmspace.h>
00392 #define Enable_interrupt() sei()
00393 #define Disable_interrupt() cli()
00394 #define Get_interrupt_state()       (SREG&0x80)
00395 
00396    #endif
00397 #endif /* _COMPILER_H_ */
00398 

Generated on Wed Sep 23 09:17:02 2009 for ATMEL by  doxygen 1.5.3