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