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