~ubuntu-branches/ubuntu/vivid/avr-libc/vivid

« back to all changes in this revision

Viewing changes to libc/misc/eewr_byte.S

  • Committer: Package Import Robot
  • Author(s): Hakan Ardo
  • Date: 2014-06-03 14:25:22 UTC
  • mfrom: (1.2.6)
  • Revision ID: package-import@ubuntu.com-20140603142522-76ia7366969f7jc2
Tags: 1:1.8.0+Atmel3.4.4-1
* New upstream release from Atmel-AVR-GNU-Toolchain v3.4.4
  (http://distribute.atmel.no/tools/opensource/Atmel-AVR-GNU-
  Toolchain/3.4.4/) (closes: #740391, #739953, #695514, #719635)
* Moved manpages to the 3avr section of /usr/share/man
* Added avr-man manpage (closes: #733939)
* Added build-arch and build-indep targets
* Moved build to binary-indep target
* Increased standards version to 3.9.5
* Added ${misc:Depends} dependency
* Applied upstream fix to make pgmspace.h ansi compatible (closes:
  #675759)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2009  Dmitry Xmelkov
2
 
   All rights reserved.
3
 
 
4
 
   Redistribution and use in source and binary forms, with or without
5
 
   modification, are permitted provided that the following conditions are met:
6
 
 
7
 
   * Redistributions of source code must retain the above copyright
8
 
     notice, this list of conditions and the following disclaimer.
9
 
   * Redistributions in binary form must reproduce the above copyright
10
 
     notice, this list of conditions and the following disclaimer in
11
 
     the documentation and/or other materials provided with the
12
 
     distribution.
13
 
   * Neither the name of the copyright holders nor the names of
14
 
     contributors may be used to endorse or promote products derived
15
 
     from this software without specific prior written permission.
16
 
 
17
 
   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18
 
   AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19
 
   IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20
 
   ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21
 
   LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22
 
   CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
 
   SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
 
   INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
 
   CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
 
   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
 
   POSSIBILITY OF SUCH DAMAGE.  */
28
 
 
29
 
/* $Id: eewr_byte.S 2024 2009-09-10 01:39:42Z dmix $    */
30
 
 
31
 
#ifndef __DOXYGEN
32
 
 
33
 
#include <avr/io.h>
34
 
 
35
 
#if     E2END && __AVR_ARCH__ > 1
36
 
 
37
 
#include <avr/eeprom.h>
38
 
#include "asmdef.h"
39
 
#include "eedef.h"
40
 
 
41
 
ENTRY   eeprom_write_byte
42
 
        mov     r18, r22
43
 
 
44
 
ENTRY   eeprom_write_r18
45
 
 
46
 
#if  __AVR_XMEGA__      /* -------------------------------------------- */
47
 
 
48
 
# ifndef CCP_IOREG_gc
49
 
#  define CCP_IOREG_gc  0xD8    /* IO Register Protection       */
50
 
# endif
51
 
# ifndef NVM_CMD_READ_EEPROM_gc
52
 
#  define NVM_CMD_READ_EEPROM_gc                0x06
53
 
# endif
54
 
# ifndef NVM_CMD_LOAD_EEPROM_BUFFER_gc
55
 
#  define NVM_CMD_LOAD_EEPROM_BUFFER_gc         0x33
56
 
# endif
57
 
# ifndef NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc
58
 
#  define NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc    0x35
59
 
# endif
60
 
# ifndef  NVM_CMD_ERASE_EEPROM_BUFFER_gc
61
 
#  define NVM_CMD_ERASE_EEPROM_BUFFER_gc        0x36
62
 
# endif
63
 
 
64
 
  ; Prepare base address of NVM.
65
 
        ldi     ZL, lo8(NVM_BASE)
66
 
        ldi     ZH, hi8(NVM_BASE)
67
 
 
68
 
  ; Wait until NVM is not busy.
69
 
1:      ldd     r19, Z + NVM_STATUS - NVM_BASE
70
 
        sbrc    r19, NVM_NVMBUSY_bp
71
 
        rjmp    1b
72
 
 
73
 
  ; Disable EEPROM mapping into data space.
74
 
        ldd     r19, Z + NVM_CTRLB - NVM_BASE
75
 
        andi    r19, ~NVM_EEMAPEN_bm
76
 
        std     Z + NVM_CTRLB - NVM_BASE, r19
77
 
 
78
 
  ; Check the clearance of EEPROM page buffer.
79
 
        ldd     r19, Z + NVM_STATUS - NVM_BASE
80
 
        sbrs    r19, NVM_EELOAD_bp
81
 
        rjmp    3f                      ; erase is not required
82
 
 
83
 
  ; Note that we have only four clock cycles to write to the CCP
84
 
  ; protected register NVM_CTRLA, after writing to CCP.  The 'ldi'
85
 
  ; instruction always takes one clock to execute and 'std' instruction takes
86
 
  ; two clock cycles.  We fall within the four cycles that the CCP leaves
87
 
  ; us to write the command execution start bit to the NVM_CTRLA
88
 
  ; register.  Note that r18 must be preserved until written to NVM_DATA0
89
 
 
90
 
  ; Issue EEPROM Buffer Erase:
91
 
        ldi     r19, NVM_CMD_ERASE_EEPROM_BUFFER_gc
92
 
        std     Z + NVM_CMD - NVM_BASE, r19
93
 
        ldi     r19, CCP_IOREG_gc
94
 
        out     CCP, r19
95
 
        ldi     r19, NVM_CMDEX_bm
96
 
        std     Z + NVM_CTRLA - NVM_BASE, r19
97
 
 
98
 
  ; Wait until NVM is not busy.
99
 
2:      ldd     r19, Z + NVM_STATUS - NVM_BASE
100
 
        sbrc    r19, NVM_NVMBUSY_bp
101
 
        rjmp    2b
102
 
 
103
 
  ; Issue EEPROM Buffer Load command.
104
 
3:      ldi     r19, NVM_CMD_LOAD_EEPROM_BUFFER_gc
105
 
        std     Z + NVM_CMD - NVM_BASE, r19
106
 
        std     Z + NVM_ADDR0 - NVM_BASE, addr_lo
107
 
        std     Z + NVM_ADDR1 - NVM_BASE, addr_hi
108
 
        std     Z + NVM_ADDR2 - NVM_BASE, __zero_reg__
109
 
        std     Z + NVM_DATA0 - NVM_BASE, r18
110
 
 
111
 
  ; Issue EEPROM Erase & Write command.
112
 
        ldi     r18, NVM_CMD_ERASE_WRITE_EEPROM_PAGE_gc
113
 
        std     Z + NVM_CMD - NVM_BASE, r18
114
 
        ldi     r18, CCP_IOREG_gc
115
 
        ldi     r19, NVM_CMDEX_bm
116
 
        out     CCP, r18
117
 
        std     Z + NVM_CTRLA - NVM_BASE, r19
118
 
 
119
 
  ; Increment address.
120
 
        adiw    addr_lo, 1
121
 
 
122
 
        ret
123
 
 
124
 
#else           /* ---------------------------------------------------- */
125
 
 
126
 
1:      sbic    _SFR_IO_ADDR (EECR), EEWE
127
 
        rjmp    1b
128
 
 
129
 
# if     defined (EEPM0) && defined (EEPM1)
130
 
        ; Set programming mode: erase and write.
131
 
        out     _SFR_IO_ADDR (EECR), __zero_reg__
132
 
# elif   defined (EEPM0) || defined (EEPM1)
133
 
#  error        /* Unknown EECR register.       */
134
 
# endif
135
 
 
136
 
# ifdef  EEARH
137
 
#  if     E2END > 0xFF
138
 
        out     _SFR_IO_ADDR (EEARH), addr_hi
139
 
#  else
140
 
        ; This is for chips like ATmega48: the EEAR8 bit must be cleaned.
141
 
        out     _SFR_IO_ADDR (EEARH), __zero_reg__
142
 
#  endif
143
 
# endif
144
 
        out     _SFR_IO_ADDR (EEARL), addr_lo
145
 
        out     _SFR_IO_ADDR (EEDR), r18
146
 
        in      __tmp_reg__, _SFR_IO_ADDR (SREG)
147
 
        cli
148
 
        sbi     _SFR_IO_ADDR (EECR), EEMWE
149
 
        sbi     _SFR_IO_ADDR (EECR), EEWE
150
 
        out     _SFR_IO_ADDR (SREG), __tmp_reg__
151
 
        adiw    addr_lo, 1
152
 
        ret
153
 
 
154
 
#endif          /* ---------------------------------------------------- */
155
 
 
156
 
ENDFUNC
157
 
 
158
 
#endif  /* E2END && __AVR_ARCH__ > 1 */
159
 
#endif  /* !__DOXYGEN__ */