Project

General

Profile

Statistics
| Revision:

root / branches / wireless / code / projects / unit_tests / test_eeprom.c @ 1935

History | View | Annotate | Download (1.93 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
    
17
    /* read whats there */
18
    ret = eeprom_get_byte(ADDR, &data);
19
    
20
    if(ret) {
21
        usb_puts("Error reading intial value! return code: ");
22
        usb_puti(ret);
23
        usb_puts(" data: ");
24
        usb_puti(data);
25
        usb_puts("\r\n");
26
        worked=0;
27
    }
28
    else {
29
        usb_puts("data was: ");
30
        usb_puti(data);
31
        usb_puts("\r\n");
32
    }
33
    
34
    /* write something new */
35
    
36
    ret = eeprom_put_byte(ADDR, 123);
37
    if(ret) {
38
        usb_puts("Error writing data! return code: ");
39
        usb_puti(ret);
40
        usb_puts("\r\n");
41
        worked=0;
42
    }
43
    else {
44
        usb_puts("wrote 123\r\n");
45
    }
46
    
47
    
48
    /* check if tis really there */
49
    
50
    ret = eeprom_get_byte(ADDR, &data2);
51
    
52
    if(ret) {
53
        usb_puts("Error reading second value! return code: ");
54
        usb_puti(ret);
55
        usb_puts(" data: ");
56
        usb_puti(data2);
57
        usb_puts("\r\n");
58
        worked=0;
59
    }
60
    else {
61
        if(data2==123) {
62
            usb_puts("data write and re-read worked!\r\n");
63
        }
64
        else {
65
            usb_puts("data re-read returned 0 but data was ");
66
            usb_puti(data2);
67
            usb_puts("\r\n");
68
            worked=0;
69
        }
70
    }
71
    
72
    
73
    /* restore old value */
74
    
75
    ret = eeprom_put_byte(ADDR, 123);
76
    if(ret) {
77
        usb_puts("Error writing data the second time! return code: ");
78
        usb_puti(ret);
79
        usb_puts("\r\n");
80
        worked=0;
81
    }
82
    else {
83
        usb_puts("re-wrote original data: ");
84
        usb_puti(data);
85
        usb_puts("\r\n");
86
    }
87
    
88
    return worked;
89
}