|
楼主 |
发表于 2009-7-27 23:45:44
|
显示全部楼层
compiler.h <font color=brown>
#ifndef _USE_COMPILER_H_
#define _USE_COMPILER_H_
/*! /name The macros to identify the compiler
*/
//! @{
#ifdef __IS_COMPILER_ICC__
#undef __IS_COMPILER_ICC__
#endif
#define __IS_COMPILER_ICC__ defined(__ICC_VERSION)
#ifdef __IS_COMPILER_IAR__
#undef __IS_COMPILER_IAR__
#endif
#define __IS_COMPILER_IAR__ defined(__IAR_SYSTEMS_ICC__)
#ifdef __IS_COMPILER_GCC__
#undef __IS_COMPILER_GCC__
#endif
#define __IS_COMPILER_GCC__ __GNUC__
//! @}
#if __IS_COMPILER_ICC__
#include <iccioavr.h>
#elif __IS_COMPILER_GCC__
#include <avr/io.h>
#include <avr/interrupt.h>
#elif __IS_COMPILER_IAR__
#ifndef _USE_IGNORE_IAR_IOAVR_H_
#ifndef _DEVICE_IO
#define _DEVICE_IO
#include <ioavr.h>
#endif
#endif
#endif
/*
*! using the ANSI-C99 standard type,if the file stdint.h dose not exit
* you should define it all by yourself.
*/
#if __IS_COMPILER_ICC__ || __IS_COMPILER_IAR__
typedef unsigned char uint8_t;
typedef signed char int8_t;
typedef unsigned int uint16_t;
typedef signed int int16_t;
typedef unsigned long uint32_t;
typedef signed long int32_t;
typedef unsigned char bool;
#else
#include <stdint.h>
#include <stdbool.h>
#endif
typedef double ES_DOUBLE;
typedef float ES_FLOAT;
#include "Snail_UseBITs.h"
/*
*! The boolean data type
*/
typedef bool ES_BOOL;
/*! /name Value of boolean
*/
//! @{
#ifndef false
# define false 0x00
#endif
#ifndef ES_FALSE
# define ES_FALSE false
#endif
#ifndef true
# define true (!false)
#endif
#ifndef ES_TRUE
# define ES_TRUE true
#endif
//! @}
#if __IS_COMPILER_GCC__
#include <avr/interrupt.h>
#elif __IS_COMPILER_IAR__
#ifndef PRAGMA
#define PRAGMA(__STRING) _Pragma(#__STRING)
#endif
#ifndef ISR
#define ISR(num) PRAGMA( vector = num ) __interrupt void isr_##num(void)
#endif
#endif
//! The mcu memory align mode
# define MCU_MEM_ALIGN_SIZE sizeof(int)
//! The mcu memory endian mode
# define MCU_MEM_LITTLE_ENDIAN ES_TRUE
//! The default NULL value
#ifndef NULL
# define NULL (0x00)
#endif
/*! /name The system level macros
*/
//! @{
#define MAX(__A,__B) (((__A) > (__B)) ? (__A) : (__B))
#define MIN(__A,__B) (((__A) < (__B)) ? (__A) : (__B))
#define UBOUND(__ARRAY) (sizeof(__ARRAY)/sizeof(__ARRAY[0]))
# define ABS(__NUM) (((__NUM) < 0)?(-(__NUM)):(__NUM))
#define BIT(__N) (1 << (__N))
//! This macro convert variable types between different datatypes.
# define TYPE_CONVERSION(__ADDR,__TYPE) (*((__TYPE *)(__ADDR)))
#if __IS_COMPILER_GCC__
# define ENABLE_GLOBAL_INTERRUPT __asm__ __volatile__("sei");
# define DISABLE_GLOBAL_INTERRUPT __asm__ __volatile__("cli");
//! @}
# define RELOAD_WATCHDOG __asm__ __volatile__("wdr");
# define NOP __asm__ __volatile__("nop");
#elif __IS_COMPILER_ICC__ || __IS_COMPILER_IAR__
# define ENABLE_GLOBAL_INTERRUPT asm("sei");
# define DISABLE_GLOBAL_INTERRUPT asm("cli");
//! @}
# define RELOAD_WATCHDOG asm("wdr");
#ifndef NOP
# define NOP asm("nop");
#endif
#endif
//! The ATOM code section macro
# define SAFE_CODE_PERFORMANCE(__CODE) \
do\
{\
unsigned char chTempSREG = SREG;\
DISABLE_GLOBAL_INTERRUPT\
__CODE;\
SREG = chTempSREG;\
}\
while (0);
//! Exit from the atom operations
# define EXIT_SAFE_CODE SREG = chTempSREG;
//! Get Interrupt state
# define GET_INTERRUPT_STATE() ((SREG & 0x80) ? ES_TRUE : ES_FALSE)
# define OBJECT_INIT_ZERO(__OBJECT) \
do\
{\
struct OBJECT_INIT\
{\
uint8_t StructMask[sizeof(__OBJECT)];\
}NULL_OBJECT = {0};\
\
*(struct OBJECT_INIT *)&(__OBJECT) = NULL_OBJECT;\
}\
while (0)
#if __IS_COMPILER_ICC__ || __IS_COMPILER_IAR__
# define ES_FLASH __flash
#elif __IS_COMPILER_GCC__
# define ES_FLASH const
#endif
#endif |
|