AVR Libc Home Page |  | AVR Libc Development Pages
Main Page | User Manual | Library Reference | FAQ | Alphabetical Index | Example Projects

eeprom.h
1 /* Copyright (c) 2002, 2003, 2004, 2007 Marek Michalkiewicz
2 Copyright (c) 2005, 2006 Bjoern Haase
3 Copyright (c) 2008 Atmel Corporation
4 Copyright (c) 2008 Wouter van Gulik
5 Copyright (c) 2009 Dmitry Xmelkov
6 All rights reserved.
7
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10
11 * Redistributions of source code must retain the above copyright
12 notice, this list of conditions and the following disclaimer.
13 * Redistributions in binary form must reproduce the above copyright
14 notice, this list of conditions and the following disclaimer in
15 the documentation and/or other materials provided with the
16 distribution.
17 * Neither the name of the copyright holders nor the names of
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE. */
32
33 /* $Id: eeprom.h 2211 2011-02-14 14:04:25Z aboyapati $ */
34
35 #ifndef _AVR_EEPROM_H_
36 #define _AVR_EEPROM_H_ 1
37
38 #include <avr/io.h>
39
40 #if !E2END && !defined(__DOXYGEN__) && !defined(__COMPILING_AVR_LIBC__)
41 # warning "Device does not have EEPROM available."
42 #else
43
44 #ifndef __DOXYGEN__
45
46 #if defined (__AVR_AT94K__)
47 # define _EEPROM_SUFFIX _at94k
48 #elif defined (__AVR_AT43USB320__)
49 # define _EEPROM_SUFFIX _43u320
50 #elif defined (__AVR_AT43USB355__)
51 # define _EEPROM_SUFFIX _43u355
52 #elif defined (__AVR_AT76C711__)
53 # define _EEPROM_SUFFIX _76c711
54 #elif defined (__AVR_AT86RF401__)
55 # define _EEPROM_SUFFIX _86r401
56 #elif defined (__AVR_AT90PWM1__)
57 # define _EEPROM_SUFFIX _90pwm1
58 #elif defined (__AVR_AT90PWM2__)
59 # define _EEPROM_SUFFIX _90pwm2
60 #elif defined (__AVR_AT90PWM2B__)
61 # define _EEPROM_SUFFIX _90pwm2b
62 #elif defined (__AVR_AT90PWM3__)
63 # define _EEPROM_SUFFIX _90pwm3
64 #elif defined (__AVR_AT90PWM3B__)
65 # define _EEPROM_SUFFIX _90pwm3b
66 #elif defined (__AVR_AT90PWM216__)
67 # define _EEPROM_SUFFIX _90pwm216
68 #elif defined (__AVR_AT90PWM316__)
69 # define _EEPROM_SUFFIX _90pwm316
70 #elif defined (__AVR_AT90PWM81__)
71 # define _EEPROM_SUFFIX _90pwm81
72 #elif defined (__AVR_ATmega16M1__)
73 # define _EEPROM_SUFFIX _m16m1
74 #elif defined (__AVR_ATmega8U2__)
75 # define _EEPROM_SUFFIX _m8u2
76 #elif defined (__AVR_ATmega16U2__)
77 # define _EEPROM_SUFFIX _m16u2
78 #elif defined (__AVR_ATmega16U4__)
79 # define _EEPROM_SUFFIX _m16u4
80 #elif defined (__AVR_ATmega32C1__)
81 # define _EEPROM_SUFFIX _m32c1
82 #elif defined (__AVR_ATmega32M1__)
83 # define _EEPROM_SUFFIX _m32m1
84 #elif defined (__AVR_ATmega32U2__)
85 # define _EEPROM_SUFFIX _m32u2
86 #elif defined (__AVR_ATmega32U4__)
87 # define _EEPROM_SUFFIX _m32u4
88 #elif defined (__AVR_ATmega32U6__)
89 # define _EEPROM_SUFFIX _m32u6
90 #elif defined (__AVR_ATmega64C1__)
91 # define _EEPROM_SUFFIX _m64c1
92 #elif defined (__AVR_ATmega64M1__)
93 # define _EEPROM_SUFFIX _m64m1
94 #elif defined (__AVR_ATmega128__)
95 # define _EEPROM_SUFFIX _m128
96 #elif defined (__AVR_ATmega1280__)
97 # define _EEPROM_SUFFIX _m1280
98 #elif defined (__AVR_ATmega1281__)
99 # define _EEPROM_SUFFIX _m1281
100 #elif defined (__AVR_ATmega1284P__)
101 # define _EEPROM_SUFFIX _m1284p
102 #elif defined (__AVR_ATmega128RFA1__)
103 # define _EEPROM_SUFFIX _m128rfa1
104 #elif defined (__AVR_ATmega2560__)
105 # define _EEPROM_SUFFIX _m2560
106 #elif defined (__AVR_ATmega2561__)
107 # define _EEPROM_SUFFIX _m2561
108 #elif defined (__AVR_AT90CAN32__)
109 # define _EEPROM_SUFFIX _can32
110 #elif defined (__AVR_AT90CAN64__)
111 # define _EEPROM_SUFFIX _can64
112 #elif defined (__AVR_AT90CAN128__)
113 # define _EEPROM_SUFFIX _can128
114 #elif defined (__AVR_AT90USB82__)
115 # define _EEPROM_SUFFIX _usb82
116 #elif defined (__AVR_AT90USB162__)
117 # define _EEPROM_SUFFIX _usb162
118 #elif defined (__AVR_AT90USB646__)
119 # define _EEPROM_SUFFIX _usb646
120 #elif defined (__AVR_AT90USB647__)
121 # define _EEPROM_SUFFIX _usb647
122 #elif defined (__AVR_AT90USB1286__)
123 # define _EEPROM_SUFFIX _usb1286
124 #elif defined (__AVR_AT90USB1287__)
125 # define _EEPROM_SUFFIX _usb1287
126 #elif defined (__AVR_ATmega64__)
127 # define _EEPROM_SUFFIX _m64
128 #elif defined (__AVR_ATmega640__)
129 # define _EEPROM_SUFFIX _m640
130 #elif defined (__AVR_ATmega644__)
131 # define _EEPROM_SUFFIX _m644
132 #elif defined (__AVR_ATmega644A__)
133 # define _EEPROM_SUFFIX _m644a
134 #elif defined (__AVR_ATmega644P__)
135 # define _EEPROM_SUFFIX _m644p
136 #elif defined (__AVR_ATmega644PA__)
137 # define _EEPROM_SUFFIX _m644pa
138 #elif defined (__AVR_ATmega645__)
139 # define _EEPROM_SUFFIX _m645
140 #elif defined (__AVR_ATmega645A__)
141 # define _EEPROM_SUFFIX _m645a
142 #elif defined (__AVR_ATmega645P__)
143 # define _EEPROM_SUFFIX _m645p
144 #elif defined (__AVR_ATmega6450__)
145 # define _EEPROM_SUFFIX _m6450
146 #elif defined (__AVR_ATmega6450A__)
147 # define _EEPROM_SUFFIX _m6450a
148 #elif defined (__AVR_ATmega6450P__)
149 # define _EEPROM_SUFFIX _m6450p
150 #elif defined (__AVR_ATmega649__)
151 # define _EEPROM_SUFFIX _m649
152 #elif defined (__AVR_ATmega649A__)
153 # define _EEPROM_SUFFIX _m649a
154 #elif defined (__AVR_ATmega649P__)
155 # define _EEPROM_SUFFIX _m649p
156 #elif defined (__AVR_ATmega6490__)
157 # define _EEPROM_SUFFIX _m6490
158 #elif defined (__AVR_ATmega6490A__)
159 # define _EEPROM_SUFFIX _m6490a
160 #elif defined (__AVR_ATmega6490P__)
161 # define _EEPROM_SUFFIX _m6490p
162 #elif defined (__AVR_ATmega103__)
163 # define _EEPROM_SUFFIX _m103
164 #elif defined (__AVR_ATmega32__)
165 # define _EEPROM_SUFFIX _m32
166 #elif defined (__AVR_ATmega323__)
167 # define _EEPROM_SUFFIX _m323
168 #elif defined (__AVR_ATmega324A__)
169 # define _EEPROM_SUFFIX _m324a
170 #elif defined (__AVR_ATmega324P__)
171 # define _EEPROM_SUFFIX _m324p
172 #elif defined (__AVR_ATmega324PA__)
173 # define _EEPROM_SUFFIX _m324pa
174 #elif defined (__AVR_ATmega325__)
175 # define _EEPROM_SUFFIX _m325
176 #elif defined (__AVR_ATmega325A__)
177 # define _EEPROM_SUFFIX _m325a
178 #elif defined (__AVR_ATmega325P__)
179 # define _EEPROM_SUFFIX _m325p
180 #elif defined (__AVR_ATmega3250__)
181 # define _EEPROM_SUFFIX _m3250
182 #elif defined (__AVR_ATmega3250A__)
183 # define _EEPROM_SUFFIX _m3250a
184 #elif defined (__AVR_ATmega3250P__)
185 # define _EEPROM_SUFFIX _m3250p
186 #elif defined (__AVR_ATmega328__)
187 # define _EEPROM_SUFFIX _m328
188 #elif defined (__AVR_ATmega328P__)
189 # define _EEPROM_SUFFIX _m328p
190 #elif defined (__AVR_ATmega329__)
191 # define _EEPROM_SUFFIX _m329
192 #elif defined (__AVR_ATmega329A__)
193 # define _EEPROM_SUFFIX _m329a
194 #elif defined (__AVR_ATmega329P__)
195 # define _EEPROM_SUFFIX _m329p
196 #elif defined (__AVR_ATmega329PA__)
197 # define _EEPROM_SUFFIX _m329pa
198 #elif defined (__AVR_ATmega3290__)
199 # define _EEPROM_SUFFIX _m3290
200 #elif defined (__AVR_ATmega3290A__)
201 # define _EEPROM_SUFFIX _m3290a
202 #elif defined (__AVR_ATmega3290P__)
203 # define _EEPROM_SUFFIX _m3290p
204 #elif defined (__AVR_ATmega32HVB__)
205 # define _EEPROM_SUFFIX _m32hvb
206 #elif defined (__AVR_ATmega32HVBREVB__)
207 # define _EEPROM_SUFFIX _m32hvbrevb
208 #elif defined (__AVR_ATmega64HVE__)
209 # define _EEPROM_SUFFIX _m64hve
210 #elif defined (__AVR_ATmega406__)
211 # define _EEPROM_SUFFIX _m406
212 #elif defined (__AVR_ATmega16__)
213 # define _EEPROM_SUFFIX _m16
214 #elif defined (__AVR_ATmega16A__)
215 # define _EEPROM_SUFFIX _m16a
216 #elif defined (__AVR_ATmega161__)
217 # define _EEPROM_SUFFIX _m161
218 #elif defined (__AVR_ATmega162__)
219 # define _EEPROM_SUFFIX _m162
220 #elif defined (__AVR_ATmega163__)
221 # define _EEPROM_SUFFIX _m163
222 #elif defined (__AVR_ATmega164__)
223 # define _EEPROM_SUFFIX _m164
224 #elif defined (__AVR_ATmega164P__)
225 # define _EEPROM_SUFFIX _m164p
226 #elif defined (__AVR_ATmega165__)
227 # define _EEPROM_SUFFIX _m165
228 #elif defined (__AVR_ATmega165A__)
229 # define _EEPROM_SUFFIX _m165a
230 #elif defined (__AVR_ATmega165P__)
231 # define _EEPROM_SUFFIX _m165p
232 #elif defined (__AVR_ATmega168__)
233 # define _EEPROM_SUFFIX _m168
234 #elif defined (__AVR_ATmega168A__)
235 # define _EEPROM_SUFFIX _m168a
236 #elif defined (__AVR_ATmega168P__)
237 # define _EEPROM_SUFFIX _m168p
238 #elif defined (__AVR_ATmega169__)
239 # define _EEPROM_SUFFIX _m169
240 #elif defined (__AVR_ATmega169A__)
241 # define _EEPROM_SUFFIX _m169a
242 #elif defined (__AVR_ATmega169P__)
243 # define _EEPROM_SUFFIX _m169p
244 #elif defined (__AVR_ATmega169PA__)
245 # define _EEPROM_SUFFIX _m169pa
246 #elif defined (__AVR_ATmega8HVA__)
247 # define _EEPROM_SUFFIX _m8hva
248 #elif defined (__AVR_ATmega16HVA__)
249 # define _EEPROM_SUFFIX _m16hva
250 #elif defined (__AVR_ATmega16HVA2__)
251 # define _EEPROM_SUFFIX _m16hva2
252 #elif defined (__AVR_ATmega16HVB__)
253 # define _EEPROM_SUFFIX _m16hvb
254 #elif defined (__AVR_ATmega16HVBREVB__)
255 # define _EEPROM_SUFFIX _m16hvbrevb
256 #elif defined (__AVR_ATmega8__)
257 # define _EEPROM_SUFFIX _m8
258 #elif defined (__AVR_ATmega48__)
259 # define _EEPROM_SUFFIX _m48
260 #elif defined (__AVR_ATmega48A__)
261 # define _EEPROM_SUFFIX _m48a
262 #elif defined (__AVR_ATmega48P__)
263 # define _EEPROM_SUFFIX _m48p
264 #elif defined (__AVR_ATmega88__)
265 # define _EEPROM_SUFFIX _m88
266 #elif defined (__AVR_ATmega88A__)
267 # define _EEPROM_SUFFIX _m88a
268 #elif defined (__AVR_ATmega88P__)
269 # define _EEPROM_SUFFIX _m88p
270 #elif defined (__AVR_ATmega88PA__)
271 # define _EEPROM_SUFFIX _m88pa
272 #elif defined (__AVR_ATmega8515__)
273 # define _EEPROM_SUFFIX _m8515
274 #elif defined (__AVR_ATmega8535__)
275 # define _EEPROM_SUFFIX _m8535
276 #elif defined (__AVR_AT90S8535__)
277 # define _EEPROM_SUFFIX _8535
278 #elif defined (__AVR_AT90C8534__)
279 # define _EEPROM_SUFFIX _8534
280 #elif defined (__AVR_AT90S8515__)
281 # define _EEPROM_SUFFIX _8515
282 #elif defined (__AVR_AT90S4434__)
283 # define _EEPROM_SUFFIX _4434
284 #elif defined (__AVR_AT90S4433__)
285 # define _EEPROM_SUFFIX _4433
286 #elif defined (__AVR_AT90S4414__)
287 # define _EEPROM_SUFFIX _4414
288 #elif defined (__AVR_ATtiny22__)
289 # define _EEPROM_SUFFIX _tn22
290 #elif defined (__AVR_ATtiny26__)
291 # define _EEPROM_SUFFIX _tn26
292 #elif defined (__AVR_AT90S2343__)
293 # define _EEPROM_SUFFIX _2343
294 #elif defined (__AVR_AT90S2333__)
295 # define _EEPROM_SUFFIX _2333
296 #elif defined (__AVR_AT90S2323__)
297 # define _EEPROM_SUFFIX _2323
298 #elif defined (__AVR_AT90S2313__)
299 # define _EEPROM_SUFFIX _2313
300 #elif defined (__AVR_ATtiny2313__)
301 # define _EEPROM_SUFFIX _tn2313
302 #elif defined (__AVR_ATtiny2313A__)
303 # define _EEPROM_SUFFIX _tn2313a
304 #elif defined (__AVR_ATtiny4313__)
305 # define _EEPROM_SUFFIX _tn4313
306 #elif defined (__AVR_ATtiny13__)
307 # define _EEPROM_SUFFIX _tn13
308 #elif defined (__AVR_ATtiny13A__)
309 # define _EEPROM_SUFFIX _tn13a
310 #elif defined (__AVR_ATtiny25__)
311 # define _EEPROM_SUFFIX _tn25
312 #elif defined (__AVR_ATtiny45__)
313 # define _EEPROM_SUFFIX _tn45
314 #elif defined (__AVR_ATtiny85__)
315 # define _EEPROM_SUFFIX _tn85
316 #elif defined (__AVR_ATtiny24__)
317 # define _EEPROM_SUFFIX _tn24
318 #elif defined (__AVR_ATtiny24A__)
319 # define _EEPROM_SUFFIX _tn24a
320 #elif defined (__AVR_ATtiny44__)
321 # define _EEPROM_SUFFIX _tn44
322 #elif defined (__AVR_ATtiny44A__)
323 # define _EEPROM_SUFFIX _tn44a
324 #elif defined (__AVR_ATtiny84__)
325 # define _EEPROM_SUFFIX _tn84
326 #elif defined (__AVR_ATtiny84A__)
327 # define _EEPROM_SUFFIX _tn84a
328 #elif defined (__AVR_ATtiny261__)
329 # define _EEPROM_SUFFIX _tn261
330 #elif defined (__AVR_ATtiny261A__)
331 # define _EEPROM_SUFFIX _tn261a
332 #elif defined (__AVR_ATtiny461__)
333 # define _EEPROM_SUFFIX _tn461
334 #elif defined (__AVR_ATtiny461A__)
335 # define _EEPROM_SUFFIX _tn461a
336 #elif defined (__AVR_ATtiny861__)
337 # define _EEPROM_SUFFIX _tn861
338 #elif defined (__AVR_ATtiny861A__)
339 # define _EEPROM_SUFFIX _tn861a
340 #elif defined (__AVR_ATtiny43U__)
341 # define _EEPROM_SUFFIX _tn43u
342 #elif defined (__AVR_ATtiny48__)
343 # define _EEPROM_SUFFIX _tn48
344 #elif defined (__AVR_ATtiny88__)
345 # define _EEPROM_SUFFIX _tn88
346 #elif defined (__AVR_ATtiny87__)
347 # define _EEPROM_SUFFIX _tn87
348 #elif defined (__AVR_ATtiny167__)
349 # define _EEPROM_SUFFIX _tn167
350 #elif defined (__AVR_AT90SCR100__)
351 # define _EEPROM_SUFFIX _90scr100
352 #elif defined (__AVR_ATxmega16A4__)
353 # define _EEPROM_SUFFIX _x16a4
354 #elif defined (__AVR_ATxmega16D4__)
355 # define _EEPROM_SUFFIX _x16d4
356 #elif defined (__AVR_ATxmega32A4__)
357 # define _EEPROM_SUFFIX _x32a4
358 #elif defined (__AVR_ATxmega32D4__)
359 # define _EEPROM_SUFFIX _x32d4
360 #elif defined (__AVR_ATxmega64A1__)
361 # define _EEPROM_SUFFIX _x64a1
362 #elif defined (__AVR_ATxmega64A1U__)
363 # define _EEPROM_SUFFIX _x64a1u
364 #elif defined (__AVR_ATxmega64A3__)
365 # define _EEPROM_SUFFIX _x64a3
366 #elif defined (__AVR_ATxmega64D3__)
367 # define _EEPROM_SUFFIX _x64d3
368 #elif defined (__AVR_ATxmega128A1__)
369 # define _EEPROM_SUFFIX _x128a1
370 #elif defined (__AVR_ATxmega128A1U__)
371 # define _EEPROM_SUFFIX _x128a1u
372 #elif defined (__AVR_ATxmega128A3__)
373 # define _EEPROM_SUFFIX _x128a3
374 #elif defined (__AVR_ATxmega128D3__)
375 # define _EEPROM_SUFFIX _x128d3
376 #elif defined (__AVR_ATxmega192A3__)
377 # define _EEPROM_SUFFIX _x192a3
378 #elif defined (__AVR_ATxmega192D3__)
379 # define _EEPROM_SUFFIX _x192d3
380 #elif defined (__AVR_ATxmega256A3__)
381 # define _EEPROM_SUFFIX _x256a3
382 #elif defined (__AVR_ATxmega256A3B__)
383 # define _EEPROM_SUFFIX _x256a3b
384 #elif defined (__AVR_ATxmega256D3__)
385 # define _EEPROM_SUFFIX _x256d3
386 #elif defined (__AVR_ATA6289__)
387 # define _EEPROM_SUFFIX _a6289
388 /* avr1: the following only supported for assembler programs */
389 #elif defined (__AVR_ATtiny28__)
390 # define _EEPROM_SUFFIX _tn28
391 #elif defined (__AVR_AT90S1200__)
392 # define _EEPROM_SUFFIX _1200
393 #elif defined (__AVR_ATtiny15__)
394 # define _EEPROM_SUFFIX _tn15
395 #elif defined (__AVR_ATtiny12__)
396 # define _EEPROM_SUFFIX _tn12
397 #elif defined (__AVR_ATtiny11__)
398 # define _EEPROM_SUFFIX _tn11
399 #else
400 # define _EEPROM_SUFFIX _UNKNOWN
401 #endif
402
403 #define _EEPROM_CONCAT1(s1, s2) s1 ## s2
404 #define _EEPROM_CONCAT2(s1, s2) _EEPROM_CONCAT1 (s1, s2)
405
406 #define eeprom_read_byte _EEPROM_CONCAT2 (__eerd_byte, _EEPROM_SUFFIX)
407 #define eeprom_read_word _EEPROM_CONCAT2 (__eerd_word, _EEPROM_SUFFIX)
408 #define eeprom_read_dword _EEPROM_CONCAT2 (__eerd_dword, _EEPROM_SUFFIX)
409 #define eeprom_read_float _EEPROM_CONCAT2 (__eerd_float, _EEPROM_SUFFIX)
410 #define eeprom_read_block _EEPROM_CONCAT2 (__eerd_block, _EEPROM_SUFFIX)
411
412 #define eeprom_write_byte _EEPROM_CONCAT2 (__eewr_byte, _EEPROM_SUFFIX)
413 #define eeprom_write_word _EEPROM_CONCAT2 (__eewr_word, _EEPROM_SUFFIX)
414 #define eeprom_write_dword _EEPROM_CONCAT2 (__eewr_dword, _EEPROM_SUFFIX)
415 #define eeprom_write_float _EEPROM_CONCAT2 (__eewr_float, _EEPROM_SUFFIX)
416 #define eeprom_write_block _EEPROM_CONCAT2 (__eewr_block, _EEPROM_SUFFIX)
417
418 #define eeprom_update_byte _EEPROM_CONCAT2 (__eeupd_byte, _EEPROM_SUFFIX)
419 #define eeprom_update_word _EEPROM_CONCAT2 (__eeupd_word, _EEPROM_SUFFIX)
420 #define eeprom_update_dword _EEPROM_CONCAT2 (__eeupd_dword, _EEPROM_SUFFIX)
421 #define eeprom_update_float _EEPROM_CONCAT2 (__eeupd_float, _EEPROM_SUFFIX)
422 #define eeprom_update_block _EEPROM_CONCAT2 (__eeupd_block, _EEPROM_SUFFIX)
423
424 #endif /* !__DOXYGEN__ */
425
426 #ifndef __ASSEMBLER__
427
428 #include <stddef.h> /* size_t */
429 #include <stdint.h>
430
431 /** \defgroup avr_eeprom <avr/eeprom.h>: EEPROM handling
432 \code #include <avr/eeprom.h> \endcode
433
434 This header file declares the interface to some simple library
435 routines suitable for handling the data EEPROM contained in the
436 AVR microcontrollers. The implementation uses a simple polled
437 mode interface. Applications that require interrupt-controlled
438 EEPROM access to ensure that no time will be wasted in spinloops
439 will have to deploy their own implementation.
440
441 \par Notes:
442
443 - In addition to the write functions there is a set of update ones.
444 This functions read each byte first and skip the burning if the
445 old value is the same with new. The scaning direction is from
446 high address to low, to obtain quick return in common cases.
447
448 - All of the read/write functions first make sure the EEPROM is
449 ready to be accessed. Since this may cause long delays if a
450 write operation is still pending, time-critical applications
451 should first poll the EEPROM e. g. using eeprom_is_ready() before
452 attempting any actual I/O. But this functions are not wait until
453 SELFPRGEN in SPMCSR becomes zero. Do this manually, if your
454 softwate contains the Flash burning.
455
456 - As these functions modify IO registers, they are known to be
457 non-reentrant. If any of these functions are used from both,
458 standard and interrupt context, the applications must ensure
459 proper protection (e.g. by disabling interrupts before accessing
460 them).
461
462 - All write functions force erase_and_write programming mode.
463
464 - For Xmega the EEPROM start address is 0, like other architectures.
465 The reading functions add the 0x2000 value to use EEPROM mapping into
466 data space.
467 */
468
469 #ifdef __cplusplus
470 extern "C" {
471 #endif
472
473 #ifndef __ATTR_PURE__
474 # ifdef __DOXYGEN__
475 # define __ATTR_PURE__
476 # else
477 # define __ATTR_PURE__ __attribute__((__pure__))
478 # endif
479 #endif
480
481 /** \def EEMEM
482 \ingroup avr_eeprom
483 Attribute expression causing a variable to be allocated within the
484 .eeprom section. */
485 #define EEMEM __attribute__((section(".eeprom")))
486
487 /** \def eeprom_is_ready
488 \ingroup avr_eeprom
489 \returns 1 if EEPROM is ready for a new read/write operation, 0 if not.
490 */
491 #if defined (__DOXYGEN__)
492 # define eeprom_is_ready()
493 #elif defined (__AVR_XMEGA__) && __AVR_XMEGA__
494 # define eeprom_is_ready() bit_is_clear (NVM_STATUS, NVM_NVMBUSY_bp)
495 #elif defined (DEECR)
496 # define eeprom_is_ready() bit_is_clear (DEECR, BSY)
497 #elif defined (EEPE)
498 # define eeprom_is_ready() bit_is_clear (EECR, EEPE)
499 #else
500 # define eeprom_is_ready() bit_is_clear (EECR, EEWE)
501 #endif
502
503
504 /** \def eeprom_busy_wait
505 \ingroup avr_eeprom
506 Loops until the eeprom is no longer busy.
507 \returns Nothing.
508 */
509 #define eeprom_busy_wait() do {} while (!eeprom_is_ready())
510
511
512 /** \ingroup avr_eeprom
513 Read one byte from EEPROM address \a __p.
514 */
515 uint8_t eeprom_read_byte (const uint8_t *__p) __ATTR_PURE__;
516
517 /** \ingroup avr_eeprom
518 Read one 16-bit word (little endian) from EEPROM address \a __p.
519 */
520 uint16_t eeprom_read_word (const uint16_t *__p) __ATTR_PURE__;
521
522 /** \ingroup avr_eeprom
523 Read one 32-bit double word (little endian) from EEPROM address \a __p.
524 */
525 uint32_t eeprom_read_dword (const uint32_t *__p) __ATTR_PURE__;
526
527 /** \ingroup avr_eeprom
528 Read one float value (little endian) from EEPROM address \a __p.
529 */
530 float eeprom_read_float (const float *__p) __ATTR_PURE__;
531
532 /** \ingroup avr_eeprom
533 Read a block of \a __n bytes from EEPROM address \a __src to SRAM
534 \a __dst.
535 */
536 void eeprom_read_block (void *__dst, const void *__src, size_t __n);
537
538
539 /** \ingroup avr_eeprom
540 Write a byte \a __value to EEPROM address \a __p.
541 */
542 void eeprom_write_byte (uint8_t *__p, uint8_t __value);
543
544 /** \ingroup avr_eeprom
545 Write a word \a __value to EEPROM address \a __p.
546 */
547 void eeprom_write_word (uint16_t *__p, uint16_t __value);
548
549 /** \ingroup avr_eeprom
550 Write a 32-bit double word \a __value to EEPROM address \a __p.
551 */
552 void eeprom_write_dword (uint32_t *__p, uint32_t __value);
553
554 /** \ingroup avr_eeprom
555 Write a float \a __value to EEPROM address \a __p.
556 */
557 void eeprom_write_float (float *__p, float __value);
558
559 /** \ingroup avr_eeprom
560 Write a block of \a __n bytes to EEPROM address \a __dst from \a __src.
561 \note The argument order is mismatch with common functions like strcpy().
562 */
563 void eeprom_write_block (const void *__src, void *__dst, size_t __n);
564
565
566 /** \ingroup avr_eeprom
567 Update a byte \a __value to EEPROM address \a __p.
568 */
569 void eeprom_update_byte (uint8_t *__p, uint8_t __value);
570
571 /** \ingroup avr_eeprom
572 Update a word \a __value to EEPROM address \a __p.
573 */
574 void eeprom_update_word (uint16_t *__p, uint16_t __value);
575
576 /** \ingroup avr_eeprom
577 Update a 32-bit double word \a __value to EEPROM address \a __p.
578 */
579 void eeprom_update_dword (uint32_t *__p, uint32_t __value);
580
581 /** \ingroup avr_eeprom
582 Update a float \a __value to EEPROM address \a __p.
583 */
584 void eeprom_update_float (float *__p, float __value);
585
586 /** \ingroup avr_eeprom
587 Update a block of \a __n bytes to EEPROM address \a __dst from \a __src.
588 \note The argument order is mismatch with common functions like strcpy().
589 */
590 void eeprom_update_block (const void *__src, void *__dst, size_t __n);
591
592
593 /** \name IAR C compatibility defines */
594 /*@{*/
595
596 /** \def _EEPUT
597 \ingroup avr_eeprom
598 Write a byte to EEPROM. Compatibility define for IAR C. */
599 #define _EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val))
600
601 /** \def __EEPUT
602 \ingroup avr_eeprom
603 Write a byte to EEPROM. Compatibility define for IAR C. */
604 #define __EEPUT(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val))
605
606 /** \def _EEGET
607 \ingroup avr_eeprom
608 Read a byte from EEPROM. Compatibility define for IAR C. */
609 #define _EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr))
610
611 /** \def __EEGET
612 \ingroup avr_eeprom
613 Read a byte from EEPROM. Compatibility define for IAR C. */
614 #define __EEGET(var, addr) (var) = eeprom_read_byte ((const uint8_t *)(addr))
615
616 /*@}*/
617
618 #ifdef __cplusplus
619 }
620 #endif
621
622 #endif /* !__ASSEMBLER__ */
623 #endif /* E2END || defined(__DOXYGEN__) || defined(__COMPILING_AVR_LIBC__) */
624 #endif /* !_AVR_EEPROM_H_ */

Automatically generated by Doxygen 1.8.3.1 on Sat Sep 14 2013.