AVR Libc Home Page | AVR Libc Development Pages | |||
Main Page | User Manual | Reference | FAQ | Example Projects |
01 1 Copyright (c) 2002, 2003, 2004, 2007 Marek Michalkiewicz 022Copyright (c) 2005, 2006 Bjoern Haase 033Copyright (c) 2008 Atmel Corporation 044Copyright (c) 2008 Wouter van Gulik 055Copyright (c) 2009 Dmitry Xmelkov 066All rights reserved. 077 088Redistribution and use in source and binary forms, with or without 099modification, are permitted provided that the following conditions are met: 1010 1111* Redistributions of source code must retain the above copyright 1212notice, this list of conditions and the following disclaimer. 1313* Redistributions in binary form must reproduce the above copyright 1414notice, this list of conditions and the following disclaimer in 1515the documentation and/or other materials provided with the 1616distribution. 1717* Neither the name of the copyright holders nor the names of 1818contributors may be used to endorse or promote products derived 1919from this software without specific prior written permission. 2020 2121THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 2222AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2323IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2424ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 2525LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 2626CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 2727SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 2828INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 2929CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 3030ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 3131POSSIBILITY OF SUCH DAMAGE. */ 3232 3333/* $Id: eeprom.h 2468 2015-02-25 12:53:38Z pitchumani $ */ 3434 3535#ifndef _AVR_EEPROM_H_ 3636#define _AVR_EEPROM_H_ 1 3737 3838#include <avr/io.h> 3939 4040#if !E2END && !defined(__DOXYGEN__) && !defined(__COMPILING_AVR_LIBC__) 4141# warning "Device does not have EEPROM available." 4242#else 4343 4444#if defined (EEAR) && !defined (EEARL) && !defined (EEARH) 4545#define EEARL EEAR 4646#endif 4747 4848#ifndef __ASSEMBLER__ 4949 5050#include <stddef.h> /* size_t */ 5151#include <stdint.h> 5252 5353/** \defgroup avr_eeprom <avr/eeprom.h>: EEPROM handling 5454\code #include <avr/eeprom.h> \endcode 5555 5656This header file declares the interface to some simple library 5757routines suitable for handling the data EEPROM contained in the 5858AVR microcontrollers. The implementation uses a simple polled 5959mode interface. Applications that require interrupt-controlled 6060EEPROM access to ensure that no time will be wasted in spinloops 6161will have to deploy their own implementation. 6262 6363\par Notes: 6464 6565- In addition to the write functions there is a set of update ones. 6666This functions read each byte first and skip the burning if the 6767old value is the same with new. The scaning direction is from 6868high address to low, to obtain quick return in common cases. 6969 7070- All of the read/write functions first make sure the EEPROM is 7171ready to be accessed. Since this may cause long delays if a 7272write operation is still pending, time-critical applications 7373should first poll the EEPROM e. g. using eeprom_is_ready() before 7474attempting any actual I/O. But this functions are not wait until 7575SELFPRGEN in SPMCSR becomes zero. Do this manually, if your 7676softwate contains the Flash burning. 7777 7878- As these functions modify IO registers, they are known to be 7979non-reentrant. If any of these functions are used from both, 8080standard and interrupt context, the applications must ensure 8181proper protection (e.g. by disabling interrupts before accessing 8282them). 8383 8484- All write functions force erase_and_write programming mode. 85858686- For Xmega the EEPROM start address is 0, like other architectures. 8787The reading functions add the 0x2000 value to use EEPROM mapping into 8888data space. 8989*/ 9090 9191#ifdef __cplusplus 9292extern "C" { 9393#endif 9494 9595#ifndef __ATTR_PURE__ 9696# ifdef __DOXYGEN__ 9797# define __ATTR_PURE__ 9898# else 9999# define __ATTR_PURE__ __attribute__((__pure__)) 100100# endif 101101#endif 102102 103103/** \def EEMEM 104104\ingroup avr_eeprom 105105Attribute expression causing a variable to be allocated within the 106106.eeprom section. */ 107 107#define EEMEM __attribute__((section(".eeprom"))) 108108 109109/** \def eeprom_is_ready 110110\ingroup avr_eeprom 111111\returns 1 if EEPROM is ready for a new read/write operation, 0 if not. 112112*/ 113113#if defined (__DOXYGEN__) 114 114# define eeprom_is_ready() 115115#elif defined (__AVR_XMEGA__) && __AVR_XMEGA__ 116116# define eeprom_is_ready() bit_is_clear (NVM_STATUS, NVM_NVMBUSY_bp) 117117#elif defined (DEECR) 118118# define eeprom_is_ready() bit_is_clear (DEECR, BSY) 119119#elif defined (EEPE) 120120# define eeprom_is_ready() bit_is_clear (EECR, EEPE) 121121#else 122122# define eeprom_is_ready() bit_is_clear (EECR, EEWE) 123123#endif 124124 125125 126126/** \def eeprom_busy_wait 127127\ingroup avr_eeprom 128128Loops until the eeprom is no longer busy. 129129\returns Nothing. 130130*/ 131 131#define eeprom_busy_wait() do {} while (!eeprom_is_ready()) 132132 133133 134134/** \ingroup avr_eeprom 135135Read one byte from EEPROM address \a __p. 136136*/ 137137uint8_t eeprom_read_byte (const uint8_t *__p) __ATTR_PURE__; 138138 139139/** \ingroup avr_eeprom 140140Read one 16-bit word (little endian) from EEPROM address \a __p. 141141*/ 142142uint16_t eeprom_read_word (const uint16_t *__p) __ATTR_PURE__; 143143 144144/** \ingroup avr_eeprom 145145Read one 32-bit double word (little endian) from EEPROM address \a __p. 146146*/ 147147uint32_t eeprom_read_dword (const uint32_t *__p) __ATTR_PURE__; 148148 149149/** \ingroup avr_eeprom 150150Read one float value (little endian) from EEPROM address \a __p. 151151*/ 152152float eeprom_read_float (const float *__p) __ATTR_PURE__; 153153 154154/** \ingroup avr_eeprom 155155Read a block of \a __n bytes from EEPROM address \a __src to SRAM 156156\a __dst. 157157*/ 158158void eeprom_read_block (void *__dst, const void *__src, size_t __n); 159159 160160 161161/** \ingroup avr_eeprom 162162Write a byte \a __value to EEPROM address \a __p. 163163*/ 164164void eeprom_write_byte (uint8_t *__p, uint8_t __value); 165165 166166/** \ingroup avr_eeprom 167167Write a word \a __value to EEPROM address \a __p. 168168*/ 169169void eeprom_write_word (uint16_t *__p, uint16_t __value); 170170 171171/** \ingroup avr_eeprom 172172Write a 32-bit double word \a __value to EEPROM address \a __p. 173173*/ 174174void eeprom_write_dword (uint32_t *__p, uint32_t __value); 175175 176176/** \ingroup avr_eeprom 177177Write a float \a __value to EEPROM address \a __p. 178178*/ 179179void eeprom_write_float (float *__p, float __value); 180180 181181/** \ingroup avr_eeprom 182182Write a block of \a __n bytes to EEPROM address \a __dst from \a __src. 183183\note The argument order is mismatch with common functions like strcpy(). 184184*/ 185185void eeprom_write_block (const void *__src, void *__dst, size_t __n); 186186 187187 188188/** \ingroup avr_eeprom 189189Update a byte \a __value to EEPROM address \a __p. 190190*/ 191191void eeprom_update_byte (uint8_t *__p, uint8_t __value); 192192 193193/** \ingroup avr_eeprom 194194Update a word \a __value to EEPROM address \a __p. 195195*/ 196196void eeprom_update_word (uint16_t *__p, uint16_t __value); 197197 198198/** \ingroup avr_eeprom 199199Update a 32-bit double word \a __value to EEPROM address \a __p. 200200*/ 201201void eeprom_update_dword (uint32_t *__p, uint32_t __value); 202202 203203/** \ingroup avr_eeprom 204204Update a float \a __value to EEPROM address \a __p. 205205*/ 206206void eeprom_update_float (float *__p, float __value); 207207 208208/** \ingroup avr_eeprom 209209Update a block of \a __n bytes to EEPROM address \a __dst from \a __src. 210210\note The argument order is mismatch with common functions like strcpy(). 211211*/ 212212void eeprom_update_block (const void *__src, void *__dst, size_t __n); 213213 214214 215215/** \name IAR C compatibility defines */ 216216/*@{*/ 217217 218218/** \def _EEPUT 219219\ingroup avr_eeprom 220220Write a byte to EEPROM. Compatibility define for IAR C. */ 221 221#define _EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val)) 222222 223223/** \def __EEPUT 224224\ingroup avr_eeprom 225225Write a byte to EEPROM. Compatibility define for IAR C. */ 226 226#define __EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val)) 227227 228228/** \def _EEGET 229229\ingroup avr_eeprom 230230Read a byte from EEPROM. Compatibility define for IAR C. */ 231 231#define _EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr)) 232232 233233/** \def __EEGET 234234\ingroup avr_eeprom 235235Read a byte from EEPROM. Compatibility define for IAR C. */ 236 236#define __EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr)) 237237 238238/*@}*/ 239239 240240#ifdef __cplusplus 241241} 242242#endif 243243 244244#endif /* !__ASSEMBLER__ */ 245245#endif /* E2END || defined(__DOXYGEN__) || defined(__COMPILING_AVR_LIBC__) */ 246246#endif /* !_AVR_EEPROM_H_ */eeprom_update_block void eeprom_update_block(const void *__src, void *__dst, size_t __n)
eeprom_write_block void eeprom_write_block(const void *__src, void *__dst, size_t __n)
eeprom_update_word void eeprom_update_word(uint16_t *__p, uint16_t __value)
eeprom_write_byte void eeprom_write_byte(uint8_t *__p, uint8_t __value)
eeprom_read_block void eeprom_read_block(void *__dst, const void *__src, size_t __n)
eeprom_write_dword void eeprom_write_dword(uint32_t *__p, uint32_t __value)
eeprom_read_float float eeprom_read_float(const float *__p) __ATTR_PURE__
eeprom_update_dword void eeprom_update_dword(uint32_t *__p, uint32_t __value)
eeprom_write_float void eeprom_write_float(float *__p, float __value)
eeprom_update_byte void eeprom_update_byte(uint8_t *__p, uint8_t __value)
uint8_t unsigned char uint8_t
Definition: stdint.h:83
uint32_t unsigned long int uint32_t
Definition: stdint.h:103
eeprom_read_dword uint32_t eeprom_read_dword(const uint32_t *__p) __ATTR_PURE__
eeprom_write_word void eeprom_write_word(uint16_t *__p, uint16_t __value)
eeprom_update_float void eeprom_update_float(float *__p, float __value)
eeprom_read_byte uint8_t eeprom_read_byte(const uint8_t *__p) __ATTR_PURE__
eeprom_read_word uint16_t eeprom_read_word(const uint16_t *__p) __ATTR_PURE__
uint16_t unsigned int uint16_t
Definition: stdint.h:93