blob: b4cf7602ae67fd426ff5577714170e3dc8de2a89 [file] [log] [blame]
Wolfgang Denk4646d2a2006-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
Wolfgang Denkc57eadc2013-07-28 22:12:47 +020015 * SPDX-License-Identifier: BSD-3-Clause
Wolfgang Denk4646d2a2006-05-30 15:56:48 +020016 * @par
17 * -- End of Copyright Notice --
18 * = PRODUCT
19 * Intel(r) IXP425 Software Release
20 *
21 * = FILENAME
22 * ix_macros.h
23 *
24 * = DESCRIPTION
25 * This file will define the basic preprocessor macros that are going to be used
26 * the IXA SDK Framework API.
27 *
28 * = AUTHOR
29 * Intel Corporation
30 *
31 * = CHANGE HISTORY
32 * 4/22/2002 4:41:05 PM - creation time
33 * ============================================================================
34 */
35
36#if !defined(__IX_MACROS_H__)
37#define __IX_MACROS_H__
38
39
40#if defined(__cplusplus)
41extern "C"
42{
43#endif /* end defined(__cplusplus) */
44
45
46/**
47 * MACRO NAME: IX_BIT_FIELD_MASK16
48 *
49 * DESCRIPTION: Builds the mask required to extract the bit field from a 16 bit unsigned integer value.
50 *
51 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
52 * bit of the bit field.
53 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
54 * bit of the bit field.
55 *
56 * @Return: Returns a 16 bit mask that will extract the bit field from a 16 bit unsigned integer value.
57 */
58#define IX_BIT_FIELD_MASK16( \
59 arg_FieldLSBBit, \
60 arg_FieldMSBBit \
61 ) \
62 ((ix_bit_mask16)((((ix_uint16)1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - \
63 (ix_uint16)1) << arg_FieldLSBBit))
64
65
66
67/**
68 * MACRO NAME: IX_GET_BIT_FIELD16
69 *
70 * DESCRIPTION: Extracts a bit field from 16 bit unsigned integer. The returned value is normalized in
71 * in the sense that will be right aligned.
72 *
73 * @Param: - IN arg_PackedData16 a 16 bit unsigned integer that contains the bit field of interest.
74 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
75 * bit of the bit field.
76 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
77 * bit of the bit field.
78 *
79 * @Return: Returns the value of the bit field. The value can be from 0 to (1 << (arg_FieldMSBBit + 1 -
80 * arg_FieldLSBBit)) - 1.
81 */
82#define IX_GET_BIT_FIELD16( \
83 arg_PackedData16, \
84 arg_FieldLSBBit, \
85 arg_FieldMSBBit \
86 ) \
87 (((ix_uint16)(arg_PackedData16) & IX_BIT_FIELD_MASK16(arg_FieldLSBBit, arg_FieldMSBBit)) >> \
88 arg_FieldLSBBit)
89
90
91/**
92 * MACRO NAME: IX_MAKE_BIT_FIELD16
93 *
94 * DESCRIPTION: This macro will create a temporary 16 bit value with the bit field
95 * desired set to the desired value.
96 *
97 * @Param: - IN arg_BitFieldValue is the new value of the bit field. The value can be from 0 to
98 * (1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - 1.
99 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
100 * bit of the bit field.
101 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
102 * bit of the bit field.
103 *
104 * @Return: Returns a temporary ix_uint16 value that has the bit field set to the appropriate value.
105 */
106#define IX_MAKE_BIT_FIELD16( \
107 arg_BitFieldValue, \
108 arg_FieldLSBBit, \
109 arg_FieldMSBBit \
110 ) \
111 (((ix_uint16)(arg_BitFieldValue) << arg_FieldLSBBit) & \
112 IX_BIT_FIELD_MASK16(arg_FieldLSBBit, arg_FieldMSBBit))
113
114/**
115 * MACRO NAME: IX_SET_BIT_FIELD16
116 *
117 * DESCRIPTION: Sets a new value for a bit field from a 16 bit unsigned integer.
118 *
119 * @Param: - IN arg_PackedData16 a 16 bit unsigned integer that contains the bit field of interest.
120 * @Param: - IN arg_BitFieldValue is the new vale of the bit field. The value can be from 0 to
121 * (1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - 1.
122 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
123 * bit of the bit field.
124 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
125 * bit of the bit field.
126 *
127 * @Return: Returns the updated value of arg_PackedData16.
128 */
129#define IX_SET_BIT_FIELD16( \
130 arg_PackedData16, \
131 arg_BitFieldValue, \
132 arg_FieldLSBBit, \
133 arg_FieldMSBBit \
134 ) \
135 (arg_PackedData16 = (((ix_uint16)(arg_PackedData16) & \
136 ~(IX_BIT_FIELD_MASK16(arg_FieldLSBBit, arg_FieldMSBBit))) | \
137 IX_MAKE_BIT_FIELD16(arg_BitFieldValue, arg_FieldLSBBit, arg_FieldMSBBit)))
138
139
140/**
141 * MACRO NAME: IX_BIT_FIELD_MASK32
142 *
143 * DESCRIPTION: Builds the mask required to extract the bit field from a 32 bit unsigned integer value.
144 *
145 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
146 * bit of the bit field.
147 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
148 * bit of the bit field.
149 *
150 * @Return: Returns a 32 bit mask that will extract the bit field from a 32 bit unsigned integer value.
151 */
152#define IX_BIT_FIELD_MASK32( \
153 arg_FieldLSBBit, \
154 arg_FieldMSBBit \
155 ) \
156 ((ix_bit_mask32)((((ix_uint32)1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - \
157 (ix_uint32)1) << arg_FieldLSBBit))
158
159
160
161/**
162 * MACRO NAME: IX_GET_BIT_FIELD32
163 *
164 * DESCRIPTION: Extracts a bit field from 32 bit unsigned integer. The returned value is normalized in
165 * in the sense that will be right aligned.
166 *
167 * @Param: - IN arg_PackedData32 a 32 bit unsigned integer that contains the bit field of interest.
168 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
169 * bit of the bit field.
170 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
171 * bit of the bit field.
172 *
173 * @Return: Returns the value of the bit field. The value can be from 0 to (1 << (arg_FieldMSBBit + 1 -
174 * arg_FieldLSBBit)) - 1.
175 */
176#define IX_GET_BIT_FIELD32( \
177 arg_PackedData32, \
178 arg_FieldLSBBit, \
179 arg_FieldMSBBit \
180 ) \
181 (((ix_uint32)(arg_PackedData32) & IX_BIT_FIELD_MASK32(arg_FieldLSBBit, arg_FieldMSBBit)) >> \
182 arg_FieldLSBBit)
183
184
185
186
187/**
188 * MACRO NAME: IX_MAKE_BIT_FIELD32
189 *
190 * DESCRIPTION: This macro will create a temporary 32 bit value with the bit field
191 * desired set to the desired value.
192 *
193 * @Param: - IN arg_BitFieldValue is the new value of the bit field. The value can be from 0 to
194 * (1 << (arg_FieldMSBBit + 1 - arg_FieldLSBBit)) - 1.
195 * @Param: - IN arg_FieldLSBBit an unsigned integer value representing the position of the least significant
196 * bit of the bit field.
197 * @Param: - IN arg_FieldMSBBit an unsigned integer value representing the position of the most significant
198 * bit of the bit field.
199 *
200 * @Return: Returns a temporary ix_uint32 value that has the bit field set to the appropriate value.
201 */
202#define IX_MAKE_BIT_FIELD32( \
203 arg_BitFieldValue, \
204 arg_FieldLSBBit, \
205 arg_FieldMSBBit \
206 ) \
207 (((ix_uint32)(arg_BitFieldValue) << arg_FieldLSBBit) & \
208 IX_BIT_FIELD_MASK32(arg_FieldLSBBit, arg_FieldMSBBit))
209
210
211/**
212 * MACRO NAME: IX_SET_BIT_FIELD32
213 *
214 * DESCRIPTION: Sets a new value for a bit field from a 32 bit unsigned integer.
215 *
216 * @Param: - IN arg_PackedData32 a 32 bit unsigned integer that contains the bit field of interest.
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 the updated value of arg_PackedData32.
225 */
226#define IX_SET_BIT_FIELD32( \
227 arg_PackedData32, \
228 arg_BitFieldValue, \
229 arg_FieldLSBBit, \
230 arg_FieldMSBBit \
231 ) \
232 (arg_PackedData32 = (((ix_uint32)(arg_PackedData32) & \
233 ~(IX_BIT_FIELD_MASK32(arg_FieldLSBBit, arg_FieldMSBBit))) | \
234 IX_MAKE_BIT_FIELD32(arg_BitFieldValue, arg_FieldLSBBit, arg_FieldMSBBit)))
235
236
237
238#if defined(__cplusplus)
239}
240#endif /* end defined(__cplusplus) */
241
242#endif /* end !defined(__IX_MACROS_H__) */