diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 22db43d272..c5240d0de8 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c @@ -1830,7 +1830,7 @@ static bool dbg_dircache_info(void) lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "Last size: %d B", - global_settings.dircache_size); + global_status.dircache_size); lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "Limit: %d B", DIRCACHE_LIMIT); diff --git a/apps/filetree.c b/apps/filetree.c index cd020d0a51..10174dbb31 100644 --- a/apps/filetree.c +++ b/apps/filetree.c @@ -572,9 +572,9 @@ int ft_enter(struct tree_context* c) if ( play ) { /* the resume_index must always be the index in the shuffled list in case shuffle is enabled */ - global_settings.resume_index = start_index; - global_settings.resume_offset = 0; - settings_save(); + global_status.resume_index = start_index; + global_status.resume_offset = 0; + status_save(); start_wps = true; } diff --git a/apps/gui/gwps-common.c b/apps/gui/gwps-common.c index f2aa497703..41edc0002b 100644 --- a/apps/gui/gwps-common.c +++ b/apps/gui/gwps-common.c @@ -2483,7 +2483,7 @@ bool gui_wps_display(void) int i; if (!wps_state.id3 && !(audio_status() & AUDIO_STATUS_PLAY)) { - global_settings.resume_index = -1; + global_status.resume_index = -1; #ifdef HAVE_LCD_CHARCELLS gui_syncsplash(HZ, true, str(LANG_END_PLAYLIST_PLAYER)); #else diff --git a/apps/main.c b/apps/main.c index 5137ff9fa6..dac7ac755d 100644 --- a/apps/main.c +++ b/apps/main.c @@ -140,7 +140,7 @@ static int init_dircache(bool preinit) if (result < 0) { 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 applied yet. Not really any easy way to fix that. */ @@ -148,7 +148,7 @@ static int init_dircache(bool preinit) clear = true; } - dircache_build(global_settings.dircache_size); + dircache_build(global_status.dircache_size); } } else @@ -160,12 +160,12 @@ static int init_dircache(bool preinit) if (!dircache_is_enabled() && !dircache_is_initializing()) { - if (global_settings.dircache_size <= 0) + if (global_status.dircache_size <= 0) { gui_syncsplash(0, true, str(LANG_DIRCACHE_BUILDING)); clear = true; } - result = dircache_build(global_settings.dircache_size); + result = dircache_build(global_status.dircache_size); } if (result < 0) @@ -176,8 +176,8 @@ static int init_dircache(bool preinit) { backlight_on(); show_logo(); - global_settings.dircache_size = dircache_get_cache_size(); - settings_save(); + global_status.dircache_size = dircache_get_cache_size(); + status_save(); } return result; diff --git a/apps/playlist.c b/apps/playlist.c index 2928db8a4f..56ffccc474 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -243,8 +243,8 @@ static void empty_playlist(struct playlist_info* playlist, bool resume) create_control(playlist); /* Reset resume settings */ - global_settings.resume_first_index = 0; - global_settings.resume_seed = -1; + global_status.resume_first_index = 0; + global_status.resume_seed = -1; } } @@ -386,8 +386,8 @@ static int recreate_control(struct playlist_info* playlist) if (playlist->current) { - global_settings.resume_seed = -1; - settings_save(); + global_status.resume_seed = -1; + status_save(); } for (i=0; iamount; i++) @@ -710,8 +710,8 @@ static int add_track_to_playlist(struct playlist_info* playlist, if (seek_pos < 0 && playlist->current) { - global_settings.resume_first_index = playlist->first_index; - settings_save(); + global_status.resume_first_index = playlist->first_index; + status_save(); } } @@ -826,8 +826,8 @@ static int remove_track_from_playlist(struct playlist_info* playlist, if (write) { - global_settings.resume_first_index = playlist->first_index; - settings_save(); + global_status.resume_first_index = playlist->first_index; + status_save(); } } @@ -902,8 +902,8 @@ static int randomise_playlist(struct playlist_info* playlist, { update_control(playlist, PLAYLIST_COMMAND_SHUFFLE, seed, playlist->first_index, NULL, NULL, NULL); - global_settings.resume_seed = seed; - settings_save(); + global_status.resume_seed = seed; + status_save(); } return 0; @@ -942,8 +942,8 @@ static int sort_playlist(struct playlist_info* playlist, bool start_current, { update_control(playlist, PLAYLIST_COMMAND_UNSHUFFLE, playlist->first_index, -1, NULL, NULL, NULL); - global_settings.resume_seed = 0; - settings_save(); + global_status.resume_seed = 0; + status_save(); } return 0; @@ -1117,8 +1117,8 @@ static void find_and_set_playlist_index(struct playlist_info* playlist, if (playlist->current) { - global_settings.resume_first_index = i; - settings_save(); + global_status.resume_first_index = i; + status_save(); } break; @@ -1742,10 +1742,10 @@ static int flush_cached_control(struct playlist_info* playlist) if (result > 0) { - if (global_settings.resume_seed >= 0) + if (global_status.resume_seed >= 0) { - global_settings.resume_seed = -1; - settings_save(); + global_status.resume_seed = -1; + status_save(); } playlist->num_cached = 0; @@ -2294,22 +2294,22 @@ int playlist_resume(void) /* Terminate on EOF */ if(nread <= 0) { - if (global_settings.resume_seed >= 0) + if (global_status.resume_seed >= 0) { /* Apply shuffle command saved in settings */ - if (global_settings.resume_seed == 0) + if (global_status.resume_seed == 0) sort_playlist(playlist, false, true); else { if (!sorted) sort_playlist(playlist, false, false); - randomise_playlist(playlist, global_settings.resume_seed, + randomise_playlist(playlist, global_status.resume_seed, false, true); } } - playlist->first_index = global_settings.resume_first_index; + playlist->first_index = global_status.resume_first_index; break; } } @@ -2361,7 +2361,7 @@ int playlist_shuffle(int random_seed, int start_index) { /* store the seek position before the shuffle */ 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; start_current = true; } @@ -2508,7 +2508,7 @@ int playlist_next(int steps) playlist->amount > 1) { /* 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); randomise_playlist(playlist, current_tick, false, true); #if CONFIG_CODEC != SWCODEC @@ -2651,19 +2651,19 @@ int playlist_update_resume_info(const struct mp3entry* id3) if (id3) { - if (global_settings.resume_index != playlist->index || - global_settings.resume_offset != id3->offset) + if (global_status.resume_index != playlist->index || + global_status.resume_offset != id3->offset) { - global_settings.resume_index = playlist->index; - global_settings.resume_offset = id3->offset; - settings_save(); + global_status.resume_index = playlist->index; + global_status.resume_offset = id3->offset; + status_save(); } } else { - global_settings.resume_index = -1; - global_settings.resume_offset = -1; - settings_save(); + global_status.resume_index = -1; + global_status.resume_offset = -1; + status_save(); } return 0; diff --git a/apps/plugin.h b/apps/plugin.h index 64cc208aae..70b5ebf354 100644 --- a/apps/plugin.h +++ b/apps/plugin.h @@ -110,12 +110,12 @@ #define PLUGIN_MAGIC 0x526F634B /* RocK */ /* 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 backwards compatibility (and please take the opportunity to sort in any 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 */ enum plugin_status { diff --git a/apps/recorder/radio.c b/apps/recorder/radio.c index 2fba14f7e2..45ddd3e0ad 100644 --- a/apps/recorder/radio.c +++ b/apps/recorder/radio.c @@ -212,7 +212,7 @@ void radio_start(void) if(radio_status == FMRADIO_OFF) 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_min; @@ -332,10 +332,10 @@ static int find_closest_preset(int freq) 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_step; - settings_save(); + status_save(); } static void next_preset(int direction) diff --git a/apps/screens.c b/apps/screens.c index ab4c5dab60..4cf56b8192 100644 --- a/apps/screens.c +++ b/apps/screens.c @@ -1337,21 +1337,21 @@ bool view_runtime(void) #endif ) { - global_settings.runtime = 0; + global_status.runtime = 0; } else #endif { - global_settings.runtime += ((current_tick - lasttime) / HZ); + global_status.runtime += ((current_tick - lasttime) / HZ); } lasttime = current_tick; - t = global_settings.runtime; + t = global_status.runtime; FOR_NB_SCREENS(i) screens[i].puts(0, y[i]++, str(LANG_CURRENT_TIME)); } else { - t = global_settings.topruntime; + t = global_status.topruntime; FOR_NB_SCREENS(i) 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 ( state == 1 ) - global_settings.runtime = 0; + global_status.runtime = 0; else - global_settings.topruntime = 0; + global_status.topruntime = 0; } break; default: diff --git a/apps/settings.c b/apps/settings.c index 1a7d159666..4280ff9f7a 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -86,6 +86,7 @@ void dac_line_in(bool enable); #endif struct user_settings global_settings; +struct system_status global_status; #ifdef HAVE_RECORDING const char rec_base_directory[] = REC_BASE_DIR; #endif @@ -346,6 +347,12 @@ bool settings_write_config(char* filename) close(fd); 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) { bool r1, r2; @@ -357,16 +364,33 @@ static bool flush_config_block_callback(void) /* * persist all runtime user settings to disk or RTC RAM */ -int settings_save( void ) +static void update_runtime(void) { int elapsed_secs; elapsed_secs = (current_tick - lasttime) / HZ; - global_settings.runtime += elapsed_secs; + global_status.runtime += elapsed_secs; lasttime += (elapsed_secs * HZ); - if ( global_settings.runtime > global_settings.topruntime ) - global_settings.topruntime = global_settings.runtime; + if ( global_status.runtime > global_status.topruntime ) + 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 /* this will be done in the ata_callback if target doesnt have rtc ram */ diff --git a/apps/settings.h b/apps/settings.h index 3ff3fe6244..8a495a0fee 100644 --- a/apps/settings.h +++ b/apps/settings.h @@ -128,7 +128,23 @@ extern unsigned char vp_dummy[VIRT_SIZE]; #if !defined(HAVE_LCD_COLOR) #define HAVE_LCD_CONTRAST #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 { /* audio settings */ @@ -254,11 +270,6 @@ struct user_settings /* resume settings */ 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 unsigned char fmr_file[MAX_FILENAME+1]; /* last fmr preset */ @@ -304,8 +315,6 @@ struct user_settings bool browse_current; /* 1=goto current song, 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 bidir_limit; /* bidir scroll length limit */ @@ -339,8 +348,6 @@ struct user_settings bool fm_force_mono; /* Forces Mono mode if true */ bool fm_full_range; /* Enables full 10MHz-160MHz range if true, else only 88MHz-108MHz */ - int last_frequency; /* Last frequency for resuming, in FREQ_STEP units, - relative to MIN_FREQ */ #endif int max_files_in_dir; /* Max entries in directory (file browser) */ @@ -406,7 +413,6 @@ struct user_settings #endif #ifdef HAVE_DIRCACHE bool dircache; /* enable directory cache */ - int dircache_size; /* directory cache structure last size, 22 bits */ #endif #ifdef HAVE_TAGCACHE #ifdef HAVE_TC_RAMCACHE @@ -548,7 +554,7 @@ struct opt_items { }; /* prototypes */ - +void status_save( void ); int settings_save(void); void settings_load(int which); void settings_reset(void); @@ -581,6 +587,8 @@ void settings_apply_trigger(void); /* 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 * files are stored */ extern long lasttime; diff --git a/apps/settings_list.c b/apps/settings_list.c index bffee257d1..861c3df6ff 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c @@ -104,7 +104,7 @@ static const char backlight_times_conf [] = {{cb,LANG_SET_BOOL_YES,LANG_SET_BOOL_NO}}} } #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) \ {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), "battery capacity",NULL,UNUSED}, #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 /* tuner */ #ifdef CONFIG_TUNER diff --git a/apps/settings_list.h b/apps/settings_list.h index 01e8cea1e7..d76d10aea1 100644 --- a/apps/settings_list.h +++ b/apps/settings_list.h @@ -61,7 +61,7 @@ struct int_setting { }; #define F_NVRAM_BYTES_MASK 0xE00 /*0-4 bytes can be stored */ #define F_NVRAM_MASK_SHIFT 9 -#define NVRAM_CONFIG_VERSION 1 +#define NVRAM_CONFIG_VERSION 2 /* Above define should be bumped if - a new NVRAM setting is added between 2 other NVRAM settings - number of bytes for a NVRAM setting is changed diff --git a/apps/tree.c b/apps/tree.c index e9ac6b5aa7..edd238a3b0 100644 --- a/apps/tree.c +++ b/apps/tree.c @@ -474,10 +474,10 @@ void reload_directory(void) static void start_resume(bool just_powered_on) { bool do_resume = false; - if ( global_settings.resume_index != -1 ) { + if ( global_status.resume_index != -1 ) { DEBUGF("Resume index %X offset %X\n", - global_settings.resume_index, - global_settings.resume_offset); + global_status.resume_index, + global_status.resume_offset); #ifdef HAVE_ALARM_MOD if ( rtc_check_alarm_started(true) ) { @@ -507,8 +507,8 @@ static void start_resume(bool just_powered_on) if (playlist_resume() != -1) { - playlist_start(global_settings.resume_index, - global_settings.resume_offset); + playlist_start(global_status.resume_index, + global_status.resume_offset); start_wps = true; } @@ -1439,10 +1439,10 @@ void tree_flush(void) #ifdef HAVE_DIRCACHE { - int old_val = global_settings.dircache_size; + int old_val = global_status.dircache_size; if (global_settings.dircache) { - global_settings.dircache_size = dircache_get_cache_size(); + global_status.dircache_size = dircache_get_cache_size(); # ifdef HAVE_EEPROM_SETTINGS dircache_save(); # endif @@ -1450,10 +1450,10 @@ void tree_flush(void) } else { - global_settings.dircache_size = 0; + global_status.dircache_size = 0; } - if (old_val != global_settings.dircache_size) - settings_save(); + if (old_val != global_status.dircache_size) + status_save(); } #endif } @@ -1484,7 +1484,7 @@ void tree_restore(void) gui_textarea_update(&screens[i]); } - dircache_build(global_settings.dircache_size); + dircache_build(global_status.dircache_size); /* Clean the text when we are done. */ FOR_NB_SCREENS(i)