Split the system status variables out of global_settings and put them into a new struct global_status. Use status_save() if these need

saving.
Added car_adapter_mode to the nvram settings, so nvram settings will be reset.


git-svn-id: svn://svn.rockbox.org/rockbox/trunk@12101 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Jonathan Gordon 2007-01-24 02:19:22 +00:00
parent cdcffd9883
commit 228d62dd18
13 changed files with 115 additions and 83 deletions

View file

@ -1830,7 +1830,7 @@ static bool dbg_dircache_info(void)
lcd_puts(0, line++, buf); lcd_puts(0, line++, buf);
snprintf(buf, sizeof(buf), "Last size: %d B", snprintf(buf, sizeof(buf), "Last size: %d B",
global_settings.dircache_size); global_status.dircache_size);
lcd_puts(0, line++, buf); lcd_puts(0, line++, buf);
snprintf(buf, sizeof(buf), "Limit: %d B", DIRCACHE_LIMIT); snprintf(buf, sizeof(buf), "Limit: %d B", DIRCACHE_LIMIT);

View file

@ -572,9 +572,9 @@ int ft_enter(struct tree_context* c)
if ( play ) { if ( play ) {
/* the resume_index must always be the index in the /* the resume_index must always be the index in the
shuffled list in case shuffle is enabled */ shuffled list in case shuffle is enabled */
global_settings.resume_index = start_index; global_status.resume_index = start_index;
global_settings.resume_offset = 0; global_status.resume_offset = 0;
settings_save(); status_save();
start_wps = true; start_wps = true;
} }

View file

@ -2483,7 +2483,7 @@ bool gui_wps_display(void)
int i; int i;
if (!wps_state.id3 && !(audio_status() & AUDIO_STATUS_PLAY)) if (!wps_state.id3 && !(audio_status() & AUDIO_STATUS_PLAY))
{ {
global_settings.resume_index = -1; global_status.resume_index = -1;
#ifdef HAVE_LCD_CHARCELLS #ifdef HAVE_LCD_CHARCELLS
gui_syncsplash(HZ, true, str(LANG_END_PLAYLIST_PLAYER)); gui_syncsplash(HZ, true, str(LANG_END_PLAYLIST_PLAYER));
#else #else

View file

@ -140,7 +140,7 @@ static int init_dircache(bool preinit)
if (result < 0) if (result < 0)
{ {
firmware_settings.disk_clean = false; firmware_settings.disk_clean = false;
if (global_settings.dircache_size <= 0) if (global_status.dircache_size <= 0)
{ {
/* This will be in default language, settings are not /* This will be in default language, settings are not
applied yet. Not really any easy way to fix that. */ applied yet. Not really any easy way to fix that. */
@ -148,7 +148,7 @@ static int init_dircache(bool preinit)
clear = true; clear = true;
} }
dircache_build(global_settings.dircache_size); dircache_build(global_status.dircache_size);
} }
} }
else else
@ -160,12 +160,12 @@ static int init_dircache(bool preinit)
if (!dircache_is_enabled() if (!dircache_is_enabled()
&& !dircache_is_initializing()) && !dircache_is_initializing())
{ {
if (global_settings.dircache_size <= 0) if (global_status.dircache_size <= 0)
{ {
gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING)); gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING));
clear = true; clear = true;
} }
result = dircache_build(global_settings.dircache_size); result = dircache_build(global_status.dircache_size);
} }
if (result < 0) if (result < 0)
@ -176,8 +176,8 @@ static int init_dircache(bool preinit)
{ {
backlight_on(); backlight_on();
show_logo(); show_logo();
global_settings.dircache_size = dircache_get_cache_size(); global_status.dircache_size = dircache_get_cache_size();
settings_save(); status_save();
} }
return result; return result;

View file

