ix_macros.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. /**
  2. * ============================================================================
  3. * = COPYRIGHT
  4. *
  5. * @par
  6. * IXP400 SW Release version 2.0
  7. *
  8. * -- Copyright Notice --
  9. *
  10. * @par
  11. * Copyright 2001-2005, Intel Corporation.
  12. * All rights reserved.
  13. *
  14. * @par
  15. * Redistribution and use in source and binary forms, with or without
  16. * modification, are permitted provided that the following conditions
  17. * are met:
  18. * 1. Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. * 2. Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. * 3. Neither the name of the Intel Corporation nor the names of its contributors
  24. * may be used to endorse or promote products derived from this software
  25. * without specific prior written permission.
  26. *
  27. * @par
  28. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
  29. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  30. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  31. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
  32. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  33. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  34. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  35. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  36. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  37. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  38. * SUCH DAMAGE.
  39. *
  40. * @par
  41. * -- End of Copyright Notice --
  42. * = PRODUCT
  43. * Intel(r) IXP425 Software Release
  44. *
  45. * = FILENAME
  46. * ix_macros.h
  47. *
  48. * = DESCRIPTION
  49. * This file will define the basic preprocessor macros that are going to be used
  50. * the IXA SDK Framework API.
  51. *
  52. * = AUTHOR
  53. * Intel Corporation
  54. *
  55. * = CHANGE HISTORY
  56. * 4/22/2002 4:41:05 PM - creation time
  57. * ============================================================================
  58. */
  59. #if !defined(__IX_MACROS_H__)
  60. #define __IX_MACROS_H__
  61. #if defined(__cplusplus)
  62. extern "C"
  63. {
  64. #endif /* end defined(__cplusplus) */
  65. /**
  66. * MACRO NAME: IX_BIT_FIELD_MASK16
  67. *
  68. * DESCRIPTION: Builds the mask required to extract the bit field from a 16 bit unsigned integer value.
  69. *
  70. * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
  71. * bit of the bit field.
  72. * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
  73. * bit of the bit field.
  74. *
  75. * @Return: Returns a 16 bit mask that will extract the bit field from a 16 bit unsigned integer value.
  76. */
  77. #define IX_BIT_FIELD_MASK16( \
  78. arg_FieldLSBBit, \
  79. arg_FieldMSBBit \
  80. ) \
  81. ((ix_bit_mask16)((((ix_uint16)1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - \
  82. (ix_uint16)1) << arg_FieldLSBBit))
  83. /**
  84. * MACRO NAME: IX_GET_BIT_FIELD16
  85. *
  86. * DESCRIPTION: Extracts a bit field from 16 bit unsigned integer. The returned value is normalized in
  87. * in the sense that will be right aligned.
  88. *
  89. * @Param: - IN arg_PackedData16 a 16 bit unsigned integer that contains the bit field of interest.
  90. * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
  91. * bit of the bit field.
  92. * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
  93. * bit of the bit field.
  94. *
  95. * @Return: Returns the value of the bit field. The value can be from 0 to (1 << (arg_FieldMSBBit + 1 -
  96. * arg_FieldLSBBit)) - 1.
  97. */
  98. #define IX_GET_BIT_FIELD16( \
  99. arg_PackedData16, \
  100. arg_FieldLSBBit, \
  101. arg_FieldMSBBit \
  102. ) \
  103. (((ix_uint16)(arg_PackedData16) & IX_BIT_FIELD_MASK16(arg_FieldLSBBit, arg_FieldMSBBit)) >> \
  104. arg_FieldLSBBit)
  105. /**
  106. * MACRO NAME: IX_MAKE_BIT_FIELD16
  107. *
  108. * DESCRIPTION: This macro will create a temporary 16 bit value with the bit field
  109. * desired set to the desired value.
  110. *
  111. * @Param: - IN arg_BitFieldValue is the new value of the bit field. The value can be from 0 to
  112. * (1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - 1.
  113. * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
  114. * bit of the bit field.
  115. * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
  116. * bit of the bit field.
  117. *
  118. * @Return: Returns a temporary ix_uint16 value that has the bit field set to the appropriate value.
  119. */
  120. #define IX_MAKE_BIT_FIELD16( \
  121. arg_BitFieldValue, \
  122. arg_FieldLSBBit, \
  123. arg_FieldMSBBit \
  124. ) \
  125. (((ix_uint16)(arg_BitFieldValue) << arg_FieldLSBBit) & \
  126. IX_BIT_FIELD_MASK16(arg_FieldLSBBit, arg_FieldMSBBit))
  127. /**
  128. * MACRO NAME: IX_SET_BIT_FIELD16
  129. *
  130. * DESCRIPTION: Sets a new value for a bit field from a 16 bit unsigned integer.
  131. *
  132. * @Param: - IN arg_PackedData16 a 16 bit unsigned integer that contains the bit field of interest.
  133. * @Param: - IN arg_BitFieldValue is the new vale of the bit field. The value can be from 0 to
  134. * (1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - 1.
  135. * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
  136. * bit of the bit field.
  137. * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
  138. * bit of the bit field.
  139. *
  140. * @Return: Returns the updated value of arg_PackedData16.
  141. */
  142. #define IX_SET_BIT_FIELD16( \
  143. arg_PackedData16, \
  144. arg_BitFieldValue, \
  145. arg_FieldLSBBit, \
  146. arg_FieldMSBBit \
  147. ) \
  148. (arg_PackedData16 = (((ix_uint16)(arg_PackedData16) & \
  149. ~(IX_BIT_FIELD_MASK16(arg_FieldLSBBit, arg_FieldMSBBit))) | \
  150. IX_MAKE_BIT_FIELD16(arg_BitFieldValue, arg_FieldLSBBit, arg_FieldMSBBit)))
  151. /**
  152. * MACRO NAME: IX_BIT_FIELD_MASK32
  153. *
  154. * DESCRIPTION: Builds the mask required to extract the bit field from a 32 bit unsigned integer value.
  155. *
  156. * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
  157. * bit of the bit field.
  158. * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
  159. * bit of the bit field.
  160. *
  161. * @Return: Returns a 32 bit mask that will extract the bit field from a 32 bit unsigned integer value.
  162. */
  163. #define IX_BIT_FIELD_MASK32( \
  164. arg_FieldLSBBit, \
  165. arg_FieldMSBBit \
  166. ) \
  167. ((ix_bit_mask32)((((ix_uint32)1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - \
  168. (ix_uint32)1) << arg_FieldLSBBit))
  169. /**
  170. * MACRO NAME: IX_GET_BIT_FIELD32
  171. *
  172. * DESCRIPTION: Extracts a bit field from 32 bit unsigned integer. The returned value is normalized in
  173. * in the sense that will be right aligned.
  174. *
  175. * @Param: - IN arg_PackedData32 a 32 bit unsigned integer that contains the bit field of interest.
  176. * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
  177. * bit of the bit field.
  178. * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
  179. * bit of the bit field.
  180. *
  181. * @Return: Returns the value of the bit field. The value can be from 0 to (1 << (arg_FieldMSBBit + 1 -
  182. * arg_FieldLSBBit)) - 1.
  183. */
  184. #define IX_GET_BIT_FIELD32( \
  185. arg_PackedData32, \
  186. arg_FieldLSBBit, \
  187. arg_FieldMSBBit \
  188. ) \
  189. (((ix_uint32)(arg_PackedData32) & IX_BIT_FIELD_MASK32(arg_FieldLSBBit, arg_FieldMSBBit)) >> \
  190. arg_FieldLSBBit)
  191. /**
  192. * MACRO NAME: IX_MAKE_BIT_FIELD32
  193. *
  194. * DESCRIPTION: This macro will create a temporary 32 bit value with the bit field
  195. * desired set to the desired value.
  196. *
  197. * @Param: - IN arg_BitFieldValue is the new value of the bit field. The value can be from 0 to
  198. * (1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - 1.
  199. * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
  200. * bit of the bit field.
  201. * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
  202. * bit of the bit field.
  203. *
  204. * @Return: Returns a temporary ix_uint32 value that has the bit field set to the appropriate value.
  205. */
  206. #define IX_MAKE_BIT_FIELD32( \
  207. arg_BitFieldValue, \
  208. arg_FieldLSBBit, \
  209. arg_FieldMSBBit \
  210. ) \
  211. (((ix_uint32)(arg_BitFieldValue) << arg_FieldLSBBit) & \
  212. IX_BIT_FIELD_MASK32(arg_FieldLSBBit, arg_FieldMSBBit))
  213. /**
  214. * MACRO NAME: IX_SET_BIT_FIELD32
  215. *
  216. * DESCRIPTION: Sets a new value for a bit field from a 32 bit unsigned integer.
  217. *
  218. * @Param: - IN arg_PackedData32 a 32 bit unsigned integer that contains the bit field of interest.
  219. * @Param: - IN arg_BitFieldValue is the new value of the bit field. The value can be from 0 to
  220. * (1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - 1.
  221. * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
  222. * bit of the bit field.
  223. * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
  224. * bit of the bit field.
  225. *
  226. * @Return: Returns the updated value of arg_PackedData32.
  227. */
  228. #define IX_SET_BIT_FIELD32( \
  229. arg_PackedData32, \
  230. arg_BitFieldValue, \
  231. arg_FieldLSBBit, \
  232. arg_FieldMSBBit \
  233. ) \
  234. (arg_PackedData32 = (((ix_uint32)(arg_PackedData32) & \
  235. ~(IX_BIT_FIELD_MASK32(arg_FieldLSBBit, arg_FieldMSBBit))) | \
  236. IX_MAKE_BIT_FIELD32(arg_BitFieldValue, arg_FieldLSBBit, arg_FieldMSBBit)))
  237. #if defined(__cplusplus)
  238. }
  239. #endif /* end defined(__cplusplus) */
  240. #endif /* end !defined(__IX_MACROS_H__) */