macro_common.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. /* macro_common.h -- 平台公共宏定义 Id: macro_common.h,v 1.5 2006/08/31 08:56:59 wangjiong Exp $ */
  2. /********************************************************
  3. Copyright(C), 1999-2004 Raisecom, Inc.
  4. filename: //文件名
  5. Author: XXX version:2004/12/20 //初始作者和版本时间
  6. Others:
  7. THIS DOCUMENT IS GENERATED BY TORNADO TOOLS refgen.exe.
  8. EXAMPLE:
  9. ->torVars.bat
  10. ->refgen -mg -out doc driver.c
  11. ->cd doc
  12. ->htmllink
  13. ***********************************************************/
  14. /*
  15. DESCRIPTION
  16. 平台公共宏定义
  17. SEE ALSO
  18. */
  19. /***********************************************************
  20. Modified History: //文件的修改历史记录列表,
  21. //在提交文件到版本服务器时一定要填入信息,该信息会自动放在此处
  22. * Log: macro_common.h,v $
  23. * Revision 1.5 2006/08/31 08:56:59 wangjiong
  24. * 为pc-lint修改代码
  25. *
  26. * Revision 1.4 2006/06/26 08:16:06 wangjiong
  27. * 修改BIT_CLEAR宏的错误
  28. *
  29. * Revision 1.3 2006/03/14 06:14:49 zhangrongtao
  30. * 转换为dos格式
  31. *
  32. * Revision 1.2 2006/03/13 03:08:56 zhangrongtao
  33. * 修改了opcom_dev和sadp对设备相关的剪裁方式
  34. *
  35. * Revision 1.1.1.2 2006/03/02 05:32:46 zhangrongtao
  36. * no message
  37. *
  38. * Revision 1.1.1.1 2006/02/23 10:53:30 lch
  39. * init
  40. *
  41. ***********************************************************/
  42. #ifndef _MACRO_COMMON_H
  43. #define _MACRO_COMMON_H
  44. /*返回a和b中的最小数*/
  45. #ifndef MIN
  46. #define MIN(a, b) ((a) < (b)? (a): (b))
  47. #endif
  48. /*返回a和b中的最大数*/
  49. #ifndef MAX
  50. #define MAX(a, b) ((a) > (b)? (a): (b))
  51. #endif
  52. /*返回不小于d的m的整数倍的最小整数*/
  53. #ifndef RND_UP
  54. #define RND_UP(d,m) ( ((d)%(m)) ? ((d)-(d)%(m)+(m)) :(d))
  55. #endif
  56. /*编译时取得数组a的元素个数*/
  57. #ifndef ARRAY_NITEM
  58. #define ARRAY_NITEM(a) (sizeof(a)/sizeof((a)[0]))
  59. #endif
  60. /*假装使用一下x变量,去掉编译告警*/
  61. #ifndef NO_USE
  62. #define NO_USE(x) ((void)(x))
  63. #endif
  64. /*可以当作空语句使用*/
  65. #ifndef OTP_NULL
  66. #define OTP_NULL ((void)NULL)
  67. #endif
  68. /*函数的输入参数*/
  69. #ifndef OTP_IN
  70. #define OTP_IN
  71. #endif
  72. /*函数的输出参数*/
  73. #ifndef OTP_OUT
  74. #define OTP_OUT
  75. #endif
  76. /*函数的输入输出参数*/
  77. #ifndef OTP_INOUT
  78. #define OTP_INOUT
  79. #endif
  80. /*判断flag中的mask标志是否有置位了的*/
  81. #define BIT_IS_SET(flag,mask) (((flag)&(mask)) == (mask))
  82. /*清除flag中的mask标志*/
  83. //#define BIT_CLEAR(flag,mask) ((flag)&=(~(mask)))
  84. /*设置 flag中的mask标志*/
  85. //#define BIT_SET(flag,mask) ((flag)|=(mask))
  86. #define OTP_PACK_ALIGN(x) __attribute__((packed, aligned(x)))
  87. /*获得单独一个bit*/
  88. #define BIT_SIGNAL(x) (1 << (x))
  89. /*包括第shift比特,向左取size比特置1,其它置0. shift从0开始,size至少1*/
  90. /*#define BIT_MASK(shift, size) (((1 << (size)) - 1) << (shift))*/ /*wangzaizhong 20081201 修改*/
  91. #define BIT_MASK(shift, size) (((1 << (size + shift))) - (1 << shift))
  92. /*包括第shift比特,向左取出size比特*/
  93. #define GET_BITS(x, shift, size) (((x) >>(shift)) & (((1 << (size)) - 1)))
  94. #define BIT_RD(val, shift, size) (((val) >> (shift)) & ((1 << (size)) - 1))
  95. #define BIT_WR(val, shift) ((val) << (shift))
  96. /* 没有lint告警的不循环
  97. 如果写在lint的配置文件中,对DEBUG宏的定义就不能起作用,不知道原因
  98. Info 717: do ... while(0)
  99. */
  100. #define WHILE_0 /*lint -save -e717 */while(0)/*lint -restore */
  101. /* 没有lint告警的死循环
  102. Info 716: while(1) ...
  103. */
  104. #define WHILE_1 /*lint -save -e716 */while(1)/*lint -restore */
  105. /* 把四个单字节无符号整数组织成一个4字节的无符号整数,
  106. B4为数值最大的字节,B1为数值最小的字节 */
  107. #define UINT8_MAKE_UINT32(B4,B3,B2,B1) \
  108. ((OTP_UINT32)( ((B4)<<24) + ((B3)<<16) + ((B2)<<8) + (B1) ))
  109. /* 用位域表示端口的时候需要的字节数 */
  110. #define BYTES_FOR_PORT(nport) (((nport)+7)/8)
  111. #define OTP_LITTLE_ENDIAN
  112. #ifdef OTP_LITTLE_ENDIAN
  113. #define ntohl(x) ((((x) & 0x000000ff) << 24) | \
  114. (((x) & 0x0000ff00) << 8) | \
  115. (((x) & 0x00ff0000) >> 8) | \
  116. (((x) & 0xff000000) >> 24))
  117. #define htonl(x) ((((x) & 0x000000ff) << 24) | \
  118. (((x) & 0x0000ff00) << 8) | \
  119. (((x) & 0x00ff0000) >> 8) | \
  120. (((x) & 0xff000000) >> 24))
  121. #define ntohs(x) ((((x) & 0x00ff) << 8) | \
  122. (((x) & 0xff00) >> 8))
  123. #define htons(x) /*lint -save -e778 -e572*/((((x) & 0x00ff) << 8) | \
  124. (((x) & 0xff00) >> 8)) /*lint -restore*/
  125. #else
  126. #define ntohl(x) (x)
  127. #define ntohs(x) (x)
  128. #define htonl(x) (x)
  129. #define htons(x) (x)
  130. #endif
  131. #endif