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