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 #ifdef __ICCAVR__
00151 #if (defined(__AT90USB1287__) || defined(__AT90USB1286__))
00152 #define code __farflash
00153 #define farcode __farflash
00154 #else
00155 #define code __flash
00156 #define farcode __flash
00157 #endif
00158 #elif defined __GNUC__
00159 #if (defined(__AVR_AT90USB1287__) || defined(__AVR_AT90USB1286__))
00160 #define code __farflash
00161 #define farcode __farflash
00162 #else
00163 #define code __flash
00164 #define farcode __flash
00165 #endif
00166 #endif
00167 #define xdata
00168 #define idata
00169 #define data
00170 #define At(x) @ x
00171 #define pdata
00172 #define bdata
00173
00174 #ifndef _CONST_TYPE_
00175 # define _CONST_TYPE_ code
00176 #endif
00177
00178 #define Enable_interrupt() __enable_interrupt()
00179 #define Disable_interrupt() __disable_interrupt()
00180 #define Get_interrupt_state() (SREG&0x80)
00181
00182 #include <iomacro.h>
00183 #define SFR_W_EXT(a,b) SFR_W_R(b,a)
00184
00185
00186 #endif
00187
00188
00189
00190
00191
00192
00193
00194 #define INTEL_ALIGNMENT LITTLE_ENDIAN
00195 #define MOTOROLA_ALIGNMENT BIG_ENDIAN
00196
00197
00198 #ifdef LITTLE_ENDIAN // => 16bit: (LSB,MSB), 32bit: (LSW,MSW) or (LSB0,LSB1,LSB2,LSB3) or (MSB3,MSB2,MSB1,MSB0)
00199 # define MSB(u16) (((U8* )&u16)[1])
00200 # define LSB(u16) (((U8* )&u16)[0])
00201 # define MSW(u32) (((U16*)&u32)[1])
00202 # define LSW(u32) (((U16*)&u32)[0])
00203 # define MSB0(u32) (((U8* )&u32)[3])
00204 # define MSB1(u32) (((U8* )&u32)[2])
00205 # define MSB2(u32) (((U8* )&u32)[1])
00206 # define MSB3(u32) (((U8* )&u32)[0])
00207 # define LSB0(u32) MSB3(u32)
00208 # define LSB1(u32) MSB2(u32)
00209 # define LSB2(u32) MSB1(u32)
00210 # define LSB3(u32) MSB0(u32)
00211 #else // BIG_ENDIAN => 16bit: (MSB,LSB), 32bit: (MSW,LSW) or (LSB3,LSB2,LSB1,LSB0) or (MSB0,MSB1,MSB2,MSB3)
00212 # define MSB(u16) (((U8* )&u16)[0])
00213 # define LSB(u16) (((U8* )&u16)[1])
00214 # define MSW(u32) (((U16*)&u32)[0])
00215 # define LSW(u32) (((U16*)&u32)[1])
00216 # define MSB0(u32) (((U8* )&u32)[0])
00217 # define MSB1(u32) (((U8* )&u32)[1])
00218 # define MSB2(u32) (((U8* )&u32)[2])
00219 # define MSB3(u32) (((U8* )&u32)[3])
00220 # define LSB0(u32) MSB3(u32)
00221 # define LSB1(u32) MSB2(u32)
00222 # define LSB2(u32) MSB1(u32)
00223 # define LSB3(u32) MSB0(u32)
00224 #endif
00225
00226
00227 #define Le16(b) \
00228 ( ((U16)( (b) & 0xFF) << 8) \
00229 | ( ((U16)(b) & 0xFF00) >> 8) \
00230 )
00231 #define Le32(b) \
00232 ( ((U32)( (b) & 0xFF) << 24) \
00233 | ((U32)((U16)(b) & 0xFF00) << 8) \
00234 | ( ((U32)(b) & 0xFF0000) >> 8) \
00235 | ( ((U32)(b) & 0xFF000000) >> 24) \
00236 )
00237
00238
00239
00240
00241
00242 #ifdef LITTLE_ENDIAN
00243 # define htons(a) Le16(a)
00244 #define ntohs(a) htons(a)
00245 # define htonl(a) Le32(a)
00246 #define ntohl(a) htonl(a)
00247 #else
00248 #define htons(a) (a)
00249 #define ntohs(a) (a)
00250 #define htonl(a) (a)
00251 #define ntohl(a) (a)
00252 #endif
00253
00254
00255
00256 #define ENABLE 1
00257 #define ENABLED 1
00258 #define DISABLED 0
00259 #define DISABLE 0
00260 #define FALSE (0==1)
00261 #define TRUE (1==1)
00262 #define true TRUE
00263 #define false FALSE
00264
00265
00266 #define KO 0
00267 #define OK 1
00268 #define OFF 0
00269 #define ON 1
00270 #ifndef NULL
00271 #define NULL 0
00272 #endif
00273 #ifndef ASM_INCLUDE // define ASM_INCLUDE in your a51 source code before include of .h file
00274 #define CLR 0
00275 #define SET 1
00276 #endif
00277
00278
00279 #define LOW(U16) ((Uchar)U16)
00280 #define HIGH(U16) ((Uchar)(U16>>8))
00281 #define TST_BIT_X(addrx,mask) (*addrx & mask)
00282 #define SET_BIT_X(addrx,mask) (*addrx = (*addrx | mask))
00283 #define CLR_BIT_X(addrx,mask) (*addrx = (*addrx & ~mask))
00284 #define OUT_X(addrx,value) (*addrx = value)
00285 #define IN_X(addrx) (*addrx)
00286
00287 # define Max(a, b) ( (a)>(b) ? (a) : (b) ) // Take the max between a and b
00288 # define Min(a, b) ( (a)<(b) ? (a) : (b) ) // Take the min between a and b
00289
00290
00291
00292
00293
00294
00295
00296
00297 # define Upper(val, n) ( ((val)+(n)) & ~((n)-1) )
00298
00299
00300
00301
00302
00303
00304
00305
00306 # define Align_up(val, n) ( ((val)+(n)-1) & ~((n)-1) )
00307
00308
00309
00310
00311
00312
00313
00314
00315 # define Align_down(val, n) ( (val) & ~((n)-1) )
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332 #define Long_call(addr) ((*(void (_ConstType_*)(void))(addr))())
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 #define SET_SFR_BIT(sfr_reg, bit_pos, bit_val) { sfr_reg &= ~(1<<(bit_pos)); sfr_reg |= ((bit_val)<<(bit_pos));}
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354 #define bit_is_clear(PORT,POSITION) ((PORT & (1<<POSITION)) == 0 )
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364 #define bit_is_set(PORT,POSITION) ((PORT & (1<<POSITION)) != 0 )
00365
00366
00367
00368
00369
00370 #define TID_GUARD(proc) ((__TID__ & 0x7FF0) != ((90 << 8) | ((proc) << 4)))
00371
00372
00373
00374
00375
00376
00377 #ifdef __GNUC__
00378 #define _CONST_TYPE_
00379 #define _ConstType_ __flash
00380 #define _MemType_
00381 #define _GenericType_ __generic
00382 #define code PROGMEM
00383 #define xdata
00384 #define idata
00385 #define data
00386 #define At(x) @ x
00387 #define pdata
00388 #define bdata
00389 #define bit U8
00390 #include <avr/interrupt.h>
00391 #include <avr/pgmspace.h>
00392 #define Enable_interrupt() sei()
00393 #define Disable_interrupt() cli()
00394 #define Get_interrupt_state() (SREG&0x80)
00395
00396 #endif
00397 #endif
00398