~ubuntu-branches/ubuntu/wily/avr-libc/wily-proposed

« back to all changes in this revision

Viewing changes to libc/misc/eeprom.S

  • Committer: Bazaar Package Importer
  • Author(s): Hakan Ardo
  • Date: 2002-04-15 14:53:38 UTC
  • Revision ID: james.westby@ubuntu.com-20020415145338-c8hi0tn5bx74w7o3
Tags: upstream-20020203
ImportĀ upstreamĀ versionĀ 20020203

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   eeprom.S
 
3
 
 
4
   Contributors:
 
5
     Created by Marek Michalkiewicz <marekm@linux.org.pl>
 
6
 
 
7
   THIS SOFTWARE IS NOT COPYRIGHTED
 
8
 
 
9
   This source code is offered for use in the public domain.  You may
 
10
   use, modify or distribute it freely.
 
11
 
 
12
   This code is distributed in the hope that it will be useful, but
 
13
   WITHOUT ANY WARRANTY.  ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
 
14
   DISCLAIMED.  This includes but is not limited to warranties of
 
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
16
 */
 
17
 
 
18
#include "macros.inc"
 
19
#include "ctoasm.inc"
 
20
 
 
21
/* the same library is used for 2313 and 8515 for now -
 
22
   I hope writing 0 to non-existent EEARH doesn't hurt... */
 
23
#ifndef EEARH
 
24
#define EEARH (EEARL+1)
 
25
#endif
 
26
 
 
27
#define addr_hi rP0
 
28
#define addr_lo rP1
 
29
#define res_hi rP0
 
30
#define res_lo rP1
 
31
 
 
32
#ifdef L_eeprom_rb
 
33
/* read one byte from EEPROM */
 
34
/* unsigned char eeprom_rb(unsigned int addr); */
 
35
/* addr = r25:r24, result = r25(=0):r24 */
 
36
 
 
37
        .section .text
 
38
        .global _U(eeprom_rb)
 
39
 
 
40
_U(eeprom_rb):
 
41
        sbic    EECR, EEWE
 
42
        rjmp    _U(eeprom_rb)   /* make sure EEPROM is ready */
 
43
#ifdef EEARH
 
44
        out     EEARH, addr_hi
 
45
#endif
 
46
        out     EEARL, addr_lo
 
47
        sbi     EECR, EERE
 
48
        clr     res_hi          /* gcc wants result extended to "int"? */
 
49
        in      res_lo, EEDR
 
50
        ret
 
51
#endif /* L_eeprom_rb */
 
52
 
 
53
#ifdef L_eeprom_rw
 
54
/* read a little endian 16-bit word from EEPROM */
 
55
/* unsigned int eeprom_rw(unsigned int addr); */
 
56
/* addr = r25:r24, result = r25:r24 */
 
57
 
 
58
        .global _U(eeprom_rw)
 
59
 
 
60
_U(eeprom_rw):
 
61
        sbic    EECR, EEWE
 
62
        rjmp    _U(eeprom_rw)   /* make sure EEPROM is ready */
 
63
#ifdef EEARH
 
64
        out     EEARH, addr_hi
 
65
#endif
 
66
        out     EEARL, addr_lo
 
67
        sbi     EECR, EERE
 
68
        adiw    addr_lo, 1
 
69
        in      __tmp_reg__, EEDR
 
70
#ifdef EEARH
 
71
        out     EEARH, addr_hi
 
72
#endif
 
73
        out     EEARL, addr_lo
 
74
        sbi     EECR, EERE
 
75
        mov     res_lo, __tmp_reg__
 
76
        in      res_hi, EEDR
 
77
        ret
 
78
#endif /* L_eeprom_rw */
 
79
 
 
80
#ifdef L_eeprom_wb
 
81
/* write a byte to EEPROM */
 
82
/* void eeprom_wb(unsigned int addr, unsigned char val); */
 
83
/* addr = r25:r24, val = r22 */
 
84
#define val rP3
 
85
 
 
86
        .global _U(eeprom_wb)
 
87
 
 
88
_U(eeprom_wb):
 
89
        sbic    EECR, EEWE
 
90
        rjmp    _U(eeprom_wb)   /* make sure EEPROM is ready */
 
91
#ifdef EEARH
 
92
        out     EEARH, addr_hi
 
93
#endif
 
94
        out     EEARL, addr_lo
 
95
        out     EEDR, val
 
96
        in      __tmp_reg__, SREG
 
97
        cli                     ; /* no ints between setting EEMWE and EEWE */
 
98
        sbi     EECR, EEMWE
 
99
        sbi     EECR, EEWE
 
100
        out     SREG, __tmp_reg__
 
101
        ret
 
102
#undef val
 
103
#endif /* L_eeprom_wb */
 
104
 
 
105
#undef addr_hi
 
106
#undef addr_lo
 
107
#undef res_hi
 
108
#undef res_lo
 
109
 
 
110
#define buf_hi rP0
 
111
#define buf_lo rP1
 
112
#define addr_hi rP2
 
113
#define addr_lo rP3
 
114
#define n_hi rP4
 
115
#define n_lo rP5
 
116
 
 
117
#ifdef L_eeprom_read_block
 
118
/* read a block of bytes from EEPROM */
 
119
/* void eeprom_read_block(void *buf, unsigned int addr, size_t n); */
 
120
/* buf = r25:r24, addr = r23:r22, n = r21:r20 */
 
121
 
 
122
        .global _U(eeprom_read_block)
 
123
 
 
124
_U(eeprom_read_block):
 
125
        cp      n_lo, __zero_reg__
 
126
        cpc     n_hi, __zero_reg__
 
127
        breq    eeprom_read_block_done
 
128
        LOAD_X(buf_lo, buf_hi)
 
129
eeprom_read_block_busy:
 
130
        sbic    EECR, EEWE
 
131
        rjmp    eeprom_read_block_busy  /* make sure EEPROM is ready */
 
132
eeprom_read_block_loop:
 
133
#ifdef EEARH
 
134
        out     EEARH, addr_hi
 
135
#endif
 
136
        out     EEARL, addr_lo
 
137
        sbi     EECR, EERE
 
138
        subi    addr_lo, lo8(-1)
 
139
        sbci    addr_hi, hi8(-1)
 
140
        in      __tmp_reg__, EEDR
 
141
        st      X+, __tmp_reg__
 
142
        subi    n_lo, lo8(1)
 
143
        sbci    n_hi, hi8(1)
 
144
        brne    eeprom_read_block_loop
 
145
eeprom_read_block_done:
 
146
        ret
 
147
#endif /* L_eeprom_read_block */
 
148