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 "global.h"
00016 
00017 #include "i2ceeprom.h"
00018 
00019 void eeprom_read_block(u08* data, u08* memaddr, u16 sizebytes)
00020 {
00021     int i;
00022 
00023     for(i=0; i<sizebytes; i++)
00024     {
00025         *data++ = i2ceepromReadByte(0xA0, (u32)memaddr++);
00026     }
00027 }
00028 
00029 void eeprom_write_block(u08* data, u08* memaddr, u16 sizebytes)
00030 {
00031     int i;
00032 
00033     for(i=0; i<sizebytes; i++)
00034     {
00035         i2ceepromWriteByte(0xA0, (u32)memaddr++, *data++);
00036     }
00037 }
00038 
00039 u08 paramLoad(u08* parameters, u08* memaddr, u16 sizebytes)
00040 {
00041     u16 i;
00042     u08 checksum_stored=0;
00043     u08 checksum=0;
00044 
00045     // load parameters
00046     eeprom_read_block(parameters, memaddr, sizebytes);
00047     // load checksum
00048     eeprom_read_block(&checksum_stored, memaddr+sizebytes, sizeof(u08));
00049 
00050     // calculate own checksum
00051     for(i=0;i<sizebytes;i++)
00052         checksum += parameters[i];
00053     checksum = ~checksum;
00054     
00055     if(checksum == checksum_stored)
00056         return TRUE;
00057     else
00058         return FALSE;
00059 }
00060 
00061 void paramStore(u08* parameters, u08* memaddr, u16 sizebytes)
00062 {
00063     u16 i;
00064     u08 checksum=0;
00065 
00066     // calculate checksum
00067     for(i=0;i<sizebytes;i++)
00068         checksum += parameters[i];
00069     checksum = ~checksum;
00070 
00071     // store parameters
00072     eeprom_write_block(parameters, memaddr, sizebytes);
00073     // store checksum
00074     eeprom_write_block(&checksum, memaddr+sizebytes, sizeof(u08));
00075 }
00076 

Generated on Mon Nov 6 23:36:59 2006 for Procyon ARMlib by  doxygen 1.4.2