Main Page | File List | Globals

eep_lib.c

Go to the documentation of this file.
00001 /*C**************************************************************************
00002 * $RCSfile: eep_lib.c,v $
00003 *----------------------------------------------------------------------------
00004 * Copyright (c) 2003 Atmel.
00005 *----------------------------------------------------------------------------
00006 * RELEASE:      $Name:  $      
00007 * REVISION:     $Revision: 1.1 $     
00008 * FILE_CVSID:   $Id: eep_lib.c,v 1.1 2004/03/29 11:24:43 jberthy Exp $       
00009 *----------------------------------------------------------------------------
00010 * PURPOSE: 
00011 * This file contains C functions to control:
00012 * EEPROM
00013 *****************************************************************************/
00014 
00015 /*_____ I N C L U D E S ____________________________________________________*/
00016 #define _EEP_LIB_C_
00017 #include "config.h"
00018 #include "eep_drv.h"
00019 #include "eep_lib.h"
00020 
00021 /*_____ M A C R O S ________________________________________________________*/
00022 
00023 /*_____ D E F I N I T I O N S ______________________________________________*/
00024 #ifndef EEPROM_SIZE
00025 #error You must define EEPROM_SIZE in bytes in config.h
00026 #else
00027 
00028 
00029 bit eeprom_erase(void)
00030 {
00031 #if EEPROM_SIZE > 0
00032 register Uint16 addr;
00033 
00034 Enable_eeprom();
00035 addr=0;
00036 do {
00037   while (eeprom_busy());
00038   eeprom_wr(addr,EEPROM_BLANK_VALUE);
00039   } while (addr++!=(EEPROM_SIZE-1));
00040 Disable_eeprom();
00041 #endif
00042 return TRUE;
00043 }
00044 
00045 bit eeprom_wr_byte (Uint16 addr, Uchar value)
00046 {
00047 Enable_eeprom();
00048 while (eeprom_busy());
00049 eeprom_wr(addr,value);
00050 Disable_eeprom();
00051 return TRUE;
00052 } 
00053 
00054 
00055 Byte eeprom_rd_byte (Uint16 addr)
00056 {
00057 register Byte b;
00058   while (eeprom_busy());
00059 Enable_eeprom();
00060 b=eeprom_rd(addr);
00061 Disable_eeprom();
00062 return b;
00063 } 
00064 
00065 
00066 
00067 bit eeprom_rd_block (Uint16 src, Byte _MemType_* dest, Byte n)
00068 {
00069   while (eeprom_busy());
00070 Enable_eeprom();
00071 for (;n--;++src) *dest++=eeprom_rd(src);
00072 Disable_eeprom();
00073 return TRUE;
00074 }
00075 
00076 
00077 
00078 bit eeprom_wr_block (Byte _MemType_* src, Uint16 dest, Byte n)
00079 {
00080 #if EEPROM_SIZE > 0
00081 
00082 Enable_eeprom();
00083 for (;n--;)
00084   {
00085   while (eeprom_busy());
00086   eeprom_wr(dest,*src++);
00087   if (dest++==(EEPROM_SIZE-1)) break; // page not aligned on boundary EEPROM memory block
00088   } 
00089 Disable_eeprom();
00090 #endif
00091 return TRUE;
00092 }
00093 
00094 #endif
00095 

Generated on Thu Apr 1 15:49:47 2004 for Library Flash by doxygen 1.3.6