⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 compiler.h

📁 mp3播放器
💻 H
📖 第 1 页 / 共 2 页
字号:
//! @file compiler.h,v
//!
//! Copyright (c) 2004 Atmel.
//!
//! Use of this program is subject to Atmel's End User License Agreement.
//! Please read file license.txt for copyright notice.
//!
//! @brief This file redefines dedicated KEIL, RAISONANCE, TASKING,
//! _IAR_AVR_(__IAR_SYSTEMS_ASM__ and __ICCAVR__)
//! keywords in order to ensure that any source file can be processed by
//! these compilers.
//!
//! @version 1.42 snd3-refd1-1_9_5 $Id: compiler.h,v 1.42 2006/07/20 15:40:45 ppatron Exp $
//!
//! @todo
//! @bug

#ifndef _COMPILER_H_
#define _COMPILER_H_

//_____ D E C L A R A T I O N S ____________________________________________
#ifndef ASM_INCLUDE // define ASM_INCLUDE in your assembly source before including any .h file

typedef float               Float16;

typedef unsigned char       U8 ;
typedef unsigned short      U16;
typedef unsigned long       U32;
typedef signed char         S8 ;
typedef signed short        S16;
typedef signed long         S32;
#if (defined __C51__)
typedef bit                 Bool;    // Shall be used with _MEM_TYPE_BIT_ to optimize the memory.
#else
typedef unsigned char       Bool;
#endif

typedef U8                  Status;
typedef Bool                Status_bool;
#define PASS 0
#define FAIL 1
#define LOW_LEVEL  0
#define HIGH_LEVEL 1


#if (defined __C51__)
#  define _MEM_TYPE_BIT_              bdata  // Used for bit accesses
#  define _MEM_TYPE_FAST_              data
#  define _MEM_TYPE_MEDFAST_          idata
#  define _MEM_TYPE_MEDSLOW_          pdata
#  define _MEM_TYPE_SLOW_             xdata
#else
#  define _MEM_TYPE_BIT_
#  define _MEM_TYPE_FAST_
#  define _MEM_TYPE_MEDFAST_
#  define _MEM_TYPE_MEDSLOW_
#  define _MEM_TYPE_SLOW_
#endif

typedef union
{
  U32 dw ; // obsolete for new firmware 
           // dw (double word) add both definition (l & dw) for compatibility 
  U32 l  ; // l changed in dw (double word) because l is used for signed long...
  U16 w[2];
  U8  b[4];
} Union32;



typedef union
{
  U16 w   ;
  U8  b[2];
} Union16;
#endif // ASM_INCLUDE

//_____ M A C R O S ________________________________________________________

// Some usefull macros...
#ifndef ASM_INCLUDE
#  define Max(a, b)            ( (a)>(b) ? (a) : (b) )       // Take the max between a and b
#  define Min(a, b)            ( (a)<(b) ? (a) : (b) )       // Take the min between a and b

// Align on the upper value <val> on a <n> boundary
// i.e. Upper(0, 4)= 4
//      Upper(1, 4)= 4
//      Upper(2, 4)= 4
//      Upper(3, 4)= 4
//      Upper(4, 4)= 8
//      ../..
#  define Upper(val, n)        ( ((val)+(n)) & ~((n)-1) )

// Align up <val> on a <n> boundary
// i.e. Align_up(0, 4)= 0
//      Align_up(1, 4)= 4
//      Align_up(2, 4)= 4
//      Align_up(3, 4)= 4
//      Align_up(4, 4)= 4
//      ../..
#  define Align_up(val, n)     ( ((val)+(n)-1) & ~((n)-1) )

// Align down <val> on a <n> boundary
// i.e. Align_down(0, 4)= 0
//      Align_down(1, 4)= 0
//      Align_down(2, 4)= 0
//      Align_down(3, 4)= 0
//      Align_down(4, 4)= 4
//      ../..
#  define Align_down(val, n)   (  (val)        & ~((n)-1) )
#endif // ASM_INCLUDE

// little-big endian management
#define INTEL_ALIGNMENT     LITTLE_ENDIAN
#define MOTOROLA_ALIGNMENT  BIG_ENDIAN

