| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- /* macro_common.h -- 平台公共宏定义 Id: macro_common.h,v 1.5 2006/08/31 08:56:59 wangjiong Exp $ */
- /********************************************************
- Copyright(C), 1999-2004 Raisecom, Inc.
- filename: //文件名
- Author: XXX version:2004/12/20 //初始作者和版本时间
- Others:
- THIS DOCUMENT IS GENERATED BY TORNADO TOOLS refgen.exe.
- EXAMPLE:
- ->torVars.bat
- ->refgen -mg -out doc driver.c
- ->cd doc
- ->htmllink
- ***********************************************************/
- /*
- DESCRIPTION
- 平台公共宏定义
- SEE ALSO
-
- */
- /***********************************************************
- Modified History: //文件的修改历史记录列表,
- //在提交文件到版本服务器时一定要填入信息,该信息会自动放在此处
- * Log: macro_common.h,v $
- * Revision 1.5 2006/08/31 08:56:59 wangjiong
- * 为pc-lint修改代码
- *
- * Revision 1.4 2006/06/26 08:16:06 wangjiong
- * 修改BIT_CLEAR宏的错误
- *
- * Revision 1.3 2006/03/14 06:14:49 zhangrongtao
- * 转换为dos格式
- *
- * Revision 1.2 2006/03/13 03:08:56 zhangrongtao
- * 修改了opcom_dev和sadp对设备相关的剪裁方式
- *
- * Revision 1.1.1.2 2006/03/02 05:32:46 zhangrongtao
- * no message
- *
- * Revision 1.1.1.1 2006/02/23 10:53:30 lch
- * init
- *
- ***********************************************************/
- #ifndef _MACRO_COMMON_H
- #define _MACRO_COMMON_H
- /*返回a和b中的最小数*/
- #ifndef MIN
- #define MIN(a, b) ((a) < (b)? (a): (b))
- #endif
- /*返回a和b中的最大数*/
- #ifndef MAX
- #define MAX(a, b) ((a) > (b)? (a): (b))
- #endif
- /*返回不小于d的m的整数倍的最小整数*/
- #ifndef RND_UP
- #define RND_UP(d,m) ( ((d)%(m)) ? ((d)-(d)%(m)+(m)) :(d))
- #endif
- /*编译时取得数组a的元素个数*/
- #ifndef ARRAY_NITEM
- #define ARRAY_NITEM(a) (sizeof(a)/sizeof((a)[0]))
- #endif
- /*假装使用一下x变量,去掉编译告警*/
- #ifndef NO_USE
- #define NO_USE(x) ((void)(x))
- #endif
- /*可以当作空语句使用*/
- #ifndef OTP_NULL
- #define OTP_NULL ((void)NULL)
- #endif
- /*函数的输入参数*/
- #ifndef OTP_IN
- #define OTP_IN
- #endif
- /*函数的输出参数*/
- #ifndef OTP_OUT
- #define OTP_OUT
- #endif
- /*函数的输入输出参数*/
- #ifndef OTP_INOUT
- #define OTP_INOUT
- #endif
- /*判断flag中的mask标志是否有置位了的*/
- #define BIT_IS_SET(flag,mask) (((flag)&(mask)) == (mask))
- /*清除flag中的mask标志*/
- //#define BIT_CLEAR(flag,mask) ((flag)&=(~(mask)))
- /*设置 flag中的mask标志*/
- //#define BIT_SET(flag,mask) ((flag)|=(mask))
- #define OTP_PACK_ALIGN(x) __attribute__((packed, aligned(x)))
- /*获得单独一个bit*/
- #define BIT_SIGNAL(x) (1 << (x))
- /*包括第shift比特,向左取size比特置1,其它置0. shift从0开始,size至少1*/
- /*#define BIT_MASK(shift, size) (((1 << (size)) - 1) << (shift))*/ /*wangzaizhong 20081201 修改*/
- #define BIT_MASK(shift, size) (((1 << (size + shift))) - (1 << shift))
- /*包括第shift比特,向左取出size比特*/
- #define GET_BITS(x, shift, size) (((x) >>(shift)) & (((1 << (size)) - 1)))
- #define BIT_RD(val, shift, size) (((val) >> (shift)) & ((1 << (size)) - 1))
- #define BIT_WR(val, shift) ((val) << (shift))
- /* 没有lint告警的不循环
- 如果写在lint的配置文件中,对DEBUG宏的定义就不能起作用,不知道原因
- Info 717: do ... while(0)
- */
- #define WHILE_0 /*lint -save -e717 */while(0)/*lint -restore */
- /* 没有lint告警的死循环
- Info 716: while(1) ...
- */
- #define WHILE_1 /*lint -save -e716 */while(1)/*lint -restore */
- /* 把四个单字节无符号整数组织成一个4字节的无符号整数,
- B4为数值最大的字节,B1为数值最小的字节 */
- #define UINT8_MAKE_UINT32(B4,B3,B2,B1) \
- ((OTP_UINT32)( ((B4)<<24) + ((B3)<<16) + ((B2)<<8) + (B1) ))
- /* 用位域表示端口的时候需要的字节数 */
- #define BYTES_FOR_PORT(nport) (((nport)+7)/8)
- #define OTP_LITTLE_ENDIAN
- #ifdef OTP_LITTLE_ENDIAN
- #define ntohl(x) ((((x) & 0x000000ff) << 24) | \
- (((x) & 0x0000ff00) << 8) | \
- (((x) & 0x00ff0000) >> 8) | \
- (((x) & 0xff000000) >> 24))
- #define htonl(x) ((((x) & 0x000000ff) << 24) | \
- (((x) & 0x0000ff00) << 8) | \
- (((x) & 0x00ff0000) >> 8) | \
- (((x) & 0xff000000) >> 24))
- #define ntohs(x) ((((x) & 0x00ff) << 8) | \
- (((x) & 0xff00) >> 8))
- #define htons(x) /*lint -save -e778 -e572*/((((x) & 0x00ff) << 8) | \
- (((x) & 0xff00) >> 8)) /*lint -restore*/
- #else
- #define ntohl(x) (x)
- #define ntohs(x) (x)
- #define htonl(x) (x)
- #define htons(x) (x)
- #endif
- #endif
|