1
/* $Id: eeprom-1.c,v 1.2.2.3 2008/04/04 08:14:45 dmix Exp $ */
3
#include <avr/eeprom.h>
7
/* Note: GCC permits arithmetic with 'void *'. */
12
#define MAXLEN (RAMEND > 0x15F ? 260 : (RAMEND - 0x60 - 30))
13
unsigned char s[E2END > MAXLEN ? MAXLEN : E2END];
15
/* Fill all EEPROM. */
16
for (p = 0; p <= (void *)E2END; p++)
17
eeprom_write_byte (p, ~(int)p);
20
for (p = 0; p <= (void *)E2END; p++)
21
if (eeprom_read_byte (p) != (~(int)p & 0xFF))
25
for (p = 0; p <= (void *)E2END - 1; p += 2) {
26
if (eeprom_read_word (p)
27
!= ((~(unsigned)p & 0xFF) | (~(unsigned)(p+1) & 0xFF) << 8))
33
/* Read double words. */
34
for (p = 0; p <= (void *)E2END - 3; p += 4) {
35
if (eeprom_read_dword (p)
36
!= ((~(unsigned)p & 0xFF)
37
| (~(unsigned)(p+1) & 0xFF) << 8
38
| (unsigned long)(~(unsigned)(p+2) & 0xFF) << 16
39
| (unsigned long)(~(unsigned)(p+3) & 0xFF) << 24))
46
for (p = 0; p <= (void *)E2END; ) {
48
if ( (n = E2END + 1 - (unsigned)p) > sizeof(s))
50
eeprom_read_block (s, p, n);
51
for (i = 0; i < n; i++) {
52
if (s[i] != (~(int)p & 0xFF))
58
/* Write only 1 byte. */
59
eeprom_write_byte ((unsigned char *)5, 1);
60
for (p = 0; p <= (void *)E2END; p++) {
62
&& eeprom_read_byte (p) != (~(int)p & 0xFF))
67
if (eeprom_read_byte ((unsigned char *)5) != 1)
70
/* Write only 1 word. */
71
/* Avr-gcc 4.2.2 produces incorrect code: the comparison of address
72
with 5 and 6 values is omited. In result exit with error.
73
Versions 3.3.6, 3.4.6, 4.0.4, 4.1.2, 4.2.3, 4.3.0(pre) give
74
correct code and are simulated OK. */
75
eeprom_write_word ((unsigned *)5, 0x1234);
76
for (p = 0; p <= (void *)E2END; p++) {
79
&& eeprom_read_byte (p) != (~(int)p & 0xFF))
84
if (eeprom_read_word ((unsigned *)5) != 0x1234)
87
/* Write only 1 double word. */
88
eeprom_write_dword ((unsigned long *)5, 0x12345678);
89
for (p = 0; p <= (void *)E2END; p++) {
90
if (((unsigned)p < 5 || (unsigned)p > 8)
91
&& eeprom_read_byte (p) != (~(int)p & 0xFF))
96
if (eeprom_read_dword ((unsigned long *)5) != 0x12345678)
100
eeprom_write_block ("\x90\xAB\xCD\xEF\x01", (void *)5, 5);
101
for (p = 0; p <= (void *)E2END; p++) {
102
if (((unsigned)p < 5 || (unsigned)p > 9)
103
&& eeprom_read_byte (p) != (~(int)p & 0xFF))
108
eeprom_read_block (s, (const void *)5, 5);
109
if (memcmp (s, "\x90\xAB\xCD\xEF\x01", 3))