$treeview $search $mathjax $extrastylesheet
avr-libc
2.0.0
$projectbrief
|
$projectbrief
|
$searchbox |
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$ */ 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 #if (EEPROM_PAGE_SIZE == 1) 00049 /* True for Dx devices right now, can write directly 00050 to mapped EEPROM mem by just setting mode to 00051 EEERWR, writing bytes and then clearing mode. */ 00052 #define __EEPROM_NON_PAGE_WRITE_AVAILABLE__ 1 00053 #endif 00054 00055 #ifndef __ASSEMBLER__ 00056 00057 #include <stddef.h> /* size_t */ 00058 #include <stdint.h> 00059 00060 /** \defgroup avr_eeprom <avr/eeprom.h>: EEPROM handling 00061 \code #include <avr/eeprom.h> \endcode 00062 00063 This header file declares the interface to some simple library 00064 routines suitable for handling the data EEPROM contained in the 00065 AVR microcontrollers. The implementation uses a simple polled 00066 mode interface. Applications that require interrupt-controlled 00067 EEPROM access to ensure that no time will be wasted in spinloops 00068 will have to deploy their own implementation. 00069 00070 \par Notes: 00071 00072 - In addition to the write functions there is a set of update ones. 00073 This functions read each byte first and skip the burning if the 00074 old value is the same with new. The scaning direction is from 00075 high address to low, to obtain quick return in common cases. 00076 00077 - All of the read/write functions first make sure the EEPROM is 00078 ready to be accessed. Since this may cause long delays if a 00079 write operation is still pending, time-critical applications 00080 should first poll the EEPROM e. g. using eeprom_is_ready() before 00081 attempting any actual I/O. But this functions are not wait until 00082 SELFPRGEN in SPMCSR becomes zero. Do this manually, if your 00083 softwate contains the Flash burning. 00084 00085 - As these functions modify IO registers, they are known to be 00086 non-reentrant. If any of these functions are used from both, 00087 standard and interrupt context, the applications must ensure 00088 proper protection (e.g. by disabling interrupts before accessing 00089 them). 00090 00091 - All write functions force erase_and_write programming mode. 00092 00093 - For Xmega the EEPROM start address is 0, like other architectures. 00094 The reading functions add the 0x2000 value to use EEPROM mapping into 00095 data space. 00096 */ 00097 00098 #ifdef __cplusplus 00099 extern "C" { 00100 #endif 00101 00102 #ifndef __ATTR_PURE__ 00103 # ifdef __DOXYGEN__ 00104 # define __ATTR_PURE__ 00105 # else 00106 # define __ATTR_PURE__ __attribute__((__pure__)) 00107 # endif 00108 #endif 00109 00110 /** \def EEMEM 00111 \ingroup avr_eeprom 00112 Attribute expression causing a variable to be allocated within the 00113 .eeprom section. */ 00114 #define EEMEM __attribute__((section(".eeprom"))) 00115 00116 /** \def eeprom_is_ready 00117 \ingroup avr_eeprom 00118 \returns 1 if EEPROM is ready for a new read/write operation, 0 if not. 00119 */ 00120 #if defined (__DOXYGEN__) 00121 # define eeprom_is_ready() 00122 #elif defined (NVM_STATUS) 00123 # define eeprom_is_ready() bit_is_clear (NVM_STATUS, NVM_NVMBUSY_bp) 00124 #elif defined (NVMCTRL_STATUS) 00125 # define eeprom_is_ready() bit_is_clear (NVMCTRL_STATUS, NVMCTRL_EEBUSY_bp) 00126 #elif defined (DEECR) 00127 # define eeprom_is_ready() bit_is_clear (DEECR, BSY) 00128 #elif defined (EEPE) 00129 # define eeprom_is_ready() bit_is_clear (EECR, EEPE) 00130 #else 00131 # define eeprom_is_ready() bit_is_clear (EECR, EEWE) 00132 #endif 00133 00134 00135 /** \def eeprom_busy_wait 00136 \ingroup avr_eeprom 00137 Loops until the eeprom is no longer busy. 00138 \returns Nothing. 00139 */ 00140 #define eeprom_busy_wait() do {} while (!eeprom_is_ready()) 00141 00142 00143 /** \ingroup avr_eeprom 00144 Read one byte from EEPROM address \a __p. 00145 */ 00146 uint8_t eeprom_read_byte (const uint8_t *__p) __ATTR_PURE__; 00147 00148 /** \ingroup avr_eeprom 00149 Read one 16-bit word (little endian) from EEPROM address \a __p. 00150 */ 00151 uint16_t eeprom_read_word (const uint16_t *__p) __ATTR_PURE__; 00152 00153 /** \ingroup avr_eeprom 00154 Read one 32-bit double word (little endian) from EEPROM address \a __p. 00155 */ 00156 uint32_t eeprom_read_dword (const uint32_t *__p) __ATTR_PURE__; 00157 00158 /** \ingroup avr_eeprom 00159 Read one float value (little endian) from EEPROM address \a __p. 00160 */ 00161 float eeprom_read_float (const float *__p) __ATTR_PURE__; 00162 00163 /** \ingroup avr_eeprom 00164 Read a block of \a __n bytes from EEPROM address \a __src to SRAM 00165 \a __dst. 00166 */ 00167 void eeprom_read_block (void *__dst, const void *__src, size_t __n); 00168 00169 00170 /** \ingroup avr_eeprom 00171 Write a byte \a __value to EEPROM address \a __p. 00172 */ 00173 void eeprom_write_byte (uint8_t *__p, uint8_t __value); 00174 00175 /** \ingroup avr_eeprom 00176 Write a word \a __value to EEPROM address \a __p. 00177 */ 00178 void eeprom_write_word (uint16_t *__p, uint16_t __value); 00179 00180 /** \ingroup avr_eeprom 00181 Write a 32-bit double word \a __value to EEPROM address \a __p. 00182 */ 00183 void eeprom_write_dword (uint32_t *__p, uint32_t __value); 00184 00185 /** \ingroup avr_eeprom 00186 Write a float \a __value to EEPROM address \a __p. 00187 */ 00188 void eeprom_write_float (float *__p, float __value); 00189 00190 /** \ingroup avr_eeprom 00191 Write a block of \a __n bytes to EEPROM address \a __dst from \a __src. 00192 \note The argument order is mismatch with common functions like strcpy(). 00193 */ 00194 void eeprom_write_block (const void *__src, void *__dst, size_t __n); 00195 00196 00197 /** \ingroup avr_eeprom 00198 Update a byte \a __value to EEPROM address \a __p. 00199 */ 00200 void eeprom_update_byte (uint8_t *__p, uint8_t __value); 00201 00202 /** \ingroup avr_eeprom 00203 Update a word \a __value to EEPROM address \a __p. 00204 */ 00205 void eeprom_update_word (uint16_t *__p, uint16_t __value); 00206 00207 /** \ingroup avr_eeprom 00208 Update a 32-bit double word \a __value to EEPROM address \a __p. 00209 */ 00210 void eeprom_update_dword (uint32_t *__p, uint32_t __value); 00211 00212 /** \ingroup avr_eeprom 00213 Update a float \a __value to EEPROM address \a __p. 00214 */ 00215 void eeprom_update_float (float *__p, float __value); 00216 00217 /** \ingroup avr_eeprom 00218 Update a block of \a __n bytes to EEPROM address \a __dst from \a __src. 00219 \note The argument order is mismatch with common functions like strcpy(). 00220 */ 00221 void eeprom_update_block (const void *__src, void *__dst, size_t __n); 00222 00223 00224 /** \name IAR C compatibility defines */ 00225 /*@{*/ 00226 00227 /** \def _EEPUT 00228 \ingroup avr_eeprom 00229 Write a byte to EEPROM. Compatibility define for IAR C. */ 00230 #define _EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val)) 00231 00232 /** \def __EEPUT 00233 \ingroup avr_eeprom 00234 Write a byte to EEPROM. Compatibility define for IAR C. */ 00235 #define __EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val)) 00236 00237 /** \def _EEGET 00238 \ingroup avr_eeprom 00239 Read a byte from EEPROM. Compatibility define for IAR C. */ 00240 #define _EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr)) 00241 00242 /** \def __EEGET 00243 \ingroup avr_eeprom 00244 Read a byte from EEPROM. Compatibility define for IAR C. */ 00245 #define __EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr)) 00246 00247 /*@}*/ 00248 00249 #ifdef __cplusplus 00250 } 00251 #endif 00252 00253 #endif /* !__ASSEMBLER__ */ 00254 #endif /* E2END || defined(__DOXYGEN__) || defined(__COMPILING_AVR_LIBC__) */ 00255 #endif /* !_AVR_EEPROM_H_ */