blob: 53f5942f9790999c66686a1778299e9ae105801c [file] [log] [blame]
Wolfgang Denkba94a1b2006-05-30 15:56:48 +02001/**
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
60#if !defined(__IX_MACROS_H__)
61#define __IX_MACROS_H__
62
63
64#if defined(__cplusplus)
65extern "C"
66{
67#endif /* end defined(__cplusplus) */
68
69
70/**
71 * MACRO NAME: IX_BIT_FIELD_MASK16
72 *
73 * DESCRIPTION: Builds the mask required to extract the bit field from a 16 bit unsigned integer value.
74 *
75 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
76 * bit of the bit field.
77 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
78 * bit of the bit field.
79 *
80 * @Return: Returns a 16 bit mask that will extract the bit field from a 16 bit unsigned integer value.
81 */
82#define IX_BIT_FIELD_MASK16( \
83 arg_FieldLSBBit, \
84 arg_FieldMSBBit \
85 ) \
86 ((ix_bit_mask16)((((ix_uint16)1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - \
87 (ix_uint16)1) << arg_FieldLSBBit))
88
89
90
91/**
92 * MACRO NAME: IX_GET_BIT_FIELD16
93 *
94 * DESCRIPTION: Extracts a bit field from 16 bit unsigned integer. The returned value is normalized in
95 * in the sense that will be right aligned.
96 *
97 * @Param: - IN arg_PackedData16 a 16 bit unsigned integer that contains the bit field of interest.
98 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
99 * bit of the bit field.
100 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
101 * bit of the bit field.
102 *
103 * @Return: Returns the value of the bit field. The value can be from 0 to (1 << (arg_FieldMSBBit + 1 -
104 * arg_FieldLSBBit)) - 1.
105 */
106#define IX_GET_BIT_FIELD16( \
107 arg_PackedData16, \
108 arg_FieldLSBBit, \
109 arg_FieldMSBBit \
110 ) \
111 (((ix_uint16)(arg_PackedData16) & IX_BIT_FIELD_MASK16(arg_FieldLSBBit, arg_FieldMSBBit)) >> \
112 arg_FieldLSBBit)
113
114
115/**
116 * MACRO NAME: IX_MAKE_BIT_FIELD16
117 *
118 * DESCRIPTION: This macro will create a temporary 16 bit value with the bit field
119 * desired set to the desired value.
120 *
121 * @Param: - IN arg_BitFieldValue is the new value of the bit field. The value can be from 0 to
122 * (1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - 1.
123 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
124 * bit of the bit field.
125 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
126 * bit of the bit field.
127 *
128 * @Return: Returns a temporary ix_uint16 value that has the bit field set to the appropriate value.
129 */
130#define IX_MAKE_BIT_FIELD16( \
131 arg_BitFieldValue, \
132 arg_FieldLSBBit, \
133 arg_FieldMSBBit \
134 ) \
135 (((ix_uint16)(arg_BitFieldValue) << arg_FieldLSBBit) & \
136 IX_BIT_FIELD_MASK16(arg_FieldLSBBit, arg_FieldMSBBit))
137
138/**
139 * MACRO NAME: IX_SET_BIT_FIELD16
140 *
141 * DESCRIPTION: Sets a new value for a bit field from a 16 bit unsigned integer.
142 *
143 * @Param: - IN arg_PackedData16 a 16 bit unsigned integer that contains the bit field of interest.
144 * @Param: - IN arg_BitFieldValue is the new vale of the bit field. The value can be from 0 to
145 * (1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - 1.
146 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
147 * bit of the bit field.
148 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
149 * bit of the bit field.
150 *
151 * @Return: Returns the updated value of arg_PackedData16.
152 */
153#define IX_SET_BIT_FIELD16( \
154 arg_PackedData16, \
155 arg_BitFieldValue, \
156 arg_FieldLSBBit, \
157 arg_FieldMSBBit \
158 ) \
159 (arg_PackedData16 = (((ix_uint16)(arg_PackedData16) & \
160 ~(IX_BIT_FIELD_MASK16(arg_FieldLSBBit, arg_FieldMSBBit))) | \
161 IX_MAKE_BIT_FIELD16(arg_BitFieldValue, arg_FieldLSBBit, arg_FieldMSBBit)))
162
163
164/**
165 * MACRO NAME: IX_BIT_FIELD_MASK32
166 *
167 * DESCRIPTION: Builds the mask required to extract the bit field from a 32 bit unsigned integer value.
168 *
169 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
170 * bit of the bit field.
171 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
172 * bit of the bit field.
173 *
174 * @Return: Returns a 32 bit mask that will extract the bit field from a 32 bit unsigned integer value.
175 */
176#define IX_BIT_FIELD_MASK32( \
177 arg_FieldLSBBit, \
178 arg_FieldMSBBit \
179 ) \
180 ((ix_bit_mask32)((((ix_uint32)1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - \
181 (ix_uint32)1) << arg_FieldLSBBit))
182
183
184
185/**
186 * MACRO NAME: IX_GET_BIT_FIELD32
187 *
188 * DESCRIPTION: Extracts a bit field from 32 bit unsigned integer. The returned value is normalized in
189 * in the sense that will be right aligned.
190 *
191 * @Param: - IN arg_PackedData32 a 32 bit unsigned integer that contains the bit field of interest.
192 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
193 * bit of the bit field.
194 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
195 * bit of the bit field.
196 *
197 * @Return: Returns the value of the bit field. The value can be from 0 to (1 << (arg_FieldMSBBit + 1 -
198 * arg_FieldLSBBit)) - 1.
199 */
200#define IX_GET_BIT_FIELD32( \
201 arg_PackedData32, \
202 arg_FieldLSBBit, \
203 arg_FieldMSBBit \
204 ) \
205 (((ix_uint32)(arg_PackedData32) & IX_BIT_FIELD_MASK32(arg_FieldLSBBit, arg_FieldMSBBit)) >> \
206 arg_FieldLSBBit)
207
208
209
210
211/**
212 * MACRO NAME: IX_MAKE_BIT_FIELD32
213 *
214 * DESCRIPTION: This macro will create a temporary 32 bit value with the bit field
215 * desired set to the desired value.
216 *
217 * @Param: - IN arg_BitFieldValue is the new value of the bit field. The value can be from 0 to
218 * (1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - 1.
219 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
220 * bit of the bit field.
221 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
222 * bit of the bit field.
223 *
224 * @Return: Returns a temporary ix_uint32 value that has the bit field set to the appropriate value.
225 */
226#define IX_MAKE_BIT_FIELD32( \
227 arg_BitFieldValue, \
228 arg_FieldLSBBit, \
229 arg_FieldMSBBit \
230 ) \
231 (((ix_uint32)(arg_BitFieldValue) << arg_FieldLSBBit) & \
232 IX_BIT_FIELD_MASK32(arg_FieldLSBBit, arg_FieldMSBBit))
233
234
235/**
236 * MACRO NAME: IX_SET_BIT_FIELD32
237 *
238 * DESCRIPTION: Sets a new value for a bit field from a 32 bit unsigned integer.
239 *
240 * @Param: - IN arg_PackedData32 a 32 bit unsigned integer that contains the bit field of interest.
241 * @Param: - IN arg_BitFieldValue is the new value of the bit field. The value can be from 0 to
242 * (1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - 1.
243 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
244 * bit of the bit field.
245 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
246 * bit of the bit field.
247 *
248 * @Return: Returns the updated value of arg_PackedData32.
249 */
250#define IX_SET_BIT_FIELD32( \
251 arg_PackedData32, \
252 arg_BitFieldValue, \
253 arg_FieldLSBBit, \
254 arg_FieldMSBBit \
255 ) \
256 (arg_PackedData32 = (((ix_uint32)(arg_PackedData32) & \
257 ~(IX_BIT_FIELD_MASK32(arg_FieldLSBBit, arg_FieldMSBBit))) | \
258 IX_MAKE_BIT_FIELD32(arg_BitFieldValue, arg_FieldLSBBit, arg_FieldMSBBit)))
259
260
261
262#if defined(__cplusplus)
263}
264#endif /* end defined(__cplusplus) */
265
266#endif /* end !defined(__IX_MACROS_H__) */