00001 #ifndef _COMPILER_H_
00002 #define _COMPILER_H_
00003
00004
00005
00006
00007
00008 #define LITTLE_ENDIAN
00009
00010 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file
00011 typedef float Float16;
00012
00013 typedef unsigned char U8 ;
00014 typedef unsigned short U16;
00015 typedef unsigned long U32;
00016 typedef signed char S8 ;
00017 typedef signed short S16;
00018 typedef long S32;
00019 typedef unsigned char Bool;
00020
00021
00022 typedef U8 Status;
00023 typedef Bool Status_bool;
00024 #define bool Bool
00025 #define PASS 0
00026 #define FAIL 1
00027
00028
00029
00030 #if (defined __C51__)
00031 # define _MEM_TYPE_BIT_ bdata // Used for bit accesses
00032 # define _MEM_TYPE_FAST_ data
00033 # define _MEM_TYPE_MEDFAST_ idata
00034 # define _MEM_TYPE_MEDSLOW_ pdata
00035 # define _MEM_TYPE_SLOW_ xdata
00036 #else
00037 # define _MEM_TYPE_BIT_
00038 # define _MEM_TYPE_FAST_
00039 # define _MEM_TYPE_MEDFAST_
00040 # define _MEM_TYPE_MEDSLOW_
00041 # define _MEM_TYPE_SLOW_
00042 #endif
00043
00044 typedef unsigned char Uchar;
00045
00046
00047 typedef unsigned char Uint8;
00048 typedef unsigned int Uint16;
00049 typedef unsigned long int Uint32;
00050
00051 typedef char Int8;
00052 typedef int Int16;
00053 typedef long int Int32;
00054
00055 typedef unsigned char Byte;
00056 typedef unsigned int Word;
00057 typedef unsigned long int DWord;
00058
00059 typedef union
00060 {
00061 Uint32 dw;
00062 Uint16 w[2];
00063 Uint8 b[4];
00064 } Union32;
00065
00066 typedef union
00067 {
00068 Uint16 w;
00069 Uint8 b[2];
00070 } Union16;
00071
00072 #ifdef __IAR_SYSTEMS_ICC__
00073 typedef char bit;
00074 typedef int p_uart_ptchar;
00075 typedef int r_uart_ptchar;
00076 #endif
00077 #ifdef __CODEVISIONAVR__
00078 typedef char bit;
00079 typedef int p_uart_ptchar;
00080 typedef char r_uart_ptchar;
00081 #endif
00082 #if !defined(__IAR_SYSTEMS_ICC__) && !defined(___ICC__)
00083 typedef char p_uart_ptchar;
00084 typedef char r_uart_ptchar;
00085 #endif
00086
00087 #endif
00088
00089
00090
00091
00092 #ifdef __ICC__
00093 #define _ConstType_ lit
00094 #define _MemType_
00095 #define _GenericType_ __generic
00096 #define code lit
00097 #define xdata
00098 #define idata
00099 #define data
00100 #endif
00101
00102
00103
00104 #ifdef __IAR_SYSTEMS_ICC__
00105 #include "inavr.h"
00106 #define _ConstType_ __flash
00107 #define _MemType_
00108 #define _GenericType_ __generic
00109 #ifdef __ICCAVR__
00110 #if (defined(__AT90USB1287__) || defined(__AT90USB1286__))
00111 #define code __farflash
00112 #define farcode __farflash
00113 #else
00114 #define code __flash
00115 #define farcode __flash
00116 #endif
00117 #elif defined __GNUC__
00118 #if (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__))
00119 #define code __farflash
00120 #define farcode __farflash
00121 #else
00122 #define code __flash
00123 #define farcode __flash
00124 #endif
00125 #endif
00126 #define xdata
00127 #define idata
00128 #define data
00129 #define At(x) @ x
00130 #define pdata
00131 #define bdata
00132
00133 #ifndef _CONST_TYPE_
00134 # define _CONST_TYPE_ code
00135 #endif
00136
00137 #define Enable_interrupt() __enable_interrupt()
00138 #define Disable_interrupt() __disable_interrupt()
00139 #define Get_interrupt_state() (SREG&0x80)
00140
00141 #include <iomacro.h>
00142 #define SFR_W_EXT(a,b) SFR_W_R(b,a)
00143
00144
00145 #endif
00146
00147
00148
00149
00150
00151
00152
00153 #define INTEL_ALIGNMENT LITTLE_ENDIAN
00154 #define MOTOROLA_ALIGNMENT BIG_ENDIAN
00155
00156
00157 #ifdef LITTLE_ENDIAN // => 16bit: (LSB,MSB), 32bit: (LSW,MSW) or (LSB0,LSB1,LSB2,LSB3) or (MSB3,MSB2,MSB1,MSB0)
00158 # define MSB(u16) (((U8* )&u16)[1])
00159 # define LSB(u16) (((U8* )&u16)[0])
00160 # define MSW(u32) (((U16*)&u32)[1])
00161 # define LSW(u32) (((U16*)&u32)[0])
00162 # define MSB0(u32) (((U8* )&u32)[3])
00163 # define MSB1(u32) (((U8* )&u32)[2])
00164 # define MSB2(u32) (((U8* )&u32)[1])
00165 # define MSB3(u32) (((U8* )&u32)[0])
00166 # define LSB0(u32) MSB3(u32)
00167 # define LSB1(u32) MSB2(u32)
00168 # define LSB2(u32) MSB1(u32)
00169 # define LSB3(u32) MSB0(u32)
00170 #else // BIG_ENDIAN => 16bit: (MSB,LSB), 32bit: (MSW,LSW) or (LSB3,LSB2,LSB1,LSB0) or (MSB0,MSB1,MSB2,MSB3)
00171 # define MSB(u16) (((U8* )&u16)[0])
00172 # define LSB(u16) (((U8* )&u16)[1])
00173 # define MSW(u32) (((U16*)&u32)[0])
00174 # define LSW(u32) (((U16*)&u32)[1])
00175 # define MSB0(u32) (((U8* )&u32)[0])
00176 # define MSB1(u32) (((U8* )&u32)[1])
00177 # define MSB2(u32) (((U8* )&u32)[2])
00178 # define MSB3(u32) (((U8* )&u32)[3])
00179 # define LSB0(u32) MSB3(u32)
00180 # define LSB1(u32) MSB2(u32)
00181 # define LSB2(u32) MSB1(u32)
00182 # define LSB3(u32) MSB0(u32)
00183 #endif
00184
00185
00186 #define Le16(b) \
00187 ( ((U16)( (b) & 0xFF) << 8) \
00188 | ( ((U16)(b) & 0xFF00) >> 8) \
00189 )
00190 #define Le32(b) \
00191 ( ((U32)( (b) & 0xFF) << 24) \
00192 | ((U32)((U16)(b) & 0xFF00) << 8) \
00193 | ( ((U32)(b) & 0xFF0000) >> 8) \
00194 | ( ((U32)(b) & 0xFF000000) >> 24) \
00195 )
00196
00197
00198
00199
00200
00201 #ifdef LITTLE_ENDIAN
00202 # define htons(a) Le16(a)
00203 #define ntohs(a) htons(a)
00204 # define htonl(a) Le32(a)
00205 #define ntohl(a) htonl(a)
00206 #else
00207 #define htons(a) (a)
00208 #define ntohs(a) (a)
00209 #define htonl(a) (a)
00210 #define ntohl(a) (a)
00211 #endif
00212
00213
00214
00215 #define ENABLE 1
00216 #define ENABLED 1
00217 #define DISABLED 0
00218 #define DISABLE 0
00219 #define FALSE (0==1)
00220 #define TRUE (1==1)
00221 #define true TRUE
00222 #define false FALSE
00223
00224
00225 #define KO 0
00226 #define OK 1
00227 #define OFF 0
00228 #define ON 1
00229 #ifndef NULL
00230 #define NULL 0
00231 #endif
00232 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file
00233 #define CLR 0
00234 #define SET 1
00235 #endif
00236
00237
00238 #define LOW(U16) ((Uchar)U16)
00239 #define HIGH(U16) ((Uchar)(U16>>8))
00240 #define TST_BIT_X(addrx,mask) (*addrx & mask)
00241 #define SET_BIT_X(addrx,mask) (*addrx = (*addrx | mask))
00242 #define CLR_BIT_X(addrx,mask) (*addrx = (*addrx & ~mask))
00243 #define OUT_X(addrx,value) (*addrx = value)
00244 #define IN_X(addrx) (*addrx)
00245
00246 # define Max(a, b) ( (a)>(b) ? (a) : (b) ) // Take the max between a and b
00247 # define Min(a, b) ( (a)<(b) ? (a) : (b) ) // Take the min between a and b
00248
00249
00250
00251
00252
00253
00254
00255
00256 # define Upper(val, n) ( ((val)+(n)) & ~((n)-1) )
00257
00258
00259
00260
00261
00262
00263
00264
00265 # define Align_up(val, n) ( ((val)+(n)-1) & ~((n)-1) )
00266
00267
00268
00269
00270
00271
00272
00273
00274 # define Align_down(val, n) ( (val) & ~((n)-1) )
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291 #define Long_call(addr) ((*(void (_ConstType_*)(void))(addr))())
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303 #define SET_SFR_BIT(sfr_reg, bit_pos, bit_val) { sfr_reg &= ~(1<<(bit_pos)); sfr_reg |= ((bit_val)<<(bit_pos));}
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313 #define bit_is_clear(PORT,POSITION) ((PORT & (1<<POSITION)) == 0 )
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323 #define bit_is_set(PORT,POSITION) ((PORT & (1<<POSITION)) != 0 )
00324
00325
00326
00327
00328
00329 #define TID_GUARD(proc) ((__TID__ & 0x7FF0) != ((90 << 8) | ((proc) << 4)))
00330
00331
00332
00333
00334
00335
00336 #ifdef __GNUC__
00337 #define _CONST_TYPE_
00338 #define _ConstType_ __flash
00339 #define _MemType_
00340 #define _GenericType_ __generic
00341 #define code PROGMEM
00342 #define xdata
00343 #define idata
00344 #define data
00345 #define At(x) @ x
00346 #define pdata
00347 #define bdata
00348 #define bit U8
00349 #include <avr/interrupt.h>
00350 #include <avr/pgmspace.h>
00351 #define Enable_interrupt() sei()
00352 #define Disable_interrupt() cli()
00353 #define Get_interrupt_state() (SREG&0x80)
00354
00355 #endif
00356 #endif
00357