// U16/U32 endian handlers
#ifdef LITTLE_ENDIAN     // => 16bit: (LSB,MSB), 32bit: (LSW,MSW) or (LSB0,LSB1,LSB2,LSB3) or (MSB3,MSB2,MSB1,MSB0)
#  define MSB(u16)        (((U8* )&u16)[1])
#  define LSB(u16)        (((U8* )&u16)[0])
#  define MSW(u32)        (((U16*)&u32)[1])
#  define LSW(u32)        (((U16*)&u32)[0])
#  define MSB0(u32)       (((U8* )&u32)[3]) // MSB of u32
#  define MSB1(u32)       (((U8* )&u32)[2])
#  define MSB2(u32)       (((U8* )&u32)[1])
#  define MSB3(u32)       (((U8* )&u32)[0]) // LSB of u32
#  define LSB0(u32)       MSB3(u32)         // LSB of u32
#  define LSB1(u32)       MSB2(u32)                      
#  define LSB2(u32)       MSB1(u32)                      
#  define LSB3(u32)       MSB0(u32)         // MSB of u32
#else // BIG_ENDIAN         => 16bit: (MSB,LSB), 32bit: (MSW,LSW) or (LSB3,LSB2,LSB1,LSB0) or (MSB0,MSB1,MSB2,MSB3)
#  define MSB(u16)        (((U8* )&u16)[0])
#  define LSB(u16)        (((U8* )&u16)[1])
#  define MSW(u32)        (((U16*)&u32)[0])
#  define LSW(u32)        (((U16*)&u32)[1])
#  define MSB0(u32)       (((U8* )&u32)[0]) // MSB of u32
#  define MSB1(u32)       (((U8* )&u32)[1])
#  define MSB2(u32)       (((U8* )&u32)[2])
#  define MSB3(u32)       (((U8* )&u32)[3]) // LSB of u32
#  define LSB0(u32)       MSB3(u32)         // LSB of u32
#  define LSB1(u32)       MSB2(u32)
#  define LSB2(u32)       MSB1(u32)
#  define LSB3(u32)       MSB0(u32)         // MSB of u32
#endif

// Endian converters
#define Le16(b)                        \
   (  ((U16)(     (b) &   0xFF) << 8)  \
   |  (     ((U16)(b) & 0xFF00) >> 8)  \
   )
#define Le32(b)                             \
   (  ((U32)(     (b) &       0xFF) << 24)  \
   |  ((U32)((U16)(b) &     0xFF00) <<  8)  \
   |  (     ((U32)(b) &   0xFF0000) >>  8)  \
   |  (     ((U32)(b) & 0xFF000000) >> 24)  \
   )

// host to network conversion: used for Intel HEX format, TCP/IP, ...
// Convert a 16-bit value from host-byte order to network-byte order
// Standard Unix, POSIX 1003.1g (draft)
#ifdef LITTLE_ENDIAN
#  define htons(a)    LE16(a)
#  define ntohs(a)    htons(a)
#  define htonl(a)    LE32(a)
#  define ntohl(a)    htonl(a)
#else
#  define htons(a)    (a)
#  define ntohs(a)    (a)
#  define htonl(a)    (a)
#  define ntohl(a)    (a)
#endif

// Memory Type Location
#ifndef _CONST_TYPE_
#  define _CONST_TYPE_ code
#endif
#ifndef _MEM_TYPE_
#  define _MEM_TYPE_
#endif

// Constants
#define ENABLE   1
#define ENABLED  1
#define DISABLED 0
#define DISABLE  0
#define FALSE   (0==1)
#define TRUE    (1==1)
#define KO      0
#define OK      1

#ifndef ASM_INCLUDE
#  define CLR     0
#  define SET     1
#endif





// Bit and bytes manipulations
#ifndef ASM_INCLUDE
#  define Low(U16)                ((U8)U16)
#  define High(U16)               ((U8)(U16>>8))
#  define Tst_bit_x(addrx,mask)   (*addrx & mask)
#  define Set_bit_x(addrx,mask)   (*addrx = (*addrx |  mask))
#  define Clr_bit_x(addrx,mask)   (*addrx = (*addrx & ~mask))
#  define Out_x(addrx,value)      (*addrx = value)
#  define In_x(addrx)             (*addrx)
#endif // ASM_INCLUDE

//! @brief Call the routine at address addr: generate an Assembly LCALL addr opcode.
//!        Example: Long_call(0); // Software reset (if no IT used before)
//!
//! NOTE:
//! May be used as a long jump opcode in some special cases
//!
//! @param addr   address of the routine to call.
#define Long_call(addr)         ((*(void (_CONST_TYPE_*)(void))(addr))())


// The next definitions are obsoletes
// ----------------------------------
#ifndef ASM_INCLUDE
typedef unsigned char       Uint8;   // Obsolete. Please use U8
typedef unsigned char       Uchar;   // Obsolete. Please use U8
typedef unsigned char       Byte;    // Obsolete. Please use U8
typedef unsigned int        Uint16;  // Obsolete. Please use U16
typedef unsigned long int   Uint32;  // Obsolete. Please use U32
typedef char                Int8;    // Obsolete. Please use S8
typedef int                 Int16;   // Obsolete. Please use S16
typedef long int            Int32;   // Obsolete. Please use S32
typedef unsigned int        Word;    // Obsolete. Please use U16
typedef unsigned long int   DWord;   // Obsolete. Please use U32 S32

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -