compiler.h

Go to the documentation of this file.
00001 /*H**************************************************************************
00002 * $RCSfile: compiler.h,v $
00003 *----------------------------------------------------------------------------
00004 * Copyright (c) 2003 Atmel.
00005 *----------------------------------------------------------------------------
00006 * RELEASE:      $Name:  $
00007 * FILE_REV:     $Revision: 585 $
00008 * FILE_CVSID:   $Id: compiler.h 585 2007-12-11 16:43:17Z rletendu $
00009 *----------------------------------------------------------------------------
00010 * PURPOSE:
00011 * This file redefines dedicated IAR AVR
00012 * keywords in order to ensure that any source file can be processed by
00013 * these compilers.
00014 *****************************************************************************/
00015 
00016 #ifndef _COMPILER_H_
00017 #define _COMPILER_H_
00018 
00019 /*_____ I N C L U D E S ____________________________________________________*/
00020 
00021 
00022 /*_____ D E C L A R A T I O N S ____________________________________________*/
00023 #define LITTLE_ENDIAN
00024 
00025 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file
00026 typedef float               Float16;
00027 
00028 typedef unsigned char       U8 ;
00029 typedef unsigned short      U16;
00030 typedef unsigned long       U32;
00031 typedef signed char         S8 ;
00032 typedef signed short        S16;
00033 typedef long                S32;
00034 #if (defined __C51__)
00035 typedef bit                 Bool;    // Shall be used with _MEM_TYPE_BIT_ to optimize the memory.
00036 #else
00037 typedef unsigned char       Bool;
00038 #endif
00039 
00040 typedef U8                  Status;
00041 typedef Bool                Status_bool;
00042 #define PASS 0
00043 #define FAIL 1
00044 
00045 
00046 
00047 #if (defined __C51__)
00048 #  define _MEM_TYPE_BIT_              bdata  // Used for bit accesses
00049 #  define _MEM_TYPE_FAST_              data
00050 #  define _MEM_TYPE_MEDFAST_          idata
00051 #  define _MEM_TYPE_MEDSLOW_          pdata
00052 #  define _MEM_TYPE_SLOW_             xdata
00053 #else
00054 #  define _MEM_TYPE_BIT_
00055 #  define _MEM_TYPE_FAST_
00056 #  define _MEM_TYPE_MEDFAST_
00057 #  define _MEM_TYPE_MEDSLOW_
00058 #  define _MEM_TYPE_SLOW_
00059 #endif
00060 
00061 typedef unsigned char       Uchar;
00062 
00063 
00064 typedef unsigned char       Uint8;
00065 typedef unsigned int        Uint16;
00066 typedef unsigned long int   Uint32;
00067 
00068 typedef char                Int8;
00069 typedef int                 Int16;
00070 typedef long int            Int32;
00071 
00072 typedef unsigned char       Byte;
00073 typedef unsigned int        Word;
00074 typedef unsigned long int   DWord;
00075 
00076 typedef union
00077 {
00078   Uint32 dw; // l changed in dw (double word) because l is used for signed long...
00079   Uint16 w[2];
00080   Uint8  b[4];
00081 } Union32;
00082 
00083 typedef union
00084 {
00085   Uint16 w;
00086   Uint8  b[2];
00087 } Union16;
00088 
00089 #ifdef __IAR_SYSTEMS_ICC__
00090 typedef char     bit;
00091 typedef int      p_uart_ptchar;
00092 typedef int      r_uart_ptchar;
00093 #endif
00094 #ifdef __CODEVISIONAVR__
00095 typedef char     bit;
00096 typedef int      p_uart_ptchar;
00097 typedef char     r_uart_ptchar;
00098 #endif
00099 #if !defined(__IAR_SYSTEMS_ICC__) && !defined(___ICC__)
00100 typedef char      p_uart_ptchar;
00101 typedef char      r_uart_ptchar;
00102 #endif
00103 
00104 #endif
00105 
00106 /**********************************************************************************/
00107 /* codevision COMPILER (__CODEVISIONAVR__)                                                 */
00108 /**********************************************************************************/
00109 #ifdef __ICC__
00110 #define _ConstType_ lit
00111 #define _MemType_
00112 #define _GenericType_ __generic
00113 #define code lit
00114 #define xdata
00115 #define idata
00116 #define data
00117 #endif
00118 /**********************************************************************************/
00119 /* IAR COMPILER (__IAR_SYSTEMS_ICC__)                                             */
00120 /**********************************************************************************/
00121 #ifdef __IAR_SYSTEMS_ICC__
00122 #include "inavr.h"
00123 #define _ConstType_ __flash
00124 #define _MemType_
00125 #define _GenericType_ __generic
00126 #define code __flash
00127 #define farcode __farflash
00128 #define xdata
00129 #define idata
00130 #define data
00131 #define At(x) @ x
00132 #define pdata
00133 #define bdata
00134 // Memory Type Location
00135 #ifndef _CONST_TYPE_
00136 #  define _CONST_TYPE_ code
00137 #endif
00138 
00139 #define Enable_interrupt() __enable_interrupt()
00140 #define Disable_interrupt() __disable_interrupt()
00141 
00142 #include <iomacro.h>
00143 #define SFR_W_EXT(a,b) SFR_W_R(b,a)
00144 #endif
00145 
00146 
00147 /* General purpose defines */
00148 /*#define _ConstType_   __farflash
00149 #define _MemType_
00150 #define _GenericType_ __generic
00151 #define code __farflash
00152 #define xdata
00153 #define idata
00154 #define data*/
00155 
00156 
00157 
00158 
00159 /*_____ M A C R O S ________________________________________________________*/
00160 /* little-big endian management */
00161 #define INTEL_ALIGNMENT     LITTLE_ENDIAN
00162 #define MOTOROLA_ALIGNMENT  BIG_ENDIAN
00163 
00164 // U16/U32 endian handlers
00165 #ifdef LITTLE_ENDIAN     // => 16bit: (LSB,MSB), 32bit: (LSW,MSW) or (LSB0,LSB1,LSB2,LSB3) or (MSB3,MSB2,MSB1,MSB0)
00166 #  define MSB(u16)        (((U8* )&u16)[1])
00167 #  define LSB(u16)        (((U8* )&u16)[0])
00168 #  define MSW(u32)        (((U16*)&u32)[1])
00169 #  define LSW(u32)        (((U16*)&u32)[0])
00170 #  define MSB0(u32)       (((U8* )&u32)[3])
00171 #  define MSB1(u32)       (((U8* )&u32)[2])
00172 #  define MSB2(u32)       (((U8* )&u32)[1])
00173 #  define MSB3(u32)       (((U8* )&u32)[0])
00174 #  define LSB0(u32)       MSB3(u32)
00175 #  define LSB1(u32)       MSB2(u32)
00176 #  define LSB2(u32)       MSB1(u32)
00177 #  define LSB3(u32)       MSB0(u32)
00178 #else // BIG_ENDIAN         => 16bit: (MSB,LSB), 32bit: (MSW,LSW) or (LSB3,LSB2,LSB1,LSB0) or (MSB0,MSB1,MSB2,MSB3)
00179 #  define MSB(u16)        (((U8* )&u16)[0])
00180 #  define LSB(u16)        (((U8* )&u16)[1])
00181 #  define MSW(u32)        (((U16*)&u32)[0])
00182 #  define LSW(u32)        (((U16*)&u32)[1])
00183 #  define MSB0(u32)       (((U8* )&u32)[0])
00184 #  define MSB1(u32)       (((U8* )&u32)[1])
00185 #  define MSB2(u32)       (((U8* )&u32)[2])
00186 #  define MSB3(u32)       (((U8* )&u32)[3])
00187 #  define LSB0(u32)       MSB3(u32)
00188 #  define LSB1(u32)       MSB2(u32)
00189 #  define LSB2(u32)       MSB1(u32)
00190 #  define LSB3(u32)       MSB0(u32)
00191 #endif
00192 
00193 // Endian converters
00194 #define Le16(b)                        \
00195    (  ((U16)(     (b) &   0xFF) << 8)  \
00196    |  (     ((U16)(b) & 0xFF00) >> 8)  \
00197    )
00198 #define Le32(b)                             \
00199    (  ((U32)(     (b) &       0xFF) << 24)  \
00200    |  ((U32)((U16)(b) &     0xFF00) <<  8)  \
00201    |  (     ((U32)(b) &   0xFF0000) >>  8)  \
00202    |  (     ((U32)(b) & 0xFF000000) >> 24)  \
00203    )
00204 
00205 // host to network conversion: used for Intel HEX format, TCP/IP, ...
00206 // Convert a 16-bit value from host-byte order to network-byte order
00207 // Standard Unix, POSIX 1003.1g (draft)
00208 
00209 #ifdef LITTLE_ENDIAN
00210 #  define htons(a)    Le16(a)
00211 #define ntohs(a)    htons(a)
00212 #  define htonl(a)    Le32(a)
00213 #define ntohl(a)    htonl(a)
00214 #else
00215 #define htons(a)    (a)
00216 #define ntohs(a)    (a)
00217 #define htonl(a)    (a)
00218 #define ntohl(a)    (a)
00219 #endif
00220 
00221 
00222 // Constants
00223 #define ENABLE   1
00224 #define ENABLED  1
00225 #define DISABLED 0
00226 #define DISABLE  0
00227 #define FALSE   (0==1)
00228 #define TRUE    (1==1)
00229 
00230 #define KO      0
00231 #define OK      1
00232 #define OFF     0
00233 #define ON      1
00234 #ifndef NULL
00235 #define NULL    0
00236 #endif
00237 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file
00238 #define CLR     0
00239 #define SET     1
00240 #endif
00241 
00242 /* Bit and bytes manipulations */
00243 #define LOW(U16)                ((Uchar)U16)
00244 #define HIGH(U16)               ((Uchar)(U16>>8))
00245 #define TST_BIT_X(addrx,mask)   (*addrx & mask)
00246 #define SET_BIT_X(addrx,mask)   (*addrx = (*addrx | mask))
00247 #define CLR_BIT_X(addrx,mask)   (*addrx = (*addrx & ~mask))
00248 #define OUT_X(addrx,value)      (*addrx = value)
00249 #define IN_X(addrx)             (*addrx)
00250 
00251 #  define Max(a, b)            ( (a)>(b) ? (a) : (b) )       // Take the max between a and b
00252 #  define Min(a, b)            ( (a)<(b) ? (a) : (b) )       // Take the min between a and b
00253 
00254 // Align on the upper value <val> on a <n> boundary
00255 // i.e. Upper(0, 4)= 4
00256 //      Upper(1, 4)= 4
00257 //      Upper(2, 4)= 4
00258 //      Upper(3, 4)= 4
00259 //      Upper(4, 4)= 8
00260 //      ../..
00261 #  define Upper(val, n)        ( ((val)+(n)) & ~((n)-1) )
00262 
00263 // Align up <val> on a <n> boundary
00264 // i.e. Align_up(0, 4)= 0
00265 //      Align_up(1, 4)= 4
00266 //      Align_up(2, 4)= 4
00267 //      Align_up(3, 4)= 4
00268 //      Align_up(4, 4)= 4
00269 //      ../..
00270 #  define Align_up(val, n)     ( ((val)+(n)-1) & ~((n)-1) )
00271 
00272 // Align down <val> on a <n> boundary
00273 // i.e. Align_down(0, 4)= 0
00274 //      Align_down(1, 4)= 0
00275 //      Align_down(2, 4)= 0
00276 //      Align_down(3, 4)= 0
00277 //      Align_down(4, 4)= 4
00278 //      ../..
00279 #  define Align_down(val, n)   (  (val)        & ~((n)-1) )
00280 
00281 /*M**************************************************************************
00282 * NAME: Long_call
00283 *----------------------------------------------------------------------------
00284 * PARAMS:
00285 * addr: address of the routine to call
00286 *----------------------------------------------------------------------------
00287 * PURPOSE:
00288 * Call the routine at address addr: generate an Assembly LCALL addr opcode.
00289 *----------------------------------------------------------------------------
00290 * EXAMPLE:
00291 * Long_call(0); // Software reset (if no IT used before)
00292 *----------------------------------------------------------------------------
00293 * NOTE:
00294 * May be used as a long jump opcode in some special cases
00295 *****************************************************************************/
00296 #define Long_call(addr)         ((*(void (_ConstType_*)(void))(addr))())
00297 
00298 /* {For Langdoc} */
00299 
00300 /***********************************************************
00301  SET_SFR_BIT macro
00302   parameters
00303     sfr_reg : defined value in include file for sfr register
00304     bit_pos : defined value B_XX in include file for particular
00305               bit of sfr register
00306     bit_val : CLR / SET
00307 ************************************************************/
00308 #define SET_SFR_BIT(sfr_reg, bit_pos, bit_val) { sfr_reg &= ~(1<<(bit_pos)); sfr_reg |= ((bit_val)<<(bit_pos));}
00309 
00310 /***********************************************************
00311  bit_is_clear macro
00312   parameters
00313     PORT     : defined value in include file for sfr register
00314     POSITION : defined value in include file for particular
00315               bit of sfr register
00316   example : if (bit_is_clear(PORTB,PORTB3)) ...
00317 ************************************************************/
00318 #define bit_is_clear(PORT,POSITION) ((PORT & (1<<POSITION)) == 0 )
00319 
00320 /***********************************************************
00321  bit_is_set macro
00322   parameters
00323     PORT     : defined value in include file for sfr register
00324     POSITION : defined value in include file for particular
00325               bit of sfr register
00326   example : if (bit_is_set(PORTB,PORTB3)) ...
00327 ************************************************************/
00328 #define bit_is_set(PORT,POSITION) ((PORT & (1<<POSITION)) != 0 )
00329 
00330 
00331 
00332 
00333 
00334 #define TID_GUARD(proc) ((__TID__ & 0x7FF0) != ((90 << 8) | ((proc) << 4)))
00335 
00336 
00337 
00338 /******************************************************************************/
00339 /* GCC COMPILER                                                               */
00340 /******************************************************************************/
00341    #ifdef __GNUC__
00342 #define _CONST_TYPE_
00343 #define _ConstType_ __flash
00344 #define _MemType_
00345 #define _GenericType_ __generic
00346 #define code PROGMEM
00347 #define xdata
00348 #define idata
00349 #define data
00350 #define At(x) @ x
00351 #define pdata
00352 #define bdata
00353 #define bit U8
00354 #define bool U8
00355    //#include <avr/sfr_defs.h>
00356    #include <avr/interrupt.h>
00357    #include <avr/pgmspace.h>
00358    #define Enable_interrupt() sei()
00359    #define Disable_interrupt() cli()
00360 
00361    #endif
00362 #endif /* _COMPILER_H_ */
00363 

Generated on Mon Dec 1 11:12:20 2008 for AVR498 : Atmel BLDC control on ATAVRMC301 with ATtiny861 by  doxygen 1.5.4