1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004 by Jens Arnold
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
27 /* helper function to extract n (<=32) bits from an arbitrary position.
28 counting from MSB to LSB */
29 unsigned long card_extract_bits(
30 const unsigned long *p
, /* the start of the bitfield array */
31 unsigned int start
, /* bit no. to start reading */
32 unsigned int size
) /* how many bits to read */
34 unsigned int long_index
= start
/ 32;
35 unsigned int bit_index
= start
% 32;
38 result
= p
[long_index
] << bit_index
;
40 if (bit_index
+ size
> 32) /* crossing longword boundary */
41 result
|= p
[long_index
+1] >> (32 - bit_index
);