Project

General

Profile

Statistics
| Revision:

root / branches / ir_branch / code / projects / libdragonfly / eeprom.c @ 1572

History | View | Annotate | Download (1.76 KB)

1
#include <avr/io.h>
2
#include "eeprom.h"
3

    
4
int eeprom_put_byte(unsigned int uiAddress, unsigned char ucData) {
5
    /* Wait for completion of previous write */
6
    while(EECR & (1<<EEWE));
7
    /* Set up address and data registers */
8
    EEAR = uiAddress;
9
    EEDR = ucData;
10
    /* Write logical one to EEMWE */
11
    EECR |= (1<<EEMWE);
12
    /* Start eeprom write by setting EEWE */
13
    EECR |= (1<<EEWE);
14
    
15
    return 0;
16
}
17

    
18
int eeprom_get_byte(unsigned int uiAddress, unsigned char *byte) {
19
    /* Wait for completion of previous write */
20
    while(EECR & (1<<EEWE));
21
    /* Set up address register */
22
    EEAR = uiAddress;
23
    /* Start eeprom read by writing EERE */
24
    EECR |= (1<<EERE);
25
    /* get data from data register */
26
    *byte=EEDR;
27
    
28
    return 0;
29
}
30

    
31

    
32
unsigned char get_robotid(void) {
33
    unsigned char c0, c1, c2;
34
    
35
    eeprom_get_byte(EEPROM_ROBOT_ID_ADDR, &c0);
36
    eeprom_get_byte(EEPROM_ROBOT_ID_ADDR+1, &c1);
37
    eeprom_get_byte(EEPROM_ROBOT_ID_ADDR+2, &c2);
38
    if(c0 == 'I' && c1 == 'D')
39
        return c2;
40
    else
41
        return 0xFF;
42
}
43

    
44
unsigned char get_bom_type(void) {
45
    unsigned char c0, c1, c2, c3;
46
    
47
    eeprom_get_byte(EEPROM_BOM_TYPE_ADDR, &c0);
48
    eeprom_get_byte(EEPROM_BOM_TYPE_ADDR+1, &c1);
49
    eeprom_get_byte(EEPROM_BOM_TYPE_ADDR+2, &c2);
50
    eeprom_get_byte(EEPROM_BOM_TYPE_ADDR+3, &c3);
51
    if(c0 == 'B' && c1 == 'O' && c2 == 'M')
52
        return c3;
53
    else
54
        return 0xFF;
55
}
56

    
57
unsigned char get_ir_offset(void) {
58
    unsigned char c0, c1, c2;
59
    
60
    eeprom_get_byte(EEPROM_IR_OFFSET_ADDR, &c0);
61
    eeprom_get_byte(EEPROM_IR_OFFSET_ADDR+1, &c1);
62
    eeprom_get_byte(EEPROM_IR_OFFSET_ADDR+2, &c2);
63
    if(c0 == 'I' && c1 == 'R')
64
        return c2;
65
    else
66
        return 0xFF;
67
}
68