@ -243,8 +243,8 @@ static void empty_playlist(struct playlist_info* playlist, bool resume)
create_control(playlist); create_control(playlist);
/* Reset resume settings */ /* Reset resume settings */
global_settings.resume_first_index = 0; global_status.resume_first_index = 0;
global_settings.resume_seed = -1; global_status.resume_seed = -1;
} }
} }
@ -386,8 +386,8 @@ static int recreate_control(struct playlist_info* playlist)
if (playlist->current) if (playlist->current)
{ {
global_settings.resume_seed = -1; global_status.resume_seed = -1;
settings_save(); status_save();
} }
for (i=0; i<playlist->amount; i++) for (i=0; i<playlist->amount; i++)
@ -710,8 +710,8 @@ static int add_track_to_playlist(struct playlist_info* playlist,
if (seek_pos < 0 && playlist->current) if (seek_pos < 0 && playlist->current)
{ {
global_settings.resume_first_index = playlist->first_index; global_status.resume_first_index = playlist->first_index;
settings_save(); status_save();
} }
} }
@ -826,8 +826,8 @@ static int remove_track_from_playlist(struct playlist_info* playlist,
if (write) if (write)
{ {
global_settings.resume_first_index = playlist->first_index; global_status.resume_first_index = playlist->first_index;
settings_save(); status_save();
} }
} }
@ -902,8 +902,8 @@ static int randomise_playlist(struct playlist_info* playlist,
{ {
update_control(playlist, PLAYLIST_COMMAND_SHUFFLE, seed, update_control(playlist, PLAYLIST_COMMAND_SHUFFLE, seed,
playlist->first_index, NULL, NULL, NULL); playlist->first_index, NULL, NULL, NULL);
global_settings.resume_seed = seed; global_status.resume_seed = seed;
settings_save(); status_save();
} }
return 0; return 0;
@ -942,8 +942,8 @@ static int sort_playlist(struct playlist_info* playlist, bool start_current,
{ {
update_control(playlist, PLAYLIST_COMMAND_UNSHUFFLE, update_control(playlist, PLAYLIST_COMMAND_UNSHUFFLE,
playlist->first_index, -1, NULL, NULL, NULL); playlist->first_index, -1, NULL, NULL, NULL);
global_settings.resume_seed = 0; global_status.resume_seed = 0;
settings_save(); status_save();
} }
return 0; return 0;
@ -1117,8 +1117,8 @@ static void find_and_set_playlist_index(struct playlist_info* playlist,
if (playlist->current) if (playlist->current)
{ {
global_settings.resume_first_index = i; global_status.resume_first_index = i;
settings_save(); status_save();
} }
break; break;
@ -1742,10 +1742,10 @@ static int flush_cached_control(struct playlist_info* playlist)
if (result > 0) if (result > 0)
{ {
if (global_settings.resume_seed >= 0) if (global_status.resume_seed >= 0)
{ {
global_settings.resume_seed = -1; global_status.resume_seed = -1;
settings_save(); status_save();
} }
playlist->num_cached = 0; playlist->num_cached = 0;
@ -2294,22 +2294,22 @@ int playlist_resume(void)
/* Terminate on EOF */ /* Terminate on EOF */
if(nread <= 0) if(nread <= 0)
{ {
if (global_settings.resume_seed >= 0) if (global_status.resume_seed >= 0)
{ {
/* Apply shuffle command saved in settings */ /* Apply shuffle command saved in settings */
if (global_settings.resume_seed == 0) if (global_status.resume_seed == 0)
sort_playlist(playlist, false, true); sort_playlist(playlist, false, true);
else else
{ {
if (!sorted) if (!sorted)
sort_playlist(playlist, false, false); sort_playlist(playlist, false, false);
randomise_playlist(playlist, global_settings.resume_seed, randomise_playlist(playlist, global_status.resume_seed,
false, true); false, true);
} }
} }
playlist->first_index = global_settings.resume_first_index; playlist->first_index = global_status.resume_first_index;
break; break;
} }
} }
@ -2361,7 +2361,7 @@ int playlist_shuffle(int random_seed, int start_index)
{ {
/* store the seek position before the shuffle */ /* store the seek position before the shuffle */
seek_pos = playlist->indices[start_index]; seek_pos = playlist->indices[start_index];
playlist->index = global_settings.resume_first_index = playlist->index = global_status.resume_first_index =
playlist->first_index = start_index; playlist->first_index = start_index;
start_current = true; start_current = true;
} }
@ -2508,7 +2508,7 @@ int playlist_next(int steps)
playlist->amount > 1) playlist->amount > 1)
{ {
/* Repeat shuffle mode. Re-shuffle playlist and resume play */ /* Repeat shuffle mode. Re-shuffle playlist and resume play */
playlist->first_index = global_settings.resume_first_index = 0; playlist->first_index = global_status.resume_first_index = 0;
sort_playlist(playlist, false, false); sort_playlist(playlist, false, false);
randomise_playlist(playlist, current_tick, false, true); randomise_playlist(playlist, current_tick, false, true);
#if CONFIG_CODEC != SWCODEC #if CONFIG_CODEC != SWCODEC
@ -2651,19 +2651,19 @@ int playlist_update_resume_info(const struct mp3entry* id3)
if (id3) if (id3)
{ {
if (global_settings.resume_index != playlist->index || if (global_status.resume_index != playlist->index ||
global_settings.resume_offset != id3->offset) global_status.resume_offset != id3->offset)
{ {
global_settings.resume_index = playlist->index; global_status.resume_index = playlist->index;
global_settings.resume_offset = id3->offset; global_status.resume_offset = id3->offset;
settings_save(); status_save();
} }
} }
else else
{ {
global_settings.resume_index = -1; global_status.resume_index = -1;
global_settings.resume_offset = -1; global_status.resume_offset = -1;
settings_save(); status_save();
} }
return 0; return 0;

View file

@ -110,12 +110,12 @@
#define PLUGIN_MAGIC 0x526F634B /* RocK */ #define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */ /* increase this every time the api struct changes */
#define PLUGIN_API_VERSION 40 #define PLUGIN_API_VERSION 41
/* update this to latest version if a change to the api struct breaks /* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */ new function which are "waiting" at the end of the function table) */
#define PLUGIN_MIN_API_VERSION 38 #define PLUGIN_MIN_API_VERSION 41
/* plugin return codes */ /* plugin return codes */
enum plugin_status { enum plugin_status {

View file

@ -212,7 +212,7 @@ void radio_start(void)
if(radio_status == FMRADIO_OFF) if(radio_status == FMRADIO_OFF)
radio_power(true); radio_power(true);
curr_freq = global_settings.last_frequency curr_freq = global_status.last_frequency
* fm_region[global_settings.fm_region].freq_step * fm_region[global_settings.fm_region].freq_step
+ fm_region[global_settings.fm_region].freq_min; + fm_region[global_settings.fm_region].freq_min;
@ -332,10 +332,10 @@ static int find_closest_preset(int freq)
static void remember_frequency(void) static void remember_frequency(void)
{ {
global_settings.last_frequency = (curr_freq global_status.last_frequency = (curr_freq
- fm_region[global_settings.fm_region].freq_min) - fm_region[global_settings.fm_region].freq_min)
/ fm_region[global_settings.fm_region].freq_step; / fm_region[global_settings.fm_region].freq_step;
settings_save(); status_save();
} }
static void next_preset(int direction) static void next_preset(int direction)

View file

@ -1337,21 +1337,21 @@ bool view_runtime(void)
#endif #endif
) )
{ {
global_settings.runtime = 0; global_status.runtime = 0;
} }
else else
#endif #endif
{ {
global_settings.runtime += ((current_tick - lasttime) / HZ); global_status.runtime += ((current_tick - lasttime) / HZ);
} }
lasttime = current_tick; lasttime = current_tick;
t = global_settings.runtime; t = global_status.runtime;
FOR_NB_SCREENS(i) FOR_NB_SCREENS(i)
screens[i].puts(0, y[i]++, str(LANG_CURRENT_TIME)); screens[i].puts(0, y[i]++, str(LANG_CURRENT_TIME));
} }
else { else {
t = global_settings.topruntime; t = global_status.topruntime;
FOR_NB_SCREENS(i) FOR_NB_SCREENS(i)
screens[i].puts(0, y[i]++, str(LANG_TOP_TIME)); screens[i].puts(0, y[i]++, str(LANG_TOP_TIME));
} }
@ -1382,9 +1382,9 @@ bool view_runtime(void)
if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES) if(gui_syncyesno_run(&message, NULL, NULL)==YESNO_YES)
{ {
if ( state == 1 ) if ( state == 1 )
global_settings.runtime = 0; global_status.runtime = 0;
else else
global_settings.topruntime = 0; global_status.topruntime = 0;
} }
break; break;
default: default:

