compiler.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
#ifndef _COMPILER_H_
00019
#define _COMPILER_H_
00020
00021
00022
#ifndef ASM_INCLUDE // define ASM_INCLUDE in your assembly source before including any .h file
00023
00024 typedef float Float16;
00025
00026 typedef unsigned char U8 ;
00027 typedef unsigned short U16;
00028 typedef unsigned long U32;
00029 typedef char S8 ;
00030 typedef short S16;
00031 typedef long S32;
00032
#if (defined __C51__)
00033
typedef bit
Bool;
00034
#else
00035 typedef unsigned char Bool;
00036
#endif
00037
00038 typedef U8 Status;
00039 typedef Bool Status_bool;
00040 #define PASS 0
00041 #define FAIL 1
00042
00043
00044
00045
#if (defined __C51__)
00046
# define _MEM_TYPE_BIT_ bdata // Used for bit accesses
00047
# define _MEM_TYPE_FAST_ data
00048
# define _MEM_TYPE_MEDFAST_ idata
00049
# define _MEM_TYPE_MEDSLOW_ pdata
00050
# define _MEM_TYPE_SLOW_ xdata
00051
#else
00052 # define _MEM_TYPE_BIT_
00053 # define _MEM_TYPE_FAST_
00054 # define _MEM_TYPE_MEDFAST_
00055 # define _MEM_TYPE_MEDSLOW_
00056 # define _MEM_TYPE_SLOW_
00057
#endif
00058
00059 typedef union
00060
{
00061 U32 dw ;
00062
00063 U32 l ;
00064 U16 w[2];
00065 U8 b[4];
00066 }
Union32;
00067
00068
00069
00070 typedef union
00071
{
00072 U16 w ;
00073 U8 b[2];
00074 }
Union16;
00075
#endif // ASM_INCLUDE
00076
00077
00078
00079
00080
#ifndef ASM_INCLUDE
00081 # define Max(a, b) ( (a)>(b) ? (a) : (b) ) // Take the max between a and b
00082 # define Min(a, b) ( (a)<(b) ? (a) : (b) ) // Take the min between a and b
00083 # define Align_up(val, n) ( ((val)+(n)-1) & ~((n)-1) ) // Around (up) the number (val) on the (n) boundary
00084 # define Align_down(val, n) ( (val) & ~((n)-1) ) // Around (down) the number (val) on the (n) boundary
00085
#endif // ASM_INCLUDE
00086
00087
00088 #define INTEL_ALIGNMENT LITTLE_ENDIAN
00089 #define MOTOROLA_ALIGNMENT BIG_ENDIAN
00090
00091
00092
#ifdef LITTLE_ENDIAN // => 16bit: (LSB,MSB), 32bit: (LSW,MSW) or (LSB0,LSB1,LSB2,LSB3) or (MSB3,MSB2,MSB1,MSB0)
00093
# define MSB(u16) (((U8* )&u16)[1])
00094
# define LSB(u16) (((U8* )&u16)[0])
00095
# define MSW(u32) (((U16*)&u32)[1])
00096
# define LSW(u32) (((U16*)&u32)[0])
00097
# define MSB0(u32) (((U8* )&u32)[3])
00098
# define MSB1(u32) (((U8* )&u32)[2])
00099
# define MSB2(u32) (((U8* )&u32)[1])
00100
# define MSB3(u32) (((U8* )&u32)[0])
00101
# define LSB0(u32) MSB3(u32)
00102
# define LSB1(u32) MSB2(u32)
00103
# define LSB2(u32) MSB1(u32)
00104
# define LSB3(u32) MSB0(u32)
00105
#else // BIG_ENDIAN => 16bit: (MSB,LSB), 32bit: (MSW,LSW) or (LSB3,LSB2,LSB1,LSB0) or (MSB0,MSB1,MSB2,MSB3)
00106 # define MSB(u16) (((U8* )&u16)[0])
00107 # define LSB(u16) (((U8* )&u16)[1])
00108 # define MSW(u32) (((U16*)&u32)[0])
00109 # define LSW(u32) (((U16*)&u32)[1])
00110 # define MSB0(u32) (((U8* )&u32)[0])
00111 # define MSB1(u32) (((U8* )&u32)[1])
00112 # define MSB2(u32) (((U8* )&u32)[2])
00113 # define MSB3(u32) (((U8* )&u32)[3])
00114 # define LSB0(u32) MSB3(u32)
00115 # define LSB1(u32) MSB2(u32)
00116 # define LSB2(u32) MSB1(u32)
00117 # define LSB3(u32) MSB0(u32)
00118
#endif
00119
00120
00121 #define Le16(b) \
00122
( ((U16)( (b) & 0xFF) << 8) \
00123
| ( ((U16)(b) & 0xFF00) >> 8) \
00124
)
00125 #define Le32(b) \
00126
( ((U32)( (b) & 0xFF) << 24) \
00127
| ((U32)((U16)(b) & 0xFF00) << 8) \
00128
| ( ((U32)(b) & 0xFF0000) >> 8) \
00129
| ( ((U32)(b) & 0xFF000000) >> 24) \
00130
)
00131
00132
00133
00134
00135
#ifdef LITTLE_ENDIAN
00136
# define htons(a) LE16(a)
00137
# define ntohs(a) htons(a)
00138
# define htonl(a) LE32(a)
00139
# define ntohl(a) htonl(a)
00140
#else
00141 # define htons(a) (a)
00142 # define ntohs(a) (a)
00143 # define htonl(a) (a)
00144 # define ntohl(a) (a)
00145
#endif
00146
00147
00148
#ifndef _CONST_TYPE_
00149 # define _CONST_TYPE_ code
00150
#endif
00151
#ifndef _MEM_TYPE_
00152
# define _MEM_TYPE_
00153
#endif
00154
00155
00156 #define ENABLE 1
00157 #define ENABLED 1
00158 #define DISABLED 0
00159 #define DISABLE 0
00160 #define FALSE (0==1)
00161 #define TRUE (1==1)
00162 #define KO 0
00163 #define OK 1
00164
00165
#ifndef ASM_INCLUDE
00166 # define CLR 0
00167 # define SET 1
00168
#endif
00169
00170
00171
00172
00173
00174
00175
#ifndef ASM_INCLUDE
00176 # define Low(U16) ((U8)U16)
00177 # define High(U16) ((U8)(U16>>8))
00178 # define Tst_bit_x(addrx,mask) (*addrx & mask)
00179 # define Set_bit_x(addrx,mask) (*addrx = (*addrx | mask))
00180 # define Clr_bit_x(addrx,mask) (*addrx = (*addrx & ~mask))
00181 # define Out_x(addrx,value) (*addrx = value)
00182 # define In_x(addrx) (*addrx)
00183
#endif // ASM_INCLUDE
00184
00192 #define Long_call(addr) ((*(void (_CONST_TYPE_*)(void))(addr))())
00193
00194
00195
00196
00197
#ifndef ASM_INCLUDE
00198 typedef unsigned char Uint8;
00199 typedef unsigned char Uchar;
00200 typedef unsigned char Byte;
00201 typedef unsigned int Uint16;
00202 typedef unsigned long int Uint32;
00203 typedef char Int8;
00204 typedef int Int16;
00205 typedef long int Int32;
00206 typedef unsigned int Word;
00207 typedef unsigned long int DWord;
00208
00209 # define LOW(U16) ((U8)U16) // Obsolete. Please use Low(x)
00210 # define HIGH(U16) ((U8)(U16>>8)) // Obsolete. Please use High(x)
00211 # define TST_BIT_X(addrx,mask) (*addrx & mask) // Obsolete. Please use Tst_bit_x
00212 # define SET_BIT_X(addrx,mask) (*addrx = (*addrx | mask)) // Obsolete. Please use Set_bit_x
00213 # define CLR_BIT_X(addrx,mask) (*addrx = (*addrx & ~mask)) // Obsolete. Please use Clr_bit_x
00214 # define OUT_X(addrx,value) (*addrx = value) // Obsolete. Please use Out_x
00215 # define IN_X(addrx) (*addrx) // Obsolete. Please use In_x
00216
00217
00218
# ifndef _ConstType_
00219 # define _ConstType_ code
00220
# endif
00221
00222
# ifndef _MemType_
00223
# define _MemType_
00224
# endif
00225
00226
# ifndef _GenericType_
00227
# define _GenericType_
00228
# endif
00229
00230
#endif // ASM_INCLUDE
00231
00232
00233
00234
#ifdef KEIL // KEIL compiler
00235
00236
# define Reentrant(x) x reentrant
00237
# define Sfr(x,y) sfr x = y
00238
# define Sfr16(x,y) sfr16 x = y
00239
# define Sbit(x,y,z) sbit x = y ^ z
00240
# define Interrupt(x,y) x interrupt y
00241
# define At(x) _at_ x
00242
00243
# ifdef __C51__ // C51 Compiler
00244
# define far xdata // far is for C251 only
00245
# endif
00246
#endif // End of KEIL
00247
00248
00249
00250
#ifdef RAISONANCE // RAISONANCE compiler
00251
00252
# define Reentrant(x) x reentrant
00253
# define Sfr(x,y) sfr x = y
00254
# define Sbit(x,y,z) sbit x = y ^ z
00255
# define Interrupt(x,y) x interrupt y
00256
# define At(x) _at_ x
00257
00258
# ifdef __C51__ // C51 Compiler
00259
# define far xdata // far is for 251 only
00260
# endif
00261
#endif // End of RAISONANCE
00262
00263
00264
00265
#ifdef TASKING // TASKING compiler
00266
00267
# include <keil.h>
00268
# define far _far
00269
# define Reentrant(x) _reentrant x
00270
# define Sfr(x,y) _sfrbyte x _at(y)
00271
# define Sbit(x,y,z) _sfrbit x _atbit(y,z)
00272
# define Interrupt(x,y) _interrupt(y) x
00273
00274
#endif // End of TASKING
00275
00276
00277
00278
#ifdef _IAR_AVR_
00279
00280
# define __IOMACRO_H
00281
# define TID_GUARD(proc) ((__TID__ & 0x7FF0) != ((90 << 8) | ((proc) << 4)))
00282
00283
# if !(__IAR_SYSTEMS_ICC__ > 2) && !defined(__IAR_SYSTEMS_ASM__)
00284
# error This file should only be compiled with iccavr or aavr.
00285
# endif // !(__IAR_SYSTEMS_ICC__ > 2) && !defined __IAR_SYSTEMS_ASM__
00286
00287
00288
# ifdef __IAR_SYSTEMS_ASM__
00289
00290
00291
# define SFR_B_BITS(_NAME,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
00292
sfrb _NAME = _ADDR
00293
00294
# define SFR_B_BITS_EXT(_NAME,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
00295
sfrb _NAME = _ADDR
00296
00297
# define SFR_B2_BITS(_NAME1,_NAME2,_ADDR,_A,_B,_C,_D,_E,_F,_G,_H)\
00298
ASMSFRB2 _NAME1, _NAME2, _ADDR
00299
00300 ASMSFRB2 MACRO
00301 sfrb \1 = \3
00302 sfrb \2 = \3
00303 ENDM
00304
00305
00306
00307
# define SFR_W_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P)\
00308
ASMSFRW _NAME, _ADDR
00309
00310
# define SFR_W_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P)\
00311
ASMSFRW _NAME, _ADDR
00312
00313 ASMSFRW MACRO
00314 sfrw \1 = \2
00315 sfrb \1L = (\2+0)
00316 sfrb \1H = (\2+1)
00317 ENDM
00318
00319
# endif // __IAR_SYSTEMS_ASM__
00320
00321
00322
00323
# ifdef __ICCAVR__
00324
00325
# define __BYTEBITS(_NAME,_A,_B,_C,_D,_E,_F,_G,_H) \
00326
U8 _NAME ## _ ## _A:1, \
00327
_NAME ## _ ## _B:1, \
00328
_NAME ## _ ## _C:1, \
00329
_NAME ## _ ## _D:1, \
00330
_NAME ## _ ## _E:1, \
00331
_NAME ## _ ## _F:1, \
00332
_NAME ## _ ## _G:1, \
00333
_NAME ## _ ## _H:1;
00334
00335
# define SFR_B_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
00336
__io union \
00337
{ \
00338
U8 _NAME; \
00339 struct \
00340 { \
00341 __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) \
00342 }; \
00343 } @ _ADDR;
00344
00345
# define SFR_B2_BITS(_NAME1, _NAME2, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
00346
__io union \
00347
{ \
00348
U8 _NAME1; \
00349 U8 _NAME2; \
00350 struct \
00351 { \
00352 __BYTEBITS(_NAME1, _A,_B,_C,_D,_E,_F,_G,_H) \
00353 }; \
00354 struct \
00355 { \
00356 __BYTEBITS(_NAME2, _A,_B,_C,_D,_E,_F,_G,_H) \
00357 }; \
00358 } @ _ADDR;
00359
00360
# define SFR_B_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H) \
00361
__tiny __no_init volatile union \
00362
{ \
00363
U8 _NAME; \
00364 struct \
00365 { \
00366 __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) \
00367 }; \
00368 } @ _ADDR;
00369
00370
# define SFR_W_BITS(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P) \
00371
__io union \
00372
{ \
00373
U16 _NAME; \
00374 struct \
00375 { \
00376 __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) \
00377 __BYTEBITS(_NAME, _I,_J,_K,_L,_M,_N,_O,_P) \
00378 }; \
00379 struct \
00380 { \
00381 U8 _NAME ## L; \
00382 U8 _NAME ## H; \
00383 }; \
00384 struct \
00385 { \
00386 __BYTEBITS(_NAME ## L, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7) \
00387 __BYTEBITS(_NAME ## H, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7) \
00388 }; \
00389 } @ _ADDR;
00390
00391
# define SFR_W_BITS_EXT(_NAME, _ADDR, _A,_B,_C,_D,_E,_F,_G,_H, _I,_J,_K,_L,_M,_N,_O,_P) \
00392
__tiny __no_init volatile union { \
00393
U16 _NAME; \
00394
struct \
00395 { \
00396 __BYTEBITS(_NAME, _A,_B,_C,_D,_E,_F,_G,_H) \
00397 __BYTEBITS(_NAME, _I,_J,_K,_L,_M,_N,_O,_P) \
00398 }; \
00399 struct \
00400 { \
00401 U8 _NAME ## L; \
00402 U8 _NAME ## H; \
00403 }; \
00404 struct \
00405 { \
00406 __BYTEBITS(_NAME ## L, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7) \
00407 __BYTEBITS(_NAME ## H, Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7) \
00408 }; \
00409 } @ _ADDR;
00410
00411
# endif // __ICCAVR__
00412
00413
00414
00415
# define SFR_B(_NAME, _ADDR) SFR_B_BITS(_NAME, _ADDR, \
00416
Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
00417
00418
# define SFR_B2(_NAME1, _NAME2, _ADDR) SFR_B2_BITS(_NAME1, _NAME2, _ADDR, \
00419
Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
00420
00421
# define SFR_B_EXT(_NAME, _ADDR) SFR_B_BITS_EXT(_NAME, _ADDR, \
00422
Bit0,Bit1,Bit2,Bit3,Bit4,Bit5,Bit6,Bit7)
00423
00424
# define SFR_W(_NAME, _ADDR) SFR_W_BITS(_NAME, _ADDR, \
00425
Bit0,Bit1,Bit2 ,Bit3 ,Bit4 ,Bit5 ,Bit6 ,Bit7 , \
00426
Bit8,Bit9,Bit10,Bit11,Bit12,Bit13,Bit14,Bit15)
00427
00428
# define SFR_W_EXT(_NAME, _ADDR) SFR_W_BITS_EXT(_NAME, _ADDR, \
00429
Bit0,Bit1,Bit2 ,Bit3 ,Bit4 ,Bit5 ,Bit6 ,Bit7 , \
00430
Bit8,Bit9,Bit10,Bit11,Bit12,Bit13,Bit14,Bit15)
00431
00432
#endif // _IAR_AVR_
00433
00434
00435
#endif // _COMPILER_H_
Generated on Mon Apr 10 17:23:29 2006 for Atmel by
1.3.7