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