View file

@ -86,6 +86,7 @@
void dac_line_in(bool enable); void dac_line_in(bool enable);
#endif #endif
struct user_settings global_settings; struct user_settings global_settings;
struct system_status global_status;
#ifdef HAVE_RECORDING #ifdef HAVE_RECORDING
const char rec_base_directory[] = REC_BASE_DIR; const char rec_base_directory[] = REC_BASE_DIR;
#endif #endif
@ -346,6 +347,12 @@ bool settings_write_config(char* filename)
close(fd); close(fd);
return true; return true;
} }
#ifndef HAVE_RTC_RAM
static bool flush_global_status_callback(void)
{
return write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
}
#endif
static bool flush_config_block_callback(void) static bool flush_config_block_callback(void)
{ {
bool r1, r2; bool r1, r2;
@ -357,16 +364,33 @@ static bool flush_config_block_callback(void)
/* /*
* persist all runtime user settings to disk or RTC RAM * persist all runtime user settings to disk or RTC RAM
*/ */
int settings_save( void ) static void update_runtime(void)
{ {
int elapsed_secs; int elapsed_secs;
elapsed_secs = (current_tick - lasttime) / HZ; elapsed_secs = (current_tick - lasttime) / HZ;
global_settings.runtime += elapsed_secs; global_status.runtime += elapsed_secs;
lasttime += (elapsed_secs * HZ); lasttime += (elapsed_secs * HZ);
if ( global_settings.runtime > global_settings.topruntime ) if ( global_status.runtime > global_status.topruntime )
global_settings.topruntime = global_settings.runtime; global_status.topruntime = global_status.runtime;
}
void status_save( void )
{
update_runtime();
#ifdef HAVE_RTC_RAM
/* this will be done in the ata_callback if
target doesnt have rtc ram */
write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
#else
register_ata_idle_func(flush_global_status_callback);
#endif
}
int settings_save( void )
{
update_runtime();
#ifdef HAVE_RTC_RAM #ifdef HAVE_RTC_RAM
/* this will be done in the ata_callback if /* this will be done in the ata_callback if
target doesnt have rtc ram */ target doesnt have rtc ram */

View file

@ -128,7 +128,23 @@ extern unsigned char vp_dummy[VIRT_SIZE];
#if !defined(HAVE_LCD_COLOR) #if !defined(HAVE_LCD_COLOR)
#define HAVE_LCD_CONTRAST #define HAVE_LCD_CONTRAST
#endif #endif
struct system_status
{
int resume_index; /* index in playlist (-1 for no active resume) */
int resume_first_index; /* index of first track in playlist */
uint32_t resume_offset; /* byte offset in mp3 file */
int resume_seed; /* shuffle seed (-1=no resume shuffle 0=sorted
>0=shuffled) */
int runtime; /* current runtime since last charge */
int topruntime; /* top known runtime */
#ifdef HAVE_DIRCACHE
int dircache_size; /* directory cache structure last size, 22 bits */
#endif
#ifdef CONFIG_TUNER
int last_frequency; /* Last frequency for resuming, in FREQ_STEP units,
relative to MIN_FREQ */
#endif
};
struct user_settings struct user_settings
{ {
/* audio settings */ /* audio settings */
@ -254,11 +270,6 @@ struct user_settings
/* resume settings */ /* resume settings */
bool resume; /* resume option: 0=off, 1=on */ bool resume; /* resume option: 0=off, 1=on */
int resume_index; /* index in playlist (-1 for no active resume) */
int resume_first_index; /* index of first track in playlist */
uint32_t resume_offset; /* byte offset in mp3 file */
int resume_seed; /* shuffle seed (-1=no resume shuffle 0=sorted
>0=shuffled) */
#ifdef CONFIG_TUNER #ifdef CONFIG_TUNER
unsigned char fmr_file[MAX_FILENAME+1]; /* last fmr preset */ unsigned char fmr_file[MAX_FILENAME+1]; /* last fmr preset */
@ -304,8 +315,6 @@ struct user_settings
bool browse_current; /* 1=goto current song, bool browse_current; /* 1=goto current song,
0=goto previous location */ 0=goto previous location */
int runtime; /* current runtime since last charge */
int topruntime; /* top known runtime */
int scroll_speed; /* long texts scrolling speed: 1-30 */ int scroll_speed; /* long texts scrolling speed: 1-30 */
int bidir_limit; /* bidir scroll length limit */ int bidir_limit; /* bidir scroll length limit */
@ -339,8 +348,6 @@ struct user_settings
bool fm_force_mono; /* Forces Mono mode if true */ bool fm_force_mono; /* Forces Mono mode if true */
bool fm_full_range; /* Enables full 10MHz-160MHz range if true, else bool fm_full_range; /* Enables full 10MHz-160MHz range if true, else
only 88MHz-108MHz */ only 88MHz-108MHz */
int last_frequency; /* Last frequency for resuming, in FREQ_STEP units,
relative to MIN_FREQ */
#endif #endif
int max_files_in_dir; /* Max entries in directory (file browser) */ int max_files_in_dir; /* Max entries in directory (file browser) */
@ -406,7 +413,6 @@ struct user_settings
#endif #endif
#ifdef HAVE_DIRCACHE #ifdef HAVE_DIRCACHE
bool dircache; /* enable directory cache */ bool dircache; /* enable directory cache */
int dircache_size; /* directory cache structure last size, 22 bits */
#endif #endif
#ifdef HAVE_TAGCACHE #ifdef HAVE_TAGCACHE
#ifdef HAVE_TC_RAMCACHE #ifdef HAVE_TC_RAMCACHE
@ -548,7 +554,7 @@ struct opt_items {
}; };
/* prototypes */ /* prototypes */
void status_save( void );
int settings_save(void); int settings_save(void);
void settings_load(int which); void settings_load(int which);
void settings_reset(void); void settings_reset(void);
@ -581,6 +587,8 @@ void settings_apply_trigger(void);
/* global settings */ /* global settings */
extern struct user_settings global_settings; extern struct user_settings global_settings;
/* global status */
extern struct system_status global_status;
/* name of directory where configuration, fonts and other data /* name of directory where configuration, fonts and other data
* files are stored */ * files are stored */
extern long lasttime; extern long lasttime;

View file

@ -104,7 +104,7 @@ static const char backlight_times_conf [] =
{{cb,LANG_SET_BOOL_YES,LANG_SET_BOOL_NO}}} } {{cb,LANG_SET_BOOL_YES,LANG_SET_BOOL_NO}}} }
#define SYSTEM_SETTING(flags,var,default) \ #define SYSTEM_SETTING(flags,var,default) \
{flags|F_T_INT, GS(var), INT(default), NULL, NULL, UNUSED} {flags|F_T_INT, &global_status.var, INT(default), NULL, NULL, UNUSED}
#define FILENAME_SETTING(flags,var,name,default,prefix,suffix,len) \ #define FILENAME_SETTING(flags,var,name,default,prefix,suffix,len) \
{flags|F_T_UCHARPTR, GS(var), CHARPTR(default),name,NULL,\ {flags|F_T_UCHARPTR, GS(var), CHARPTR(default),name,NULL,\
@ -179,7 +179,7 @@ const struct settings_list settings[] = {
{F_T_INT,GS(battery_capacity),INT(BATTERY_CAPACITY_DEFAULT), {F_T_INT,GS(battery_capacity),INT(BATTERY_CAPACITY_DEFAULT),
"battery capacity",NULL,UNUSED}, "battery capacity",NULL,UNUSED},
#ifdef CONFIG_CHARGING #ifdef CONFIG_CHARGING
OFFON_SETTING(0,car_adapter_mode,false,"car adapter mode", NULL), OFFON_SETTING(NVRAM(1),car_adapter_mode,false,"car adapter mode", NULL),
#endif #endif
/* tuner */ /* tuner */
#ifdef CONFIG_TUNER #ifdef CONFIG_TUNER

View file

@ -61,7 +61,7 @@ struct int_setting {
}; };
#define F_NVRAM_BYTES_MASK 0xE00 /*0-4 bytes can be stored */ #define F_NVRAM_BYTES_MASK 0xE00 /*0-4 bytes can be stored */
#define F_NVRAM_MASK_SHIFT 9 #define F_NVRAM_MASK_SHIFT 9
#define NVRAM_CONFIG_VERSION 1 #define NVRAM_CONFIG_VERSION 2
/* Above define should be bumped if /* Above define should be bumped if
- a new NVRAM setting is added between 2 other NVRAM settings - a new NVRAM setting is added between 2 other NVRAM settings
- number of bytes for a NVRAM setting is changed - number of bytes for a NVRAM setting is changed

View file

@ -474,10 +474,10 @@ void reload_directory(void)
static void start_resume(bool just_powered_on) static void start_resume(bool just_powered_on)
{ {
bool do_resume = false; bool do_resume = false;
if ( global_settings.resume_index != -1 ) { if ( global_status.resume_index != -1 ) {
DEBUGF("Resume index %X offset %X\n", DEBUGF("Resume index %X offset %X\n",
global_settings.resume_index, global_status.resume_index,
global_settings.resume_offset); global_status.resume_offset);
#ifdef HAVE_ALARM_MOD #ifdef HAVE_ALARM_MOD
if ( rtc_check_alarm_started(true) ) { if ( rtc_check_alarm_started(true) ) {
@ -507,8 +507,8 @@ static void start_resume(bool just_powered_on)
if (playlist_resume() != -1) if (playlist_resume() != -1)
{ {
playlist_start(global_settings.resume_index, playlist_start(global_status.resume_index,
global_settings.resume_offset); global_status.resume_offset);
start_wps = true; start_wps = true;
} }
@ -1439,10 +1439,10 @@ void tree_flush(void)
#ifdef HAVE_DIRCACHE #ifdef HAVE_DIRCACHE
{ {
int old_val = global_settings.dircache_size; int old_val = global_status.dircache_size;
if (global_settings.dircache) if (global_settings.dircache)
{ {
global_settings.dircache_size = dircache_get_cache_size(); global_status.dircache_size = dircache_get_cache_size();
# ifdef HAVE_EEPROM_SETTINGS # ifdef HAVE_EEPROM_SETTINGS
dircache_save(); dircache_save();
# endif # endif
@ -1450,10 +1450,10 @@ void tree_flush(void)
} }
else else
{ {
global_settings.dircache_size = 0; global_status.dircache_size = 0;
} }
if (old_val != global_settings.dircache_size) if (old_val != global_status.dircache_size)
settings_save(); status_save();
} }
#endif #endif
} }
@ -1484,7 +1484,7 @@ void tree_restore(void)
gui_textarea_update(&screens[i]); gui_textarea_update(&screens[i]);
} }
dircache_build(global_settings.dircache_size); dircache_build(global_status.dircache_size);
/* Clean the text when we are done. */ /* Clean the text when we are done. */
FOR_NB_SCREENS(i) FOR_NB_SCREENS(i)