root / trunk / code / projects / test / testeeprom.c @ 902
History | View | Annotate | Download (1.96 KB)
1 |
/** @file testeeprom.c
|
---|---|
2 |
* @brief tests the eeprom code
|
3 |
*
|
4 |
* stores and retrives a value, then sets it back to what it was
|
5 |
*/
|
6 |
#include <dragonfly_lib.h> |
7 |
#include "eeprom.h" |
8 |
|
9 |
#define ADDR 0 |
10 |
|
11 |
int testeeprom(void) { |
12 |
unsigned char data, data2; |
13 |
int ret;
|
14 |
int worked=1; |
15 |
|
16 |
dragonfly_init(ALL_ON); |
17 |
|
18 |
/* read whats there */
|
19 |
ret = eeprom_get_byte(ADDR, &data); |
20 |
|
21 |
if(ret) {
|
22 |
usb_puts("Error reading intial value! return code: ");
|
23 |
usb_puti(ret); |
24 |
usb_puts(" data: ");
|
25 |
usb_puti(data); |
26 |
usb_puts("\r\n");
|
27 |
worked=0;
|
28 |
} |
29 |
else {
|
30 |
usb_puts("data was: ");
|
31 |
usb_puti(data); |
32 |
usb_puts("\r\n");
|
33 |
} |
34 |
|
35 |
/* write something new */
|
36 |
|
37 |
ret = eeprom_put_byte(ADDR, 123);
|
38 |
if(ret) {
|
39 |
usb_puts("Error writing data! return code: ");
|
40 |
usb_puti(ret); |
41 |
usb_puts("\r\n");
|
42 |
worked=0;
|
43 |
} |
44 |
else {
|
45 |
usb_puts("wrote 123\r\n");
|
46 |
} |
47 |
|
48 |
|
49 |
/* check if tis really there */
|
50 |
|
51 |
ret = eeprom_get_byte(ADDR, &data2); |
52 |
|
53 |
if(ret) {
|
54 |
usb_puts("Error reading second value! return code: ");
|
55 |
usb_puti(ret); |
56 |
usb_puts(" data: ");
|
57 |
usb_puti(data2); |
58 |
usb_puts("\r\n");
|
59 |
worked=0;
|
60 |
} |
61 |
else {
|
62 |
if(data2==123) { |
63 |
usb_puts("data write and re-read worked!\r\n");
|
64 |
} |
65 |
else {
|
66 |
usb_puts("data re-read returned 0 but data was ");
|
67 |
usb_puti(data2); |
68 |
usb_puts("\r\n");
|
69 |
worked=0;
|
70 |
} |
71 |
} |
72 |
|
73 |
|
74 |
/* restore old value */
|
75 |
|
76 |
ret = eeprom_put_byte(ADDR, 123);
|
77 |
if(ret) {
|
78 |
usb_puts("Error writing data the second time! return code: ");
|
79 |
usb_puti(ret); |
80 |
usb_puts("\r\n");
|
81 |
worked=0;
|
82 |
} |
83 |
else {
|
84 |
usb_puts("re-wrote original data: ");
|
85 |
usb_puti(data); |
86 |
usb_puts("\r\n");
|
87 |
} |
88 |
|
89 |
return worked;
|
90 |
} |