[LIB][ICC][GCC][IAR]AVR Software Framework - UTILS
[使用说明]1. 在每一个.c文件的开头加入对compiler.h的引用,将会得到对stdint、stdbool、中断、原子操作、强制类新转换等的支持,
注意,最好使用相对路径,例如,对于如下的目录结构,
|
+ UTILS
- Application
|
-Service
|
-MyService
|
-MyService.c
在Application\Service\MyService\MyService.c文件中应该加入
#include "..\..\..\UTILS\compiler.h"
2. 在你的代码中,可以用以下宏来配合#if / #elif 根据编译器的不同来选择性的编译代码
__IS_COMPILER_IAR__ -------------- 该宏用来判断当前编译器是否为IAR
__IS_COMPILER_GCC__ -------------- 该宏用来判断当前编译器是否为GCC
__IS_COMPILER_ICC__ -------------- 该宏用来判断当前编译器是否为ICC
3. 用以下的宏来标明某一段代码是原子操作
SAFE_CODE_PERFORMANCE(),例如
uint32_t wTempCounter;
SAFE_CODE_PERFORMANCE
(
wTempCounter = g_wCounter; //g_wCounter很可能是一个使用中断触发而累加的计数器
//这里还可以添加其他很多代码
)
//一些和wTempCounter相关的计算,上面的方式用来保证计数器操作的完整性
如果在原子操作中需要中途退出,应加入以下宏
EXIT_SAFE_CODE
4. 用宏OBJECT_INIT_ZERO()可以将任何大型数据结构初始化为0,并且能够尽可能的开启编译器自身的优化。
5. 对于IAR和GCC都可以使用ISR()来声明中断向量。ICC则需要特殊处理。
6. 目前只能同时兼容IAR、GCC和ICC。
<font color=red>[目录结构]
|
- UTILS
|
- compiler.h ------------编译器/平台无关性文件 部分对应RD_MacroAndConst.h
- Snail_Error.h ------------公共的错误类接口文件
- Snail_Error.c ------------公共的错误类模块文件.c
- Snail_UseBits.h ------------提供对各类位定义的支持对应RD_UseBits.h
+ PREPROCESSOR ------------这里同AVR32 Software Framework
[相关下载]
点击此处下载 ourdev_465073.rar(文件大小:12K) <font color=green>(原文件名:UTILS.rar) 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_ENDIANES_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))
# 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;\
}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 呼……Beta版本……累死俺了……希望大家拍砖……
以后的所有库函数,都会基于UTILS…… 顶。。。 顶。。。 顶傻孩子老大~谢谢 什么是UTILS? 占位观看 :-) to 【9楼】 bad_fpga
可以理解为common…… 占位学习 iccavr会悲剧的多...
效率... to 【13楼】 snoopyzz
ICC怎么了?不明白? 用iccavr越用的多,越觉得其编译器效率不好
最明显的是位域,即使是端口,也会被编译成移位... 呵呵……同感……不过应该可以作为安全代码……IAR和GCC都存在优化问题。
用这个头文件以后,可以先用ICC建立工程,编译,验证没有问题,然后再用IAR或者GCC编译……谋求效率和优化…… 不错,16L好思路... 分号、括号…… doxygen。。。。。 一定要顶起 顶起 收下 mark 回复【16楼】Gorgon Meducer 傻孩子
-----------------------------------------------------------------------
都看些什么书?有这么多感想... - -b这个……
页:
[1]