summaryrefslogtreecommitdiff
path: root/apps/settings.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/settings.c')
-rw-r--r--apps/settings.c39
1 files changed, 2 insertions, 37 deletions
diff --git a/apps/settings.c b/apps/settings.c
index f89fc581ca..3f257e093a 100644
--- a/apps/settings.c
+++ b/apps/settings.c
@@ -83,11 +83,7 @@ struct system_status global_status;
83#include "pcm_sampr.h" 83#include "pcm_sampr.h"
84 84
85#define NVRAM_DATA_START 8 85#define NVRAM_DATA_START 8
86#ifdef HAVE_RTC_RAM
87#define NVRAM_BLOCK_SIZE 44
88#else
89#define NVRAM_BLOCK_SIZE (sizeof(struct system_status) + NVRAM_DATA_START) 86#define NVRAM_BLOCK_SIZE (sizeof(struct system_status) + NVRAM_DATA_START)
90#endif
91 87
92#define MAX_LINES 10 88#define MAX_LINES 10
93 89
@@ -118,7 +114,6 @@ static bool read_nvram_data(char* buf, int max_len)
118{ 114{
119 unsigned crc32 = 0xffffffff; 115 unsigned crc32 = 0xffffffff;
120 int var_count = 0, i = 0, buf_pos = 0; 116 int var_count = 0, i = 0, buf_pos = 0;
121#ifndef HAVE_RTC_RAM
122 int fd = open(NVRAM_FILE, O_RDONLY); 117 int fd = open(NVRAM_FILE, O_RDONLY);
123 int bytes; 118 int bytes;
124 if (fd < 0) 119 if (fd < 0)
@@ -128,12 +123,6 @@ static bool read_nvram_data(char* buf, int max_len)
128 close(fd); 123 close(fd);
129 if (bytes < 8) /* min is 8 bytes,magic, ver, vars, crc32 */ 124 if (bytes < 8) /* min is 8 bytes,magic, ver, vars, crc32 */
130 return false; 125 return false;
131#else
132 memset(buf,0,max_len);
133 /* read rtc block */
134 for (i=0; i < max_len; i++ )
135 buf[i] = rtc_read(0x14+i);
136#endif
137 /* check magic, version */ 126 /* check magic, version */
138 if ((buf[0] != 'R') || (buf[1] != 'b') 127 if ((buf[0] != 'R') || (buf[1] != 'b')
139 || (buf[2] != NVRAM_CONFIG_VERSION)) 128 || (buf[2] != NVRAM_CONFIG_VERSION))
@@ -171,9 +160,7 @@ static bool write_nvram_data(char* buf, int max_len)
171 unsigned crc32 = 0xffffffff; 160 unsigned crc32 = 0xffffffff;
172 int i = 0, buf_pos = 0; 161 int i = 0, buf_pos = 0;
173 char var_count = 0; 162 char var_count = 0;
174#ifndef HAVE_RTC_RAM
175 int fd; 163 int fd;
176#endif
177 memset(buf,0,max_len); 164 memset(buf,0,max_len);
178 /* magic, version */ 165 /* magic, version */
179 buf[0] = 'R'; buf[1] = 'b'; 166 buf[0] = 'R'; buf[1] = 'b';
@@ -195,7 +182,6 @@ static bool write_nvram_data(char* buf, int max_len)
195 crc32 = crc_32(&buf[NVRAM_DATA_START], 182 crc32 = crc_32(&buf[NVRAM_DATA_START],
196 max_len-NVRAM_DATA_START-1,0xffffffff); 183 max_len-NVRAM_DATA_START-1,0xffffffff);
197 memcpy(&buf[4],&crc32,4); 184 memcpy(&buf[4],&crc32,4);
198#ifndef HAVE_RTC_RAM
199 fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY, 0666); 185 fd = open(NVRAM_FILE,O_CREAT|O_TRUNC|O_WRONLY, 0666);
200 if (fd >= 0) 186 if (fd >= 0)
201 { 187 {
@@ -204,16 +190,6 @@ static bool write_nvram_data(char* buf, int max_len)
204 if (len < 8) 190 if (len < 8)
205 return false; 191 return false;
206 } 192 }
207#else
208 /* FIXME: okay, it _would_ be cleaner and faster to implement rtc_write so
209 that it would write a number of bytes at a time since the RTC chip
210 supports that, but this will have to do for now 8-) */
211 for (i=0; i < NVRAM_BLOCK_SIZE; i++ ) {
212 int r = rtc_write(0x14+i, buf[i]);
213 if (r)
214 return false;
215 }
216#endif
217 return true; 193 return true;
218} 194}
219 195
@@ -586,12 +562,12 @@ static bool settings_write_config(const char* filename, int options)
586 close(fd); 562 close(fd);
587 return true; 563 return true;
588} 564}
589#ifndef HAVE_RTC_RAM 565
590static void flush_global_status_callback(void) 566static void flush_global_status_callback(void)
591{ 567{
592 write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); 568 write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
593} 569}
594#endif 570
595static void flush_config_block_callback(void) 571static void flush_config_block_callback(void)
596{ 572{
597 write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE); 573 write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
@@ -621,23 +597,12 @@ static void update_runtime(void)
621void status_save(void) 597void status_save(void)
622{ 598{
623 update_runtime(); 599 update_runtime();
624#ifdef HAVE_RTC_RAM
625 /* this will be done in the storage_callback if
626 target doesnt have rtc ram */
627 write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
628#else
629 register_storage_idle_func(flush_global_status_callback); 600 register_storage_idle_func(flush_global_status_callback);
630#endif
631} 601}
632 602
633int settings_save(void) 603int settings_save(void)
634{ 604{
635 update_runtime(); 605 update_runtime();
636#ifdef HAVE_RTC_RAM
637 /* this will be done in the storage_callback if
638 target doesnt have rtc ram */
639 write_nvram_data(nvram_buffer,NVRAM_BLOCK_SIZE);
640#endif
641 register_storage_idle_func(flush_config_block_callback); 606 register_storage_idle_func(flush_config_block_callback);
642 return 0; 607 return 0;
643} 608}