diff options
author | Jörg Hohensohn <hohensoh@rockbox.org> | 2004-06-19 15:50:02 +0000 |
---|---|---|
committer | Jörg Hohensohn <hohensoh@rockbox.org> | 2004-06-19 15:50:02 +0000 |
commit | 6ff6d21d138f789e47f0487833475ac99a6f5f16 (patch) | |
tree | dfc5e850aae19ca1f80e6063ffa85d5359b072cf /apps/settings.c | |
parent | 75e7e501d5bcc77acad61cb769ebd03e4f3ce983 (diff) | |
download | rockbox-6ff6d21d138f789e47f0487833475ac99a6f5f16.tar.gz rockbox-6ff6d21d138f789e47f0487833475ac99a6f5f16.zip |
settings_load() is now split in RTC and HD part, so RTC settings get loaded early (car adapter mode)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4776 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/settings.c')
-rw-r--r-- | apps/settings.c | 100 |
1 files changed, 54 insertions, 46 deletions
diff --git a/apps/settings.c b/apps/settings.c index f5f46225d2..463fd710be 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -428,8 +428,8 @@ static void init_config_buffer( void ) | |||
428 | { | 428 | { |
429 | DEBUGF( "init_config_buffer()\n" ); | 429 | DEBUGF( "init_config_buffer()\n" ); |
430 | 430 | ||
431 | /* reset to 0xff - all unused */ | 431 | /* reset to 0 - all unused */ |
432 | memset(config_block, 0xff, CONFIG_BLOCK_SIZE); | 432 | memset(config_block, 0, CONFIG_BLOCK_SIZE); |
433 | /* insert header */ | 433 | /* insert header */ |
434 | config_block[0] = 'R'; | 434 | config_block[0] = 'R'; |
435 | config_block[1] = 'o'; | 435 | config_block[1] = 'o'; |
@@ -480,33 +480,32 @@ static int save_config_buffer( void ) | |||
480 | /* | 480 | /* |
481 | * load the config block buffer from disk or RTC RAM | 481 | * load the config block buffer from disk or RTC RAM |
482 | */ | 482 | */ |
483 | static int load_config_buffer( void ) | 483 | static int load_config_buffer(int which) |
484 | { | 484 | { |
485 | unsigned short chksum; | 485 | unsigned short chksum; |
486 | bool correct = false; | 486 | bool correct = false; |
487 | 487 | ||
488 | #ifdef HAVE_RTC | 488 | |
489 | unsigned int i; | ||
490 | unsigned char rtc_block[RTC_BLOCK_SIZE]; | ||
491 | #endif | ||
492 | |||
493 | DEBUGF( "load_config_buffer()\n" ); | 489 | DEBUGF( "load_config_buffer()\n" ); |
494 | 490 | ||
495 | if (fat_startsector() != 0) { | 491 | if (which & SETTINGS_HD) |
496 | ata_read_sectors( 61, 1, config_block); | 492 | { |
493 | if (fat_startsector() != 0) { | ||
494 | ata_read_sectors( 61, 1, config_block); | ||
497 | 495 | ||
498 | /* calculate the checksum, check it and the header */ | 496 | /* calculate the checksum, check it and the header */ |
499 | chksum = calculate_config_checksum(config_block); | 497 | chksum = calculate_config_checksum(config_block); |
500 | 498 | ||
501 | if (config_block[0] == 'R' && | 499 | if (config_block[0] == 'R' && |
502 | config_block[1] == 'o' && | 500 | config_block[1] == 'o' && |
503 | config_block[2] == 'c' && | 501 | config_block[2] == 'c' && |
504 | config_block[3] == CONFIG_BLOCK_VERSION && | 502 | config_block[3] == CONFIG_BLOCK_VERSION && |
505 | (chksum >> 8) == config_block[RTC_BLOCK_SIZE - 2] && | 503 | (chksum >> 8) == config_block[RTC_BLOCK_SIZE - 2] && |
506 | (chksum & 0xff) == config_block[RTC_BLOCK_SIZE - 1]) | 504 | (chksum & 0xff) == config_block[RTC_BLOCK_SIZE - 1]) |
507 | { | 505 | { |
508 | DEBUGF( "load_config_buffer: header & checksum test ok\n" ); | 506 | DEBUGF( "load_config_buffer: header & checksum test ok\n" ); |
509 | correct = true; | 507 | correct = true; |
508 | } | ||
510 | } | 509 | } |
511 | } | 510 | } |
512 | 511 | ||
@@ -514,24 +513,31 @@ static int load_config_buffer( void ) | |||
514 | if(!correct) | 513 | if(!correct) |
515 | { | 514 | { |
516 | /* If the disk sector was incorrect, reinit the buffer */ | 515 | /* If the disk sector was incorrect, reinit the buffer */ |
517 | memset(config_block, 0xff, CONFIG_BLOCK_SIZE); | 516 | memset(config_block, 0, CONFIG_BLOCK_SIZE); |
518 | } | 517 | } |
519 | /* read rtc block */ | ||
520 | for (i=0; i < RTC_BLOCK_SIZE; i++ ) | ||
521 | rtc_block[i] = rtc_read(0x14+i); | ||
522 | 518 | ||
523 | chksum = calculate_config_checksum(rtc_block); | 519 | if (which & SETTINGS_RTC) |
524 | |||
525 | /* if rtc block is ok, use that */ | ||
526 | if (rtc_block[0] == 'R' && | ||
527 | rtc_block[1] == 'o' && | ||
528 | rtc_block[2] == 'c' && | ||
529 | rtc_block[3] == CONFIG_BLOCK_VERSION && | ||
530 | (chksum >> 8) == rtc_block[RTC_BLOCK_SIZE - 2] && | ||
531 | (chksum & 0xff) == rtc_block[RTC_BLOCK_SIZE - 1]) | ||
532 | { | 520 | { |
533 | memcpy(config_block, rtc_block, RTC_BLOCK_SIZE); | 521 | unsigned int i; |
534 | correct = true; | 522 | unsigned char rtc_block[RTC_BLOCK_SIZE]; |
523 | |||
524 | /* read rtc block */ | ||
525 | for (i=0; i < RTC_BLOCK_SIZE; i++ ) | ||
526 | rtc_block[i] = rtc_read(0x14+i); | ||
527 | |||
528 | chksum = calculate_config_checksum(rtc_block); | ||
529 | |||
530 | /* if rtc block is ok, use that */ | ||
531 | if (rtc_block[0] == 'R' && | ||
532 | rtc_block[1] == 'o' && | ||
533 | rtc_block[2] == 'c' && | ||
534 | rtc_block[3] == CONFIG_BLOCK_VERSION && | ||
535 | (chksum >> 8) == rtc_block[RTC_BLOCK_SIZE - 2] && | ||
536 | (chksum & 0xff) == rtc_block[RTC_BLOCK_SIZE - 1]) | ||
537 | { | ||
538 | memcpy(config_block, rtc_block, RTC_BLOCK_SIZE); | ||
539 | correct = true; | ||
540 | } | ||
535 | } | 541 | } |
536 | #endif | 542 | #endif |
537 | 543 | ||
@@ -831,18 +837,15 @@ static void load_bit_table(const struct bit_entry* p_table, int count, int bitst | |||
831 | /* | 837 | /* |
832 | * load settings from disk or RTC RAM | 838 | * load settings from disk or RTC RAM |
833 | */ | 839 | */ |
834 | void settings_load(void) | 840 | void settings_load(int which) |
835 | { | 841 | { |
836 | int restore[6]; /* recover, FIXME: get rid of this */ | 842 | int restore[6]; /* recover, FIXME: get rid of this */ |
837 | 843 | ||
838 | DEBUGF( "reload_all_settings()\n" ); | 844 | DEBUGF( "reload_all_settings()\n" ); |
839 | 845 | ||
840 | /* populate settings with default values */ | ||
841 | settings_reset(); | ||
842 | |||
843 | /* load the buffer from the RTC (resets it to all-unused if the block | 846 | /* load the buffer from the RTC (resets it to all-unused if the block |
844 | is invalid) and decode the settings which are set in the block */ | 847 | is invalid) and decode the settings which are set in the block */ |
845 | if (!load_config_buffer()) | 848 | if (!load_config_buffer(which)) |
846 | { | 849 | { |
847 | /* While the mpeg_val2phys business still exists: ( FIXME: to be removed) */ | 850 | /* While the mpeg_val2phys business still exists: ( FIXME: to be removed) */ |
848 | /* temporarily put markers into the values to detect if they got loaded */ | 851 | /* temporarily put markers into the values to detect if they got loaded */ |
@@ -862,8 +865,15 @@ void settings_load(void) | |||
862 | #endif | 865 | #endif |
863 | 866 | ||
864 | /* load scalar values from RTC and HD sector, specified via table */ | 867 | /* load scalar values from RTC and HD sector, specified via table */ |
865 | load_bit_table(rtc_bits, sizeof(rtc_bits)/sizeof(rtc_bits[0]), 4*8); | 868 | if (which & SETTINGS_RTC) |
866 | load_bit_table(hd_bits, sizeof(hd_bits)/sizeof(hd_bits[0]), RTC_BLOCK_SIZE*8); | 869 | { |
870 | load_bit_table(rtc_bits, sizeof(rtc_bits)/sizeof(rtc_bits[0]), 4*8); | ||
871 | } | ||
872 | if (which & SETTINGS_HD) | ||
873 | { | ||
874 | load_bit_table(hd_bits, sizeof(hd_bits)/sizeof(hd_bits[0]), | ||
875 | RTC_BLOCK_SIZE*8); | ||
876 | } | ||
867 | 877 | ||
868 | /* FIXME, to be removed with mpeg_val2phys: */ | 878 | /* FIXME, to be removed with mpeg_val2phys: */ |
869 | /* if a value got loaded, convert it, else restore it */ | 879 | /* if a value got loaded, convert it, else restore it */ |
@@ -888,9 +898,7 @@ void settings_load(void) | |||
888 | strncpy(global_settings.wps_file, &config_block[0xb8], MAX_FILENAME); | 898 | strncpy(global_settings.wps_file, &config_block[0xb8], MAX_FILENAME); |
889 | strncpy(global_settings.lang_file, &config_block[0xcc], MAX_FILENAME); | 899 | strncpy(global_settings.lang_file, &config_block[0xcc], MAX_FILENAME); |
890 | strncpy(global_settings.font_file, &config_block[0xe0], MAX_FILENAME); | 900 | strncpy(global_settings.font_file, &config_block[0xe0], MAX_FILENAME); |
891 | } | 901 | } |
892 | |||
893 | settings_apply(); | ||
894 | } | 902 | } |
895 | 903 | ||
896 | /* parse a line from a configuration file. the line format is: | 904 | /* parse a line from a configuration file. the line format is: |