1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Jörg Hohensohn 2004-06-19 15:50:02 +00:00
parent 75e7e501d5
commit 6ff6d21d13
3 changed files with 76 additions and 61 deletions

View file

@ -55,6 +55,9 @@
#include "screens.h" #include "screens.h"
#include "power.h" #include "power.h"
#include "talk.h" #include "talk.h"
#include "plugin.h"
/*#define AUTOROCK*/ /* define this to check for "autostart.rock" on boot */
char appsversion[]=APPSVERSION; char appsversion[]=APPSVERSION;
@ -76,7 +79,8 @@ void init(void)
font_init(); font_init();
show_logo(); show_logo();
settings_reset(); settings_reset();
settings_load(); settings_load(SETTINGS_ALL);
settings_apply();
sleep(HZ/2); sleep(HZ/2);
tree_init(); tree_init();
playlist_init(); playlist_init();
@ -129,6 +133,7 @@ void init(void)
#ifdef HAVE_RTC #ifdef HAVE_RTC
rtc_init(); rtc_init();
settings_load(SETTINGS_RTC); /* early load parts of global_settings */
#endif #endif
adc_init(); adc_init();
@ -142,7 +147,7 @@ void init(void)
powermgmt_init(); powermgmt_init();
#ifdef HAVE_BATTERIES #ifdef HAVE_BATTERIES
if (coldstart && charger_inserted()) if (coldstart && charger_inserted() && !global_settings.car_adapter_mode)
{ {
rc = charging_screen(); /* display a "charging" screen */ rc = charging_screen(); /* display a "charging" screen */
if (rc == 1 || rc == 2) /* charger removed or "Off/Stop" pressed */ if (rc == 1 || rc == 2) /* charger removed or "Off/Stop" pressed */
@ -196,7 +201,8 @@ void init(void)
} }
} }
settings_load(); settings_load(SETTINGS_ALL);
settings_apply();
status_init(); status_init();
playlist_init(); playlist_init();
@ -215,24 +221,20 @@ void init(void)
mpeg_init(); mpeg_init();
talk_init(); talk_init();
/* no auto-rolo on startup any more, but I leave it here for reference */ #ifdef AUTOROCK
#if 0 if (!usb_detect())
if (coldstart && !usb_detect()) {
{ /* when starting from flash, this time _we_ have to yield */
int fd; int fd;
#ifdef ARCHOS_PLAYER static const char filename[] = PLUGIN_DIR "/autostart.rock";
static const char filename[] = "/archos.mod";
#else
static const char filename[] = "/ajbrec.ajz";
#endif
fd = open(filename, O_RDONLY); fd = open(filename, O_RDONLY);
if(fd >= 0) /* no complaint if it doesn't exit */ if(fd >= 0) /* no complaint if it doesn't exit */
{ {
close(fd); close(fd);
rolo_load((char*)filename); /* start if it does */ plugin_load((char*)filename, NULL); /* start if it does */
} }
} }
#endif // #if 0 #endif /* #ifdef AUTOROCK */
} }
int main(void) int main(void)

View file

