Oops. Should commit patches correctly.
[Rockbox.git] / firmware / hotswap.c
blobbbcdabf6493ca6a71f3ae34fa498d98b0c06a974
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
19 #include <stdbool.h>
20 #include "config.h"
21 #ifdef HAVE_MMC
22 #include "ata_mmc.h"
23 #else
24 #include "hotswap.h"
25 #endif
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;
36 unsigned long result;
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);
43 result >>= 32 - size;
45 return result;