diff options
-rw-r--r-- | apps/settings.c | 75 | ||||
-rw-r--r-- | firmware/drivers/ata_mmc.c | 29 |
2 files changed, 29 insertions, 75 deletions
diff --git a/apps/settings.c b/apps/settings.c index bb2cc4f929..936aa2233e 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -73,7 +73,7 @@ const char rec_base_directory[] = REC_BASE_DIR; | |||
73 | 73 | ||
74 | 74 | ||
75 | 75 | ||
76 | #define CONFIG_BLOCK_VERSION 20 | 76 | #define CONFIG_BLOCK_VERSION 21 |
77 | #define CONFIG_BLOCK_SIZE 512 | 77 | #define CONFIG_BLOCK_SIZE 512 |
78 | #define RTC_BLOCK_SIZE 44 | 78 | #define RTC_BLOCK_SIZE 44 |
79 | 79 | ||
@@ -382,82 +382,49 @@ static const struct bit_entry hd_bits[] = | |||
382 | /* Sum of all bit sizes must not grow beyond 0xB8*8 = 1472 */ | 382 | /* Sum of all bit sizes must not grow beyond 0xB8*8 = 1472 */ |
383 | }; | 383 | }; |
384 | 384 | ||
385 | 385 | /* helper function to extract n (<=32) bits from an arbitrary position | |
386 | /* helper function to extract n (<=32) bits from an arbitrary position */ | 386 | * counting from LSB to MSB */ |
387 | static unsigned long get_bits( | 387 | static unsigned long get_bits( |
388 | const unsigned long* p, /* the start of the bitfield array */ | 388 | const unsigned long* p, /* the start of the bitfield array */ |
389 | unsigned int from, /* bit no. to start reading from */ | 389 | unsigned int from, /* bit no. to start reading from */ |
390 | unsigned int size) /* how many bits to read */ | 390 | unsigned int size) /* how many bits to read */ |
391 | { | 391 | { |
392 | unsigned int bit_index; | 392 | unsigned int long_index = from / 32; |
393 | unsigned int bits_to_use; | 393 | unsigned int bit_index = from % 32; |
394 | |||
395 | unsigned long mask; | ||
396 | unsigned long result; | 394 | unsigned long result; |
397 | 395 | ||
398 | if (size==1) | 396 | result = p[long_index] >> bit_index; |
399 | { /* short cut */ | ||
400 | return (p[from/32] & 1<<from%32) != 0; | ||
401 | } | ||
402 | 397 | ||
403 | result = 0; | 398 | if (bit_index + size > 32) /* crossing longword boundary */ |
404 | while (size) | 399 | result |= p[long_index+1] << (32 - bit_index); |
405 | { | ||
406 | bit_index = from % 32; | ||
407 | bits_to_use = MIN(32 - bit_index, size); | ||
408 | mask = 0xFFFFFFFF >> (32 - bits_to_use); | ||
409 | mask <<= bit_index; | ||
410 | |||
411 | result <<= bits_to_use; /* from last round */ | ||
412 | result |= (p[from/32] & mask) >> bit_index; | ||
413 | 400 | ||
414 | from += bits_to_use; | 401 | result &= 0xFFFFFFFF >> (32 - size); |
415 | size -= bits_to_use; | ||
416 | } | ||
417 | 402 | ||
418 | return result; | 403 | return result; |
419 | } | 404 | } |
420 | 405 | ||
421 | /* helper function to set n (<=32) bits to an arbitrary position */ | 406 | /* helper function to set n (<=32) bits to an arbitrary position, |
407 | * counting from LSB to MSB */ | ||
422 | static void set_bits( | 408 | static void set_bits( |
423 | unsigned long* p, /* the start of the bitfield array */ | 409 | unsigned long* p, /* the start of the bitfield array */ |
424 | unsigned int from, /* bit no. to start writing into */ | 410 | unsigned int from, /* bit no. to start writing into */ |
425 | unsigned int size, /* how many bits to change */ | 411 | unsigned int size, /* how many bits to change */ |
426 | unsigned long value) /* content (LSBs will be taken) */ | 412 | unsigned long value) /* content (LSBs will be taken) */ |
427 | { | 413 | { |
428 | unsigned int end; | 414 | unsigned int long_index = from / 32; |
429 | unsigned int word_index, bit_index; | 415 | unsigned int bit_index = from % 32; |
430 | unsigned int bits_to_use; | ||
431 | |||
432 | unsigned long mask; | 416 | unsigned long mask; |
433 | 417 | ||
434 | if (size==1) | 418 | mask = 0xFFFFFFFF >> (32 - size); |
435 | { /* short cut */ | 419 | value &= mask; |
436 | if (value & 1) | 420 | mask <<= bit_index; |
437 | p[from/32] |= 1<<from%32; | ||
438 | else | ||
439 | p[from/32] &= ~(1<<from%32); | ||
440 | return; | ||
441 | } | ||
442 | 421 | ||
443 | end = from + size - 1; | 422 | if (bit_index + size > 32) |
423 | p[long_index+1] = | ||
424 | (p[long_index+1] & (0xFFFFFFFF << (bit_index + size - 32))) | ||
425 | | (value >> (32 - bit_index)); | ||
444 | 426 | ||
445 | /* write back to front, least to most significant */ | 427 | p[long_index] = (p[long_index] & ~mask) | (value << bit_index); |
446 | while (size) | ||
447 | { | ||
448 | word_index = end / 32; | ||
449 | bit_index = (end % 32) + 1; | ||
450 | bits_to_use = MIN(bit_index, size); | ||
451 | bit_index -= bits_to_use; | ||
452 | mask = 0xFFFFFFFF >> (32 - bits_to_use); | ||
453 | mask <<= bit_index; | ||
454 | |||
455 | p[word_index] = (p[word_index] & ~mask) | (value<<bit_index & mask); | ||
456 | |||
457 | value >>= bits_to_use; | ||
458 | size -= bits_to_use; | ||
459 | end -= bits_to_use; | ||
460 | } | ||
461 | } | 428 | } |
462 | 429 | ||
463 | /* | 430 | /* |
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 | } |