- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

# eep_lib.c

Go to the documentation of this file.

    00001 /*This file is prepared for Doxygen automatic documentation generation.*/
    00013
    00014 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
    00015  *
    00016  * Redistribution and use in source and binary forms, with or without
    00017  * modification, are permitted provided that the following conditions are met:
    00018  *
    00019  * 1. Redistributions of source code must retain the above copyright notice,
    00020  * this list of conditions and the following disclaimer.
    00021  *
    00022  * 2. Redistributions in binary form must reproduce the above copyright notice,
    00023  * this list of conditions and the following disclaimer in the documentation
    00024  * and/or other materials provided with the distribution.
    00025  *
    00026  * 3. The name of Atmel may not be used to endorse or promote products derived
    00027  * from this software without specific prior written permission.
    00028  *
    00029  * 4. This software may only be redistributed and used in connection with an Atmel
    00030  * AVR product.
    00031  *
    00032  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
    00033  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    00034  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE EXPRESSLY AND
    00035  * SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
    00036  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
    00037  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
    00038  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00039  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    00040  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
    00041  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    00042  */
    00043
    00044 /*_____ I N C L U D E S ____________________________________________________*/
    00045 #define _EEP_LIB_C_
    00046 #include "config.h"
    00047 #include "eep_drv.h"
    00048 #include "eep_lib.h"
    00049
    00050 /*_____ M A C R O S ________________________________________________________*/
    00051
    00052 /*_____ D E F I N I T I O N S ______________________________________________*/
    00053 #ifndef EEPROM_SIZE
    00054 #error You must define EEPROM_SIZE in bytes in config.h
    00055 #else
    00056
    00057
    00058 bit eeprom_erase(void)
    00059 {
    00060 #if EEPROM_SIZE > 0
    00061 register Uint16 addr;
    00062
    00063 Enable_eeprom();
    00064 addr=0;
    00065 do {
    00066   while (eeprom_busy());
    00067   eeprom_wr(addr,EEPROM_BLANK_VALUE);
    00068   } while (addr++!=(EEPROM_SIZE-1));
    00069 Disable_eeprom();
    00070 #endif
    00071 return TRUE;
    00072 }
    00073
    00074 bit eeprom_wr_byte (Uint16 addr, Uchar value)
    00075 {
    00076 Enable_eeprom();
    00077 while (eeprom_busy());
    00078 eeprom_wr(addr,value);
    00079 Disable_eeprom();
    00080 return TRUE;
    00081 }
    00082
    00083
    00084 Byte eeprom_rd_byte (Uint16 addr)
    00085 {
    00086 register Byte b;
    00087   while (eeprom_busy());
    00088 Enable_eeprom();
    00089 b=eeprom_rd(addr);
    00090 Disable_eeprom();
    00091 return b;
    00092 }
    00093
    00094
    00095
    00096 bit eeprom_rd_block (Uint16 src, Byte _MemType_* dest, Byte n)
    00097 {
    00098   while (eeprom_busy());
    00099 Enable_eeprom();
    00100 for (;n--;++src) *dest++=eeprom_rd(src);
    00101 Disable_eeprom();
    00102 return TRUE;
    00103 }
    00104
    00105
    00106
    00107 bit eeprom_wr_block (Byte _MemType_* src, Uint16 dest, U16 n)
    00108 {
    00109 #if EEPROM_SIZE > 0
    00110
    00111 Enable_eeprom();
    00112 for (;n--;)
    00113   {
    00114   while (eeprom_busy());
    00115   eeprom_wr(dest,*src++);
    00116   if (dest++==(EEPROM_SIZE-1)) break; // page not aligned on boundary EEPROM memory block
    00117   }
    00118 Disable_eeprom();
    00119 #endif
    00120 return TRUE;
    00121 }
    00122
    00123 #endif
    00124