4 * Copyright (C) 2013-06-10 K.Ohta <whatisthis.sowhat ai gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
11 * This library / program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 * See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this library; see the file COPYING. If not, write to the
18 * Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
21 * As a special exception, if you link this(includeed from sdcc) library
22 * with other files, some of which are compiled with SDCC,
23 * to produce an executable, this library does not by itself cause
24 * the resulting executable to be covered by the GNU General Public License.
25 * This exception does not however invalidate any other reasons why
26 * the executable file might be covered by the GNU General Public License.
29 #include "eeprom_util.h"
31 void save_eeprom(void)
37 unsigned char *q = (char *)(&setup);
42 writeword_eeprom(p, sum, 0x1298);
44 for(i = 0; i < sizeof(__radioset_t); i++) {
45 writebyte_eeprom(p, sum, *q);
50 eeprom_writebyte(*p, sum[0] >> 8);
51 eeprom_writebyte(*p + 1, sum[0] & 0xff);
54 unsigned char load_eeprom(void)
59 unsigned char *q = (unsigned char *)(&setup);
66 magic = readword_eeprom(&p, &sum);
67 if(magic != 0x1298) return 0x01; // NO MAGICWORD
69 for(i = 0; i < sizeof(__radioset_t); i++ ){
70 *q = readbyte_eeprom(&p, &sum);
73 magic = (eeprom_readbyte(p) << 8) + eeprom_readbyte(p + 1);
75 if(sum != magic) return 0x00;
80 * Check eeprom, and format/restore.
82 static void check_eeprom_sub(void)
86 printstr("Formatting... ");
89 printstr("Save defaults ");
94 void check_eeprom(void)
98 switch(load_eeprom()) {
99 case 0x01: // No magic-word
101 c = printhelp_2lines("EEPROM FORMAT", "Press any key");
104 case 0x00: // Checksum error
106 c = printhelp_2lines("X-) Sum error", "Press any key");
109 case 0xff: // Success
112 default: // Unknown error