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