-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheeprom.c
122 lines (109 loc) · 2.66 KB
/
eeprom.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
* Copyright (c) 2007, Kalopa Research Limited. All rights
* reserved. Unpublished rights reserved under the copyright laws
* of the United States and/or the Republic of Ireland.
*
* The software contained herein is proprietary to and embodies the
* confidential technology of Kalopa Research Limited. Possession,
* use, duplication or dissemination of the software and media is
* authorized only pursuant to a valid written license from Kalopa
* Research Limited.
*
* RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the
* U.S. Government is subject to restrictions as set forth in
* Subparagraph (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19,
* as applicable.
*
* THIS SOFTWARE IS PROVIDED BY KALOPA RESEARCH LIMITED "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KALOPA
* RESEARCH LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* ABSTRACT
* This file provides mechanisms for accessing configuration data
* from the system EEPROM. It also provides a mechanism for updating
* the EEPROM values via the serial port.
*/
#include <stdio.h>
#include <avr.h>
#include "otto.h"
uchar_t eeprom_ok;
uint_t eeprom_addr = 0;
/*
*
*/
void
eeprom_data_test()
{
eeprom_ok = (eeprom_rdint(EEPROM_MAGIC_ADDR) == EEPROM_MAGIC_CODE);
}
/*
* Copy a block of data from the EEPROM to RAM.
*/
void
eeprom_copy(int srcaddr, void *dst, int len)
{
char *dp = (char *)dst;
while (len--)
*dp++ = _rdeeprom(srcaddr++);
}
/*
* Read an int (16 bits) from the EEPROM.
*/
uint_t
eeprom_rdint(int addr)
{
uint_t val;
val = _rdeeprom(addr);
val |= _rdeeprom(addr + 1) << 8;
return(val);
}
/*
* Write an int (16 bits) to the EEPROM.
*/
void
eeprom_wrint(int addr, uint_t val)
{
_wreeprom(addr, val & 0xff);
_wreeprom(addr + 1, (val >> 8) & 0xff);
}
/*
*
*/
uint_t
eeprom_getaddr()
{
return(eeprom_addr);
}
/*
*
*/
void
eeprom_setaddr(uint_t val)
{
eeprom_addr = val;
}
/*
*
*/
uint_t
eeprom_read()
{
return(_rdeeprom(eeprom_addr++));
}
/*
*
*/
void
eeprom_write(uint_t val)
{
_wreeprom(eeprom_addr++, val & 0xff);
}