Main Page | Modules | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

param.c

Go to the documentation of this file.
00001 /*! \file param.c \brief EEPROM Parameter Storage Library. */
00002 //*****************************************************************************
00003 //
00004 // File Name    : 'param.c'
00005 // Title        : EEPROM Parameter Storage Library
00006 // Author       : Pascal Stang (c)2005
00007 // Created      : 9/16/2005
00008 // Revised      : 9/20/2005
00009 // Version      : 0.1
00010 // Target MCU   : Atmel AVR series
00011 // Editor Tabs  : 4
00012 //
00013 //*****************************************************************************
00014 
00015 #include <avr/eeprom.h>
00016 
00017 #include "global.h"
00018 
00019 u08 paramLoad(u08* parameters, u08* memaddr, u16 sizebytes)
00020 {
00021     u16 i;
00022     u08 checksum_stored=0;
00023     u08 checksum=0;
00024 
00025     // load parameters
00026     eeprom_read_block(parameters, memaddr, sizebytes);
00027     // load checksum
00028     eeprom_read_block(&checksum_stored, memaddr+sizebytes, sizeof(u08));
00029 
00030     // calculate own checksum
00031     for(i=0;i<sizebytes;i++)
00032         checksum += parameters[i];
00033     checksum = ~checksum;
00034     
00035     if(checksum == checksum_stored)
00036         return TRUE;
00037     else
00038         return FALSE;
00039 }
00040 
00041 void paramStore(u08* parameters, u08* memaddr, u16 sizebytes)
00042 {
00043     u16 i;
00044     u08 checksum=0;
00045 
00046     // calculate checksum
00047     for(i=0;i<sizebytes;i++)
00048         checksum += parameters[i];
00049     checksum = ~checksum;
00050 
00051     // store parameters
00052     eeprom_write_block(parameters, memaddr, sizebytes);
00053     // store checksum
00054     eeprom_write_block(&checksum, memaddr+sizebytes, sizeof(u08));
00055 }
00056 

Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by  doxygen 1.4.2