Line No. | Rev | Author | Line |
---|---|---|---|
1 | 6 | kaklik | /*! \file param.c \brief EEPROM Parameter Storage Library. */ |
2 | //***************************************************************************** |
||
3 | // |
||
4 | // File Name : 'param.c' |
||
5 | // Title : EEPROM Parameter Storage Library |
||
6 | // Author : Pascal Stang (c)2005 |
||
7 | // Created : 9/16/2005 |
||
8 | // Revised : 9/20/2005 |
||
9 | // Version : 0.1 |
||
10 | // Target MCU : Atmel AVR series |
||
11 | // Editor Tabs : 4 |
||
12 | // |
||
13 | //***************************************************************************** |
||
14 | |||
15 | #include <avr/eeprom.h> |
||
16 | |||
17 | #include "global.h" |
||
18 | |||
19 | u08 paramLoad(u08* parameters, u08* memaddr, u16 sizebytes) |
||
20 | { |
||
21 | u16 i; |
||
22 | u08 checksum_stored=0; |
||
23 | u08 checksum=0; |
||
24 | |||
25 | // load parameters |
||
26 | eeprom_read_block(parameters, memaddr, sizebytes); |
||
27 | // load checksum |
||
28 | eeprom_read_block(&checksum_stored, memaddr+sizebytes, sizeof(u08)); |
||
29 | |||
30 | // calculate own checksum |
||
31 | for(i=0;i<sizebytes;i++) |
||
32 | checksum += parameters[i]; |
||
33 | checksum = ~checksum; |
||
34 | |||
35 | if(checksum == checksum_stored) |
||
36 | return TRUE; |
||
37 | else |
||
38 | return FALSE; |
||
39 | } |
||
40 | |||
41 | void paramStore(u08* parameters, u08* memaddr, u16 sizebytes) |
||
42 | { |
||
43 | u16 i; |
||
44 | u08 checksum=0; |
||
45 | |||
46 | // calculate checksum |
||
47 | for(i=0;i<sizebytes;i++) |
||
48 | checksum += parameters[i]; |
||
49 | checksum = ~checksum; |
||
50 | |||
51 | // store parameters |
||
52 | eeprom_write_block(parameters, memaddr, sizebytes); |
||
53 | // store checksum |
||
54 | eeprom_write_block(&checksum, memaddr+sizebytes, sizeof(u08)); |
||
55 | } |
||
56 |
Powered by WebSVN v2.8.3