summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2002-07-28 16:09:44 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2002-07-28 16:09:44 +0000
commitd0abfe86e00f3cec41970231ad90710914c73025 (patch)
tree9504918753d01f438df1c988ec813af28cbe3a89
parentb92c0cf3ebe5c1069c3410db388db81648bca00c (diff)
downloadrockbox-d0abfe86e00f3cec41970231ad90710914c73025.tar.gz
rockbox-d0abfe86e00f3cec41970231ad90710914c73025.zip
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
-rw-r--r--apps/settings.c89
-rw-r--r--apps/settings.h1
2 files changed, 72 insertions, 18 deletions
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 @@
20 20
21#include <stdio.h> 21#include <stdio.h>
22#include "config.h" 22#include "config.h"
23#include "kernel.h"
23#include "settings.h" 24#include "settings.h"
24#include "disk.h" 25#include "disk.h"
25#include "panic.h" 26#include "panic.h"
@@ -28,11 +29,11 @@
28#include "lcd.h" 29#include "lcd.h"
29#include "mpeg.h" 30#include "mpeg.h"
30#include "string.h" 31#include "string.h"
32#include "ata.h"
33#include "power.h"
31 34
32struct user_settings global_settings; 35struct user_settings global_settings;
33 36
34#ifdef HAVE_RTC
35
36/******************************************** 37/********************************************
37 38
38Config block as saved on the battery-packed RTC user RAM memory block 39Config block as saved on the battery-packed RTC user RAM memory block
@@ -60,7 +61,6 @@ offset abs
60 61
61 the geeky but useless statistics part: 62 the geeky but useless statistics part:
620x24 <total uptime in seconds: 32 bits uint, actually unused for now> 630x24 <total uptime in seconds: 32 bits uint, actually unused for now>
630x28 <boots: 16 bits uint>
64 64
650x2a <checksum 2 bytes: xor of 0x0-0x29> 650x2a <checksum 2 bytes: xor of 0x0-0x29>
66 66
@@ -113,6 +113,7 @@ static void init_config_buffer( void )
113 rtc_config_block[3] = 0x0; /* config block version number */ 113 rtc_config_block[3] = 0x0; /* config block version number */
114} 114}
115 115
116#ifdef HAVE_RTC
116/* 117/*
117 * save the config block buffer on the RTC RAM 118 * save the config block buffer on the RTC RAM
118 */ 119 */
@@ -184,8 +185,61 @@ static int load_config_buffer( void )
184 return 1; 185 return 1;
185} 186}
186 187
188#else /* HAVE_RTC */
189/*
190 * save the config block buffer on the 61 Sector
191 */
192static int save_config_buffer( void )
193{
194 DEBUGF( "save_config_buffer()\n" );
195
196 /* update the checksum in the end of the block before saving */
197 calculate_config_checksum(rtc_config_block + sizeof(rtc_config_block) - 2);
198#ifdef SAVE_TO_DISK
199 if(battery_level_safe())
200 return !ata_write_sectors( 61, 1, rtc_config_block);
201 else
202 return -1;
203#else
204 return 0;
205#endif
206}
207
208/*
209 * load the config block buffer from disk
210 */
211static int load_config_buffer( void )
212{
213#ifdef SAVE_TO_DISK
214 unsigned char cksum[2];
215
216 DEBUGF( "load_config_buffer()\n" );
217
218 ata_read_sectors( 61, 1, rtc_config_block);
219
220 /* calculate the checksum, check it and the header */
221 calculate_config_checksum(cksum);
222
223 if (rtc_config_block[0x0] == 'R'
224 && rtc_config_block[0x1] == 'o'
225 && rtc_config_block[0x2] == 'c'
226 && rtc_config_block[0x3] == 0x0
227 && cksum[0] == rtc_config_block[0x2a]
228 && cksum[1] == rtc_config_block[0x2b]) {
229 DEBUGF( "load_config_buffer: header & checksum test ok\n" );
230 return 0; /* header and checksum is valid */
231 }
232#endif
233 /* if checksum is not valid, initialize the config buffer to all-unused */
234 DEBUGF( "load_config_buffer: header & checksum test failed\n" );
235 init_config_buffer();
236 return 1;
237}
238
239
187#endif /* HAVE_RTC */ 240#endif /* HAVE_RTC */
188 241
242
189/* 243/*
190 * persist all runtime user settings to disk or RTC RAM 244 * persist all runtime user settings to disk or RTC RAM
191 */ 245 */
@@ -193,7 +247,6 @@ int settings_save( void )
193{ 247{
194 DEBUGF( "settings_save()\n" ); 248 DEBUGF( "settings_save()\n" );
195 249
196#ifdef HAVE_RTC
197 /* update the config block buffer with current 250 /* update the config block buffer with current
198 settings and save the block in the RTC */ 251 settings and save the block in the RTC */
199 rtc_config_block[0x4] = (unsigned char)global_settings.volume; 252 rtc_config_block[0x4] = (unsigned char)global_settings.volume;
@@ -220,12 +273,22 @@ int settings_save( void )
220 rtc_config_block[0x11] = (unsigned char)global_settings.avc; 273 rtc_config_block[0x11] = (unsigned char)global_settings.avc;
221 274
222 memcpy(&rtc_config_block[0x24], &global_settings.total_uptime, 4); 275 memcpy(&rtc_config_block[0x24], &global_settings.total_uptime, 4);
223 memcpy(&rtc_config_block[0x28], &global_settings.total_boots, 2);
224
225 save_config_buffer();
226#endif /* HAVE_RTC */
227 276
228 return 1; 277 if(save_config_buffer())
278 {
279 lcd_clear_display();
280#ifdef HAVE_LCD_CHARCELLS
281 lcd_puts(0, 0, "Save failed");
282 lcd_puts(0, 1, "Batt. low?");
283#else
284 lcd_puts(4, 2, "Save failed");
285 lcd_puts(2, 4, "Is battery low?");
286 lcd_update();
287#endif
288 sleep(HZ*2);
289 return -1;
290 }
291 return 0;
229} 292}
230 293
231/* 294/*
@@ -233,16 +296,13 @@ int settings_save( void )
233 */ 296 */
234void settings_load(void) 297void settings_load(void)
235{ 298{
236#ifdef HAVE_RTC
237 unsigned char c; 299 unsigned char c;
238#endif
239 300
240 DEBUGF( "reload_all_settings()\n" ); 301 DEBUGF( "reload_all_settings()\n" );
241 302
242 /* populate settings with default values */ 303 /* populate settings with default values */
243 settings_reset(); 304 settings_reset();
244 305
245#ifdef HAVE_RTC
246 /* load the buffer from the RTC (resets it to all-unused if the block 306 /* load the buffer from the RTC (resets it to all-unused if the block
247 is invalid) and decode the settings which are set in the block */ 307 is invalid) and decode the settings which are set in the block */
248 if (!load_config_buffer()) { 308 if (!load_config_buffer()) {
@@ -286,11 +346,7 @@ void settings_load(void)
286 346
287 if (rtc_config_block[0x24] != 0xFF) 347 if (rtc_config_block[0x24] != 0xFF)
288 memcpy(&global_settings.total_uptime, &rtc_config_block[0x24], 4); 348 memcpy(&global_settings.total_uptime, &rtc_config_block[0x24], 4);
289 if (rtc_config_block[0x28] != 0xFF)
290 memcpy(&global_settings.total_boots, &rtc_config_block[0x28], 2);
291 } 349 }
292
293#endif /* HAVE_RTC */
294} 350}
295 351
296/* 352/*
@@ -314,7 +370,6 @@ void settings_reset(void) {
314 global_settings.mp3filter = true; 370 global_settings.mp3filter = true;
315 global_settings.sort_case = false; 371 global_settings.sort_case = false;
316 global_settings.playlist_shuffle = false; 372 global_settings.playlist_shuffle = false;
317 global_settings.total_boots = 0;
318 global_settings.total_uptime = 0; 373 global_settings.total_uptime = 0;
319 global_settings.scroll_speed = 8; 374 global_settings.scroll_speed = 8;
320} 375}
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
63 int wps_display; /* 0=id3, 1=file, 2=parse */ 63 int wps_display; /* 0=id3, 1=file, 2=parse */
64 64
65 /* geeky persistent statistics */ 65 /* geeky persistent statistics */
66 unsigned short total_boots; /* how many times the device has been booted */
67 unsigned int total_uptime; /* total uptime since rockbox was first booted */ 66 unsigned int total_uptime; /* total uptime since rockbox was first booted */
68}; 67};
69 68