source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/hardware/tools/avr/avr/include/avr/common.h @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 3 years ago

Adding new version

File size: 7.9 KB
Line 
1/* Copyright (c) 2007 Eric B. Weddington
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
10   * Redistributions in binary form must reproduce the above copyright
11     notice, this list of conditions and the following disclaimer in
12     the documentation and/or other materials provided with the
13     distribution.
14
15   * Neither the name of the copyright holders nor the names of
16     contributors may be used to endorse or promote products derived
17     from this software without specific prior written permission.
18
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  POSSIBILITY OF SUCH DAMAGE. */
30
31/* $Id$ */
32
33
34#ifndef _AVR_COMMON_H
35#define _AVR_COMMON_H
36
37#include <avr/sfr_defs.h>
38
39/*
40This purpose of this header is to define registers that have not been
41previously defined in the individual device IO header files, and to define
42other symbols that are common across AVR device families.
43
44This file is designed to be included in <avr/io.h> after the individual
45device IO header files, and after <avr/sfr_defs.h>
46
47*/
48
49/*------------ Registers Not Previously Defined ------------*/
50
51/*
52These are registers that are not previously defined in the individual
53IO header files, OR they are defined here because they are used in parts of
54avr-libc even if a device is not selected but a general architecture has
55been selected.
56*/
57
58
59/*
60Stack pointer register.
61
62AVR architecture 1 has no RAM, thus no stack pointer.
63
64All other architectures do have a stack pointer.  Some devices have only
65less than 256 bytes of possible RAM locations (128 Bytes of SRAM
66and no option for external RAM), thus SPH is officially "reserved"
67for them.
68*/
69#if __AVR_ARCH__ >= 100
70#  ifndef SPL
71#    define SPL _SFR_MEM8(0x3D)
72#  endif
73#  ifndef SPH
74#    define SPH _SFR_MEM8(0x3E)
75#  endif
76#  ifndef SP
77#    define SP _SFR_MEM16(0x3D)
78#  endif
79#elif __AVR_ARCH__ != 1
80#  ifndef SPL
81#    define SPL _SFR_IO8(0x3D)
82#  endif
83#  if XRAMEND < 0x100 && !defined(__COMPILING_AVR_LIBC__)
84#    ifndef SP
85#      define SP  _SFR_IO8(0x3D)
86#    endif
87#  else
88#    ifndef SP
89#      define SP  _SFR_IO16(0x3D)
90#    endif
91#    ifndef SPH
92#      define SPH _SFR_IO8(0x3E)
93#    endif
94#  endif /* XRAMEND < 0x100 && !defined(__COMPILING_AVR_LIBC__) */
95#endif /* __AVR_ARCH__ != 1 */
96
97
98/* Status Register */
99#ifndef SREG
100#  if __AVR_ARCH__ >= 100
101#    define SREG _SFR_MEM8(0x3F)
102#  else
103#    define SREG _SFR_IO8(0x3F)
104#  endif
105#endif
106
107
108/* SREG bit definitions */
109#ifndef SREG_C
110#  define SREG_C  (0)
111#endif
112#ifndef SREG_Z
113#  define SREG_Z  (1)
114#endif
115#ifndef SREG_N
116#  define SREG_N  (2)
117#endif
118#ifndef SREG_V
119#  define SREG_V  (3)
120#endif
121#ifndef SREG_S
122#  define SREG_S  (4)
123#endif
124#ifndef SREG_H
125#  define SREG_H  (5)
126#endif
127#ifndef SREG_T
128#  define SREG_T  (6)
129#endif
130#ifndef SREG_I
131#  define SREG_I  (7)
132#endif
133
134
135#if defined(__COMPILING_AVR_LIBC__)
136
137/* AVR 6 Architecture */
138#  if __AVR_ARCH__ == 6
139#    ifndef EIND
140#      define EIND  _SFR_IO8(0X3C)
141#    endif
142/* XMEGA Architectures */
143#  elif __AVR_ARCH__ >= 100
144#    ifndef EIND
145#      define EIND  _SFR_MEM8(0x3C)
146#    endif
147#  endif
148
149/*
150Only few devices come without EEPROM.  In order to assemble the
151EEPROM library components without defining a specific device, we
152keep the EEPROM-related definitions here.
153*/
154
155/* EEPROM Control Register */
156#  ifndef EECR
157#    define EECR   _SFR_IO8(0x1C)
158#  endif
159
160/* EEPROM Data Register */
161#  ifndef EEDR
162#    define EEDR   _SFR_IO8(0x1D)
163#  endif
164
165/* EEPROM Address Register */
166#  ifndef EEAR
167#    define EEAR   _SFR_IO16(0x1E)
168#  endif
169#  ifndef EEARL
170#    define EEARL  _SFR_IO8(0x1E)
171#  endif
172#  ifndef EEARH
173#    define EEARH  _SFR_IO8(0x1F)
174#  endif
175
176/* EEPROM Control Register bits */
177#  ifndef EERE
178#    define EERE   (0)
179#  endif
180#  ifndef EEWE
181#    define EEWE   (1)
182#  endif
183#  ifndef EEMWE
184#    define EEMWE  (2)
185#  endif
186#  ifndef EERIE
187#    define EERIE  (3)
188#  endif
189
190
191/* RAM Page Z Select Register   */
192#ifndef RAMPZ
193#  if     defined(__AVR_HAVE_RAMPZ__) && __AVR_HAVE_RAMPZ__
194#    if     __AVR_ARCH__ >= 100
195#      define RAMPZ     _SFR_MEM8(0x3B)
196#    else
197#      define RAMPZ     _SFR_IO8(0x3B)
198#    endif
199#  endif
200#endif
201
202#endif /* __COMPILING_AVR_LIBC__ */
203
204
205
206/*------------ Common Symbols ------------*/
207
208/*
209Generic definitions for registers that are common across multiple AVR devices
210and families.
211*/
212
213/* Pointer registers definitions */
214#if __AVR_ARCH__ != 1  /* avr1 does not have X and Y pointers */
215#  define XL  r26
216#  define XH  r27
217#  define YL  r28
218#  define YH  r29
219#endif /* #if __AVR_ARCH__ != 1 */
220#define ZL  r30
221#define ZH  r31
222
223
224/* Status Register */
225#if defined(SREG)
226#  define AVR_STATUS_REG   SREG
227#  if __AVR_ARCH__ >= 100
228#    define AVR_STATUS_ADDR  _SFR_MEM_ADDR(SREG)
229#  else
230#    define AVR_STATUS_ADDR  _SFR_IO_ADDR(SREG)
231#  endif
232#endif
233
234/* Stack Pointer (combined) Register */
235#if defined(SP)
236#  define AVR_STACK_POINTER_REG   SP
237#  if __AVR_ARCH__ >= 100
238#    define AVR_STACK_POINTER_ADDR  _SFR_MEM_ADDR(SP)
239#  else
240#    define AVR_STACK_POINTER_ADDR  _SFR_IO_ADDR(SP)
241#  endif
242#endif
243
244/* Stack Pointer High Register */
245#if defined(SPH)
246#  define _HAVE_AVR_STACK_POINTER_HI 1
247#  define AVR_STACK_POINTER_HI_REG   SPH
248#  if __AVR_ARCH__ >= 100
249#    define AVR_STACK_POINTER_HI_ADDR  _SFR_MEM_ADDR(SPH)
250#  else
251#    define AVR_STACK_POINTER_HI_ADDR  _SFR_IO_ADDR(SPH)
252#  endif
253#endif
254
255/* Stack Pointer Low Register */
256#if defined(SPL)
257#  define AVR_STACK_POINTER_LO_REG   SPL
258#  if __AVR_ARCH__ >= 100
259#    define AVR_STACK_POINTER_LO_ADDR  _SFR_MEM_ADDR(SPL)
260#  else
261#    define AVR_STACK_POINTER_LO_ADDR  _SFR_IO_ADDR(SPL)
262#  endif
263#endif
264
265/* RAMPD Register */
266#if defined(RAMPD)
267#  define AVR_RAMPD_REG   RAMPD
268#  if __AVR_ARCH__ >= 100
269#    define AVR_RAMPD_ADDR  _SFR_MEM_ADDR(RAMPD)
270#  else
271#    define AVR_RAMPD_ADDR  _SFR_IO_ADDR(RAMPD)
272#  endif
273#endif
274
275/* RAMPX Register */
276#if defined(RAMPX)
277#  define AVR_RAMPX_REG   RAMPX
278#  if __AVR_ARCH__ >= 100
279#    define AVR_RAMPX_ADDR  _SFR_MEM_ADDR(RAMPX)
280#  else
281#    define AVR_RAMPX_ADDR  _SFR_IO_ADDR(RAMPX)
282#  endif
283#endif
284
285/* RAMPY Register */
286#if defined(RAMPY)
287#  define AVR_RAMPY_REG   RAMPY
288#  if __AVR_ARCH__ >= 100
289#    define AVR_RAMPY_ADDR  _SFR_MEM_ADDR(RAMPY)
290#  else
291#    define AVR_RAMPY_ADDR  _SFR_IO_ADDR(RAMPY)
292#  endif
293#endif
294
295/* RAMPZ Register */
296#if defined(RAMPZ)
297#  define AVR_RAMPZ_REG   RAMPZ
298#  if __AVR_ARCH__ >= 100
299#    define AVR_RAMPZ_ADDR  _SFR_MEM_ADDR(RAMPZ)
300#  else
301#    define AVR_RAMPZ_ADDR  _SFR_IO_ADDR(RAMPZ)
302#  endif
303#endif
304
305/* Extended Indirect Register */
306#if defined(EIND)
307#  define AVR_EXTENDED_INDIRECT_REG   EIND
308#  if __AVR_ARCH__ >= 100
309#    define AVR_EXTENDED_INDIRECT_ADDR  _SFR_MEM_ADDR(EIND)
310#  else
311#    define AVR_EXTENDED_INDIRECT_ADDR  _SFR_IO_ADDR(EIND)
312#  endif
313#endif
314
315/*------------ Workaround to old compilers (4.1.2 and earlier)  ------------*/
316
317#ifndef __AVR_HAVE_MOVW__
318# if  defined(__AVR_ENHANCED__) && __AVR_ENHANCED__
319#  define __AVR_HAVE_MOVW__ 1
320# endif
321#endif
322
323#ifndef __AVR_HAVE_LPMX__
324# if  defined(__AVR_ENHANCED__) && __AVR_ENHANCED__
325#  define __AVR_HAVE_LPMX__ 1
326# endif
327#endif
328
329#ifndef __AVR_HAVE_MUL__
330# if  defined(__AVR_ENHANCED__) && __AVR_ENHANCED__
331#  define __AVR_HAVE_MUL__ 1
332# endif
333#endif
334
335#endif /* _AVR_COMMON_H */
Note: See TracBrowser for help on using the repository browser.