$extrastylesheet
avr-libc
2.0.0
Standard C library for AVR-GCC
|
AVR Libc Home Page |
![]() |
AVR Libc Development Pages |
|||
Main Page |
User Manual |
Library Reference |
FAQ |
Example Projects |
00001 /* Copyright (c) 2002, 2003, 2004, 2007 Marek Michalkiewicz 00002 Copyright (c) 2005, 2006 Bjoern Haase 00003 Copyright (c) 2008 Atmel Corporation 00004 Copyright (c) 2008 Wouter van Gulik 00005 Copyright (c) 2009 Dmitry Xmelkov 00006 All rights reserved. 00007 00008 Redistribution and use in source and binary forms, with or without 00009 modification, are permitted provided that the following conditions are met: 00010 00011 * Redistributions of source code must retain the above copyright 00012 notice, this list of conditions and the following disclaimer. 00013 * Redistributions in binary form must reproduce the above copyright 00014 notice, this list of conditions and the following disclaimer in 00015 the documentation and/or other materials provided with the 00016 distribution. 00017 * Neither the name of the copyright holders nor the names of 00018 contributors may be used to endorse or promote products derived 00019 from this software without specific prior written permission. 00020 00021 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00022 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00025 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00026 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00027 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00028 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00029 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00030 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00031 POSSIBILITY OF SUCH DAMAGE. */ 00032 00033 /* $Id: eeprom.h 2468 2015-02-25 12:53:38Z pitchumani $ */ 00034 00035 #ifndef _AVR_EEPROM_H_ 00036 #define _AVR_EEPROM_H_ 1 00037 00038 #include <avr/io.h> 00039 00040 #if !E2END && !defined(__DOXYGEN__) && !defined(__COMPILING_AVR_LIBC__) 00041 # warning "Device does not have EEPROM available." 00042 #else 00043 00044 #if defined (EEAR) && !defined (EEARL) && !defined (EEARH) 00045 #define EEARL EEAR 00046 #endif 00047 00048 #ifndef __ASSEMBLER__ 00049 00050 #include <stddef.h> /* size_t */ 00051 #include <stdint.h> 00052 00053 /** \defgroup avr_eeprom <avr/eeprom.h>: EEPROM handling 00054 \code #include <avr/eeprom.h> \endcode 00055 00056 This header file declares the interface to some simple library 00057 routines suitable for handling the data EEPROM contained in the 00058 AVR microcontrollers. The implementation uses a simple polled 00059 mode interface. Applications that require interrupt-controlled 00060 EEPROM access to ensure that no time will be wasted in spinloops 00061 will have to deploy their own implementation. 00062 00063 \par Notes: 00064 00065 - In addition to the write functions there is a set of update ones. 00066 This functions read each byte first and skip the burning if the 00067 old value is the same with new. The scaning direction is from 00068 high address to low, to obtain quick return in common cases. 00069 00070 - All of the read/write functions first make sure the EEPROM is 00071 ready to be accessed. Since this may cause long delays if a 00072 write operation is still pending, time-critical applications 00073 should first poll the EEPROM e. g. using eeprom_is_ready() before 00074 attempting any actual I/O. But this functions are not wait until 00075 SELFPRGEN in SPMCSR becomes zero. Do this manually, if your 00076 softwate contains the Flash burning. 00077 00078 - As these functions modify IO registers, they are known to be 00079 non-reentrant. If any of these functions are used from both, 00080 standard and interrupt context, the applications must ensure 00081 proper protection (e.g. by disabling interrupts before accessing 00082 them). 00083 00084 - All write functions force erase_and_write programming mode. 00085 00086 - For Xmega the EEPROM start address is 0, like other architectures. 00087 The reading functions add the 0x2000 value to use EEPROM mapping into 00088 data space. 00089 */ 00090 00091 #ifdef __cplusplus 00092 extern "C" { 00093 #endif 00094 00095 #ifndef __ATTR_PURE__ 00096 # ifdef __DOXYGEN__ 00097 # define __ATTR_PURE__ 00098 # else 00099 # define __ATTR_PURE__ __attribute__((__pure__)) 00100 # endif 00101 #endif 00102 00103 /** \def EEMEM 00104 \ingroup avr_eeprom 00105 Attribute expression causing a variable to be allocated within the 00106 .eeprom section. */ 00107 #define EEMEM __attribute__((section(".eeprom"))) 00108 00109 /** \def eeprom_is_ready 00110 \ingroup avr_eeprom 00111 \returns 1 if EEPROM is ready for a new read/write operation, 0 if not. 00112 */ 00113 #if defined (__DOXYGEN__) 00114 # define eeprom_is_ready() 00115 #elif defined (__AVR_XMEGA__) && __AVR_XMEGA__ 00116 # define eeprom_is_ready() bit_is_clear (NVM_STATUS, NVM_NVMBUSY_bp) 00117 #elif defined (DEECR) 00118 # define eeprom_is_ready() bit_is_clear (DEECR, BSY) 00119 #elif defined (EEPE) 00120 # define eeprom_is_ready() bit_is_clear (EECR, EEPE) 00121 #else 00122 # define eeprom_is_ready() bit_is_clear (EECR, EEWE) 00123 #endif 00124 00125 00126 /** \def eeprom_busy_wait 00127 \ingroup avr_eeprom 00128 Loops until the eeprom is no longer busy. 00129 \returns Nothing. 00130 */ 00131 #define eeprom_busy_wait() do {} while (!eeprom_is_ready()) 00132 00133 00134 /** \ingroup avr_eeprom 00135 Read one byte from EEPROM address \a __p. 00136 */ 00137 uint8_t eeprom_read_byte (const uint8_t *__p) __ATTR_PURE__; 00138 00139 /** \ingroup avr_eeprom 00140 Read one 16-bit word (little endian) from EEPROM address \a __p. 00141 */ 00142 uint16_t eeprom_read_word (const uint16_t *__p) __ATTR_PURE__; 00143 00144 /** \ingroup avr_eeprom 00145 Read one 32-bit double word (little endian) from EEPROM address \a __p. 00146 */ 00147 uint32_t eeprom_read_dword (const uint32_t *__p) __ATTR_PURE__; 00148 00149 /** \ingroup avr_eeprom 00150 Read one float value (little endian) from EEPROM address \a __p. 00151 */ 00152 float eeprom_read_float (const float *__p) __ATTR_PURE__; 00153 00154 /** \ingroup avr_eeprom 00155 Read a block of \a __n bytes from EEPROM address \a __src to SRAM 00156 \a __dst. 00157 */ 00158 void eeprom_read_block (void *__dst, const void *__src, size_t __n); 00159 00160 00161 /** \ingroup avr_eeprom 00162 Write a byte \a __value to EEPROM address \a __p. 00163 */ 00164 void eeprom_write_byte (uint8_t *__p, uint8_t __value); 00165 00166 /** \ingroup avr_eeprom 00167 Write a word \a __value to EEPROM address \a __p. 00168 */ 00169 void eeprom_write_word (uint16_t *__p, uint16_t __value); 00170 00171 /** \ingroup avr_eeprom 00172 Write a 32-bit double word \a __value to EEPROM address \a __p. 00173 */ 00174 void eeprom_write_dword (uint32_t *__p, uint32_t __value); 00175 00176 /** \ingroup avr_eeprom 00177 Write a float \a __value to EEPROM address \a __p. 00178 */ 00179 void eeprom_write_float (float *__p, float __value); 00180 00181 /** \ingroup avr_eeprom 00182 Write a block of \a __n bytes to EEPROM address \a __dst from \a __src. 00183 \note The argument order is mismatch with common functions like strcpy(). 00184 */ 00185 void eeprom_write_block (const void *__src, void *__dst, size_t __n); 00186 00187 00188 /** \ingroup avr_eeprom 00189 Update a byte \a __value to EEPROM address \a __p. 00190 */ 00191 void eeprom_update_byte (uint8_t *__p, uint8_t __value); 00192 00193 /** \ingroup avr_eeprom 00194 Update a word \a __value to EEPROM address \a __p. 00195 */ 00196 void eeprom_update_word (uint16_t *__p, uint16_t __value); 00197 00198 /** \ingroup avr_eeprom 00199 Update a 32-bit double word \a __value to EEPROM address \a __p. 00200 */ 00201 void eeprom_update_dword (uint32_t *__p, uint32_t __value); 00202 00203 /** \ingroup avr_eeprom 00204 Update a float \a __value to EEPROM address \a __p. 00205 */ 00206 void eeprom_update_float (float *__p, float __value); 00207 00208 /** \ingroup avr_eeprom 00209 Update a block of \a __n bytes to EEPROM address \a __dst from \a __src. 00210 \note The argument order is mismatch with common functions like strcpy(). 00211 */ 00212 void eeprom_update_block (const void *__src, void *__dst, size_t __n); 00213 00214 00215 /** \name IAR C compatibility defines */ 00216 /*@{*/ 00217 00218 /** \def _EEPUT 00219 \ingroup avr_eeprom 00220 Write a byte to EEPROM. Compatibility define for IAR C. */ 00221 #define _EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val)) 00222 00223 /** \def __EEPUT 00224 \ingroup avr_eeprom 00225 Write a byte to EEPROM. Compatibility define for IAR C. */ 00226 #define __EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val)) 00227 00228 /** \def _EEGET 00229 \ingroup avr_eeprom 00230 Read a byte from EEPROM. Compatibility define for IAR C. */ 00231 #define _EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr)) 00232 00233 /** \def __EEGET 00234 \ingroup avr_eeprom 00235 Read a byte from EEPROM. Compatibility define for IAR C. */ 00236 #define __EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr)) 00237 00238 /*@}*/ 00239 00240 #ifdef __cplusplus 00241 } 00242 #endif 00243 00244 #endif /* !__ASSEMBLER__ */ 00245 #endif /* E2END || defined(__DOXYGEN__) || defined(__COMPILING_AVR_LIBC__) */ 00246 #endif /* !_AVR_EEPROM_H_ */