@ -428,8 +428,8 @@ static void init_config_buffer( void )
{ {
DEBUGF( "init_config_buffer()\n" ); DEBUGF( "init_config_buffer()\n" );
/* reset to 0xff - all unused */ /* reset to 0 - all unused */
memset(config_block, 0xff, CONFIG_BLOCK_SIZE); memset(config_block, 0, CONFIG_BLOCK_SIZE);
/* insert header */ /* insert header */
config_block[0] = 'R'; config_block[0] = 'R';
config_block[1] = 'o'; config_block[1] = 'o';
@ -480,33 +480,32 @@ static int save_config_buffer( void )
/* /*
* load the config block buffer from disk or RTC RAM * load the config block buffer from disk or RTC RAM
*/ */
static int load_config_buffer( void ) static int load_config_buffer(int which)
{ {
unsigned short chksum; unsigned short chksum;
bool correct = false; bool correct = false;
#ifdef HAVE_RTC
unsigned int i;
unsigned char rtc_block[RTC_BLOCK_SIZE];
#endif
DEBUGF( "load_config_buffer()\n" ); DEBUGF( "load_config_buffer()\n" );
if (fat_startsector() != 0) { if (which & SETTINGS_HD)
ata_read_sectors( 61, 1, config_block); {
if (fat_startsector() != 0) {
ata_read_sectors( 61, 1, config_block);
/* calculate the checksum, check it and the header */ /* calculate the checksum, check it and the header */
chksum = calculate_config_checksum(config_block); chksum = calculate_config_checksum(config_block);
if (config_block[0] == 'R' && if (config_block[0] == 'R' &&
config_block[1] == 'o' && config_block[1] == 'o' &&
config_block[2] == 'c' && config_block[2] == 'c' &&
config_block[3] == CONFIG_BLOCK_VERSION && config_block[3] == CONFIG_BLOCK_VERSION &&
(chksum >> 8) == config_block[RTC_BLOCK_SIZE - 2] && (chksum >> 8) == config_block[RTC_BLOCK_SIZE - 2] &&
(chksum & 0xff) == config_block[RTC_BLOCK_SIZE - 1]) (chksum & 0xff) == config_block[RTC_BLOCK_SIZE - 1])
{ {
DEBUGF( "load_config_buffer: header & checksum test ok\n" ); DEBUGF( "load_config_buffer: header & checksum test ok\n" );
correct = true; correct = true;
}
} }
} }
@ -514,24 +513,31 @@ static int load_config_buffer( void )
if(!correct) if(!correct)
{ {
/* If the disk sector was incorrect, reinit the buffer */ /* If the disk sector was incorrect, reinit the buffer */
memset(config_block, 0xff, CONFIG_BLOCK_SIZE); memset(config_block, 0, CONFIG_BLOCK_SIZE);
} }
/* read rtc block */
for (i=0; i < RTC_BLOCK_SIZE; i++ )
rtc_block[i] = rtc_read(0x14+i);
chksum = calculate_config_checksum(rtc_block); if (which & SETTINGS_RTC)
/* if rtc block is ok, use that */
if (rtc_block[0] == 'R' &&
rtc_block[1] == 'o' &&
rtc_block[2] == 'c' &&
rtc_block[3] == CONFIG_BLOCK_VERSION &&
(chksum >> 8) == rtc_block[RTC_BLOCK_SIZE - 2] &&
(chksum & 0xff) == rtc_block[RTC_BLOCK_SIZE - 1])
{ {
memcpy(config_block, rtc_block, RTC_BLOCK_SIZE); unsigned int i;
correct = true; unsigned char rtc_block[RTC_BLOCK_SIZE];
/* read rtc block */
for (i=0; i < RTC_BLOCK_SIZE; i++ )
rtc_block[i] = rtc_read(0x14+i);
chksum = calculate_config_checksum(rtc_block);
/* if rtc block is ok, use that */
if (rtc_block[0] == 'R' &&
rtc_block[1] == 'o' &&
rtc_block[2] == 'c' &&
rtc_block[3] == CONFIG_BLOCK_VERSION &&
(chksum >> 8) == rtc_block[RTC_BLOCK_SIZE - 2] &&
(chksum & 0xff) == rtc_block[RTC_BLOCK_SIZE - 1])
{
memcpy(config_block, rtc_block, RTC_BLOCK_SIZE);
correct = true;
}
} }
#endif #endif
@ -831,18 +837,15 @@ static void load_bit_table(const struct bit_entry* p_table, int count, int bitst
/* /*
* load settings from disk or RTC RAM * load settings from disk or RTC RAM
*/ */
void settings_load(void) void settings_load(int which)
{ {
int restore[6]; /* recover, FIXME: get rid of this */ int restore[6]; /* recover, FIXME: get rid of this */
DEBUGF( "reload_all_settings()\n" ); DEBUGF( "reload_all_settings()\n" );
/* populate settings with default values */
settings_reset();
/* load the buffer from the RTC (resets it to all-unused if the block /* load the buffer from the RTC (resets it to all-unused if the block
is invalid) and decode the settings which are set in the block */ is invalid) and decode the settings which are set in the block */
if (!load_config_buffer()) if (!load_config_buffer(which))
{ {
/* While the mpeg_val2phys business still exists: ( FIXME: to be removed) */ /* While the mpeg_val2phys business still exists: ( FIXME: to be removed) */
/* temporarily put markers into the values to detect if they got loaded */ /* temporarily put markers into the values to detect if they got loaded */
@ -862,8 +865,15 @@ void settings_load(void)
#endif #endif
/* load scalar values from RTC and HD sector, specified via table */ /* load scalar values from RTC and HD sector, specified via table */
load_bit_table(rtc_bits, sizeof(rtc_bits)/sizeof(rtc_bits[0]), 4*8); if (which & SETTINGS_RTC)
load_bit_table(hd_bits, sizeof(hd_bits)/sizeof(hd_bits[0]), RTC_BLOCK_SIZE*8); {
load_bit_table(rtc_bits, sizeof(rtc_bits)/sizeof(rtc_bits[0]), 4*8);
}
if (which & SETTINGS_HD)
{
load_bit_table(hd_bits, sizeof(hd_bits)/sizeof(hd_bits[0]),
RTC_BLOCK_SIZE*8);
}
/* FIXME, to be removed with mpeg_val2phys: */ /* FIXME, to be removed with mpeg_val2phys: */
/* if a value got loaded, convert it, else restore it */ /* if a value got loaded, convert it, else restore it */
@ -888,9 +898,7 @@ void settings_load(void)
strncpy(global_settings.wps_file, &config_block[0xb8], MAX_FILENAME); strncpy(global_settings.wps_file, &config_block[0xb8], MAX_FILENAME);
strncpy(global_settings.lang_file, &config_block[0xcc], MAX_FILENAME); strncpy(global_settings.lang_file, &config_block[0xcc], MAX_FILENAME);
strncpy(global_settings.font_file, &config_block[0xe0], MAX_FILENAME); strncpy(global_settings.font_file, &config_block[0xe0], MAX_FILENAME);
} }
settings_apply();
} }
/* parse a line from a configuration file. the line format is: /* parse a line from a configuration file. the line format is:

View file

@ -220,7 +220,7 @@ struct opt_items {
/* prototypes */ /* prototypes */
int settings_save(void); int settings_save(void);
void settings_load(void); void settings_load(int which);
void settings_reset(void); void settings_reset(void);
void settings_apply(void); void settings_apply(void);
void settings_apply_pm_range(void); void settings_apply_pm_range(void);
@ -267,6 +267,11 @@ extern char rec_base_directory[];
#endif #endif
#define MIN_CONTRAST_SETTING 5 #define MIN_CONTRAST_SETTING 5
/* argument bits for settings_load() */
#define SETTINGS_RTC 1 /* only the settings from the RTC nonvolatile RAM */
#define SETTINGS_HD 2 /* only the settings fron the disk sector */
#define SETTINGS_ALL 3 /* both */
/* repeat mode options */ /* repeat mode options */
enum { REPEAT_OFF, REPEAT_ALL, REPEAT_ONE, NUM_REPEAT_MODES }; enum { REPEAT_OFF, REPEAT_ALL, REPEAT_ONE, NUM_REPEAT_MODES };