From d0abfe86e00f3cec41970231ad90710914c73025 Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Sun, 28 Jul 2002 16:09:44 +0000 Subject: Experimental disk save by Yves. #define SAVE_TO_DISK to try it git-svn-id: svn://svn.rockbox.org/rockbox/trunk@1484 a1c6a512-1295-4272-9138-f99709370657 --- apps/settings.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++----------- apps/settings.h | 1 - 2 files changed, 72 insertions(+), 18 deletions(-) (limited to 'apps') diff --git a/apps/settings.c b/apps/settings.c index 5eebc61b41..68f5e66036 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -20,6 +20,7 @@ #include #include "config.h" +#include "kernel.h" #include "settings.h" #include "disk.h" #include "panic.h" @@ -28,11 +29,11 @@ #include "lcd.h" #include "mpeg.h" #include "string.h" +#include "ata.h" +#include "power.h" struct user_settings global_settings; -#ifdef HAVE_RTC - /******************************************** Config block as saved on the battery-packed RTC user RAM memory block @@ -60,7 +61,6 @@ offset abs the geeky but useless statistics part: 0x24 -0x28 0x2a @@ -113,6 +113,7 @@ static void init_config_buffer( void ) rtc_config_block[3] = 0x0; /* config block version number */ } +#ifdef HAVE_RTC /* * save the config block buffer on the RTC RAM */ @@ -184,8 +185,61 @@ static int load_config_buffer( void ) return 1; } +#else /* HAVE_RTC */ +/* + * save the config block buffer on the 61 Sector + */ +static int save_config_buffer( void ) +{ + DEBUGF( "save_config_buffer()\n" ); + + /* update the checksum in the end of the block before saving */ + calculate_config_checksum(rtc_config_block + sizeof(rtc_config_block) - 2); +#ifdef SAVE_TO_DISK + if(battery_level_safe()) + return !ata_write_sectors( 61, 1, rtc_config_block); + else + return -1; +#else + return 0; +#endif +} + +/* + * load the config block buffer from disk + */ +static int load_config_buffer( void ) +{ +#ifdef SAVE_TO_DISK + unsigned char cksum[2]; + + DEBUGF( "load_config_buffer()\n" ); + + ata_read_sectors( 61, 1, rtc_config_block); + + /* calculate the checksum, check it and the header */ + calculate_config_checksum(cksum); + + if (rtc_config_block[0x0] == 'R' + && rtc_config_block[0x1] == 'o' + && rtc_config_block[0x2] == 'c' + && rtc_config_block[0x3] == 0x0 + && cksum[0] == rtc_config_block[0x2a] + && cksum[1] == rtc_config_block[0x2b]) { + DEBUGF( "load_config_buffer: header & checksum test ok\n" ); + return 0; /* header and checksum is valid */ + } +#endif + /* if checksum is not valid, initialize the config buffer to all-unused */ + DEBUGF( "load_config_buffer: header & checksum test failed\n" ); + init_config_buffer(); + return 1; +} + + #endif /* HAVE_RTC */ + /* * persist all runtime user settings to disk or RTC RAM */ @@ -193,7 +247,6 @@ int settings_save( void ) { DEBUGF( "settings_save()\n" ); -#ifdef HAVE_RTC /* update the config block buffer with current settings and save the block in the RTC */ rtc_config_block[0x4] = (unsigned char)global_settings.volume; @@ -220,12 +273,22 @@ int settings_save( void ) rtc_config_block[0x11] = (unsigned char)global_settings.avc; memcpy(&rtc_config_block[0x24], &global_settings.total_uptime, 4); - memcpy(&rtc_config_block[0x28], &global_settings.total_boots, 2); - - save_config_buffer(); -#endif /* HAVE_RTC */ - return 1; + if(save_config_buffer()) + { + lcd_clear_display(); +#ifdef HAVE_LCD_CHARCELLS + lcd_puts(0, 0, "Save failed"); + lcd_puts(0, 1, "Batt. low?"); +#else + lcd_puts(4, 2, "Save failed"); + lcd_puts(2, 4, "Is battery low?"); + lcd_update(); +#endif + sleep(HZ*2); + return -1; + } + return 0; } /* @@ -233,16 +296,13 @@ int settings_save( void ) */ void settings_load(void) { -#ifdef HAVE_RTC unsigned char c; -#endif DEBUGF( "reload_all_settings()\n" ); /* populate settings with default values */ settings_reset(); -#ifdef HAVE_RTC /* 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 */ if (!load_config_buffer()) { @@ -286,11 +346,7 @@ void settings_load(void) if (rtc_config_block[0x24] != 0xFF) memcpy(&global_settings.total_uptime, &rtc_config_block[0x24], 4); - if (rtc_config_block[0x28] != 0xFF) - memcpy(&global_settings.total_boots, &rtc_config_block[0x28], 2); } - -#endif /* HAVE_RTC */ } /* @@ -314,7 +370,6 @@ void settings_reset(void) { global_settings.mp3filter = true; global_settings.sort_case = false; global_settings.playlist_shuffle = false; - global_settings.total_boots = 0; global_settings.total_uptime = 0; global_settings.scroll_speed = 8; } diff --git a/apps/settings.h b/apps/settings.h index 6a9f0ea636..ba6f32c37a 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -63,7 +63,6 @@ struct user_settings int wps_display; /* 0=id3, 1=file, 2=parse */ /* geeky persistent statistics */ - unsigned short total_boots; /* how many times the device has been booted */ unsigned int total_uptime; /* total uptime since rockbox was first booted */ }; -- cgit v1.2.3