diff options
author | Jens Arnold <amiconn@rockbox.org> | 2005-05-04 22:30:36 +0000 |
---|---|---|
committer | Jens Arnold <amiconn@rockbox.org> | 2005-05-04 22:30:36 +0000 |
commit | 251deaa4cabb434a104b7d86c949d6777a8bb2bf (patch) | |
tree | 42dd645e11ef795fe7eb8a8f19e0c849d806fffe /firmware | |
parent | 116e4646b0eed98bec965145698ee89c05f400e7 (diff) | |
download | rockbox-251deaa4cabb434a104b7d86c949d6777a8bb2bf.tar.gz rockbox-251deaa4cabb434a104b7d86c949d6777a8bb2bf.zip |
Improved bitfield handling for settings and MMC (more straigtforward, smaller code). This switches the order for fields crossing a longword boundary, so the config block version bump is necessary. Save your settings to a file before upgrading.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6404 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/ata_mmc.c | 29 |
1 files changed, 8 insertions, 21 deletions
diff --git a/firmware/drivers/ata_mmc.c b/firmware/drivers/ata_mmc.c index 9e854ce977..02ec72a1f2 100644 --- a/firmware/drivers/ata_mmc.c +++ b/firmware/drivers/ata_mmc.c | |||
@@ -395,29 +395,16 @@ unsigned long mmc_extract_bits( | |||
395 | unsigned int start, /* bit no. to start reading */ | 395 | unsigned int start, /* bit no. to start reading */ |
396 | unsigned int size) /* how many bits to read */ | 396 | unsigned int size) /* how many bits to read */ |
397 | { | 397 | { |
398 | unsigned int bit_index; | 398 | unsigned int long_index = start / 32; |
399 | unsigned int bits_to_use; | 399 | unsigned int bit_index = start % 32; |
400 | unsigned long mask; | ||
401 | unsigned long result; | 400 | unsigned long result; |
401 | |||
402 | result = p[long_index] << bit_index; | ||
402 | 403 | ||
403 | if (size == 1) | 404 | if (bit_index + size > 32) /* crossing longword boundary */ |
404 | { /* short cut */ | 405 | result |= p[long_index+1] >> (32 - bit_index); |
405 | return ((p[start/32] >> (31 - (start % 32))) & 1); | 406 | |
406 | } | 407 | result >>= 32 - size; |
407 | |||
408 | result = 0; | ||
409 | while (size) | ||
410 | { | ||
411 | bit_index = start % 32; | ||
412 | bits_to_use = MIN(32 - bit_index, size); | ||
413 | mask = 0xFFFFFFFF >> (32 - bits_to_use); | ||
414 | |||
415 | result <<= bits_to_use; /* start last round */ | ||
416 | result |= (p[start/32] >> (32 - bits_to_use - bit_index)) & mask; | ||
417 | |||
418 | start += bits_to_use; | ||
419 | size -= bits_to_use; | ||
420 | } | ||
421 | 408 | ||
422 | return result; | 409 | return result; |
423 | } | 410 | } |