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

Generated on Fri Sep 11 14:25:27 2009 for ATMEL by  doxygen 1.5.3