📄 compiler.h
字号:
/*This file is prepared for Doxygen automatic documentation generation.*/
/*! \file *********************************************************************
*
* \brief Compiler file for AVR32.
*
* This file defines commonly used types and macros.
*
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
* - Supported devices: All AVR32 devices can be used.
* - AppNote:
*
* \author Atmel Corporation: http://www.atmel.com \n
* Support and FAQ: http://support.atmel.no/
*
******************************************************************************/
/* Copyright (c) 2007, Atmel Corporation All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. The name of ATMEL may not be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
* SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _COMPILER_H_
#define _COMPILER_H_
#if (__GNUC__ && __AVR32__) || (__ICCAVR32__ || __AAVR32__)
# include <avr32/io.h>
#endif
#if __ICCAVR32__
# include <intrinsics.h>
#endif
#include "preprocessor.h"
//_____ D E C L A R A T I O N S ____________________________________________
#ifdef __AVR32_ABI_COMPILER__ // Automatically defined when compiling for AVR32, not when assembling.
#include <stddef.h>
#include <stdlib.h>
#if __ICCAVR32__
/*! \name Compiler Keywords
*
* Port of some keywords from GNU GCC for AVR32 to IAR Embedded Workbench for Atmel AVR32.
*/
//! @{
#define __asm__ asm
#define __inline__ inline
#define __volatile__
//! @}
#endif
/*! \name Usual Types
*/
//! @{
typedef unsigned char Bool; //!< Boolean.
typedef unsigned char U8 ; //!< 8-bit unsigned integer.
typedef unsigned short int U16; //!< 16-bit unsigned integer.
typedef unsigned long int U32; //!< 32-bit unsigned integer.
typedef unsigned long long int U64; //!< 64-bit unsigned integer.
typedef signed char S8 ; //!< 8-bit signed integer.
typedef signed short int S16; //!< 16-bit signed integer.
typedef signed long int S32; //!< 32-bit signed integer.
typedef signed long long int S64; //!< 64-bit signed integer.
typedef float F32; //!< 32-bit floating-point number.
typedef double F64; //!< 64-bit floating-point number.
//! @}
/*! \name Status Types
*/
//! @{
typedef Bool Status_bool_t; //!< Boolean status.
typedef U8 Status_t; //!< 8-bit-coded status.
//! @}
/*! \name Aliasing Aggregate Types
*/
//! @{
//! 16-bit union.
typedef union
{
U16 u16 ;
U8 u8 [2];
} Union16;
//! 32-bit union.
typedef union
{
U32 u32 ;
U16 u16[2];
U8 u8 [4];
} Union32;
//! 64-bit union.
typedef union
{
U64 u64 ;
U32 u32[2];
U16 u16[4];
U8 u8 [8];
} Union64;
//! Union of pointers to 64-, 32-, 16- and 8-bit unsigned integers.
typedef union
{
U64 *u64ptr;
U32 *u32ptr;
U16 *u16ptr;
U8 *u8ptr ;
} UnionPtr;
//! Union of pointers to volatile 64-, 32-, 16- and 8-bit unsigned integers.
typedef union
{
volatile U64 *u64ptr;
volatile U32 *u32ptr;
volatile U16 *u16ptr;
volatile U8 *u8ptr ;
} UnionVPtr;
//! Union of pointers to constant 64-, 32-, 16- and 8-bit unsigned integers.
typedef union
{
const U64 *u64ptr;
const U32 *u32ptr;
const U16 *u16ptr;
const U8 *u8ptr ;
} UnionCPtr;
//! Union of pointers to constant volatile 64-, 32-, 16- and 8-bit unsigned integers.
typedef union
{
const volatile U64 *u64ptr;
const volatile U32 *u32ptr;
const volatile U16 *u16ptr;
const volatile U8 *u8ptr ;
} UnionCVPtr;
//! Structure of pointers to 64-, 32-, 16- and 8-bit unsigned integers.
typedef struct
{
U64 *u64ptr;
U32 *u32ptr;
U16 *u16ptr;
U8 *u8ptr ;
} StructPtr;
//! Structure of pointers to volatile 64-, 32-, 16- and 8-bit unsigned integers.
typedef struct
{
volatile U64 *u64ptr;
volatile U32 *u32ptr;
volatile U16 *u16ptr;
volatile U8 *u8ptr ;
} StructVPtr;
//! Structure of pointers to constant 64-, 32-, 16- and 8-bit unsigned integers.
typedef struct
{
const U64 *u64ptr;
const U32 *u32ptr;
const U16 *u16ptr;
const U8 *u8ptr ;
} StructCPtr;
//! Structure of pointers to constant volatile 64-, 32-, 16- and 8-bit unsigned integers.
typedef struct
{
const volatile U64 *u64ptr;
const volatile U32 *u32ptr;
const volatile U16 *u16ptr;
const volatile U8 *u8ptr ;
} StructCVPtr;
//! @}
#endif // __AVR32_ABI_COMPILER__
//_____ M A C R O S ________________________________________________________
/*! \name Usual Constants
*/
//! @{
#define DISABLE 0
#define ENABLE 1
#define DISABLED 0
#define ENABLED 1
#define OFF 0
#define ON 1
#define FALSE 0
#define TRUE 1
#define KO 0
#define OK 1
#define PASS 0
#define FAIL 1
#define LOW 0
#define HIGH 1
#define CLR 0
#define SET 1
//! @}
#ifdef __AVR32_ABI_COMPILER__ // Automatically defined when compiling for AVR32, not when assembling.
/*! \name Bit-Field Handling
*/
//! @{
/*! \brief Reads the bits of a value specified by a given bit-mask.
*
* \param value Value to read bits from.
* \param mask Bit-mask indicating bits to read.
*
* \return Read bits.
*/
#define Rd_bits( value, mask) ((value) & (mask))
/*! \brief Writes the bits of a C lvalue specified by a given bit-mask.
*
* \param lvalue C lvalue to write bits to.
* \param mask Bit-mask indicating bits to write.
* \param bits Bits to write.
*
* \return Resulting value with written bits.
*/
#define Wr_bits(lvalue, mask, bits) ((lvalue) = ((lvalue) & ~(mask)) |\
((bits ) & (mask)))
/*! \brief Tests the bits of a value specified by a given bit-mask.
*
* \param value Value of which to test bits.
* \param mask Bit-mask indicating bits to test.
*
* \return \c 1 if at least one of the tested bits is set, else \c 0.
*/
#define Tst_bits( value, mask) (Rd_bits(value, mask) != 0)
/*! \brief Clears the bits of a C lvalue specified by a given bit-mask.
*
* \param lvalue C lvalue of which to clear bits.
* \param mask Bit-mask indicating bits to clear.
*
* \return Resulting value with cleared bits.
*/
#define Clr_bits(lvalue, mask) ((lvalue) &= ~(mask))
/*! \brief Sets the bits of a C lvalue specified by a given bit-mask.
*
* \param lvalue C lvalue of which to set bits.
* \param mask Bit-mask indicating bits to set.
*
* \return Resulting value with set bits.
*/
#define Set_bits(lvalue, mask) ((lvalue) |= (mask))
/*! \brief Toggles the bits of a C lvalue specified by a given bit-mask.
*
* \param lvalue C lvalue of which to toggle bits.
* \param mask Bit-mask indicating bits to toggle.
*
* \return Resulting value with toggled bits.
*/
#define Tgl_bits(lvalue, mask) ((lvalue) ^= (mask))
/*! \brief Reads the bit-field of a value specified by a given bit-mask.
*
* \param value Value to read a bit-field from.
* \param mask Bit-mask indicating the bit-field to read.
*
* \return Read bit-field.
*/
#define Rd_bitfield( value, mask) (Rd_bits( value, mask) >> ctz(mask))
/*! \brief Writes the bit-field of a C lvalue specified by a given bit-mask.
*
* \param lvalue C lvalue to write a bit-field to.
* \param mask Bit-mask indicating the bit-field to write.
* \param bitfield Bit-field to write.
*
* \return Resulting value with written bit-field.
*/
#define Wr_bitfield(lvalue, mask, bitfield) (Wr_bits(lvalue, mask, (U32)(bitfield) << ctz(mask)))
//! @}
/*! \brief This macro is used to test fatal errors.
*
* The macro tests if the expression is FALSE. If it is, a fatal error is
* detected and the application hangs up.
*
* \param expr Expression to evaluate and supposed to be nonzero.
*/
#ifdef _ASSERT_ENABLE_
#define Assert(expr) \
{\
if (!(expr)) while (TRUE);\
}
#else
#define Assert(expr)
#endif
/*! \name Zero-Bit Counting
*
* Under AVR32-GCC, __builtin_clz and __builtin_ctz behave like macros when
* applied to constant expressions (values known at compile time), so they are
* more optimized than the use of the corresponding assembly instructions and
* they can be used as constant expressions e.g. to initialize objects having
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -