1 /* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
\r
3 /*This file is prepared for Doxygen automatic documentation generation.*/
\r
4 /*! \file *********************************************************************
\r
6 * \brief NEWLIB_ADDONS miscellaneous macros include file for AVR32.
\r
8 * - Compiler: GNU GCC for AVR32
\r
9 * - Supported devices: All AVR32 devices can be used.
\r
12 * \author Atmel Corporation: http://www.atmel.com \n
\r
13 * Support and FAQ: http://support.atmel.no/
\r
15 ******************************************************************************/
\r
17 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
\r
19 * Redistribution and use in source and binary forms, with or without
\r
20 * modification, are permitted provided that the following conditions are met:
\r
22 * 1. Redistributions of source code must retain the above copyright notice, this
\r
23 * list of conditions and the following disclaimer.
\r
25 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
26 * this list of conditions and the following disclaimer in the documentation
\r
27 * and/or other materials provided with the distribution.
\r
29 * 3. The name of Atmel may not be used to endorse or promote products derived
\r
30 * from this software without specific prior written permission.
\r
32 * 4. This software may only be redistributed and used in connection with an Atmel
\r
35 * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
\r
36 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
\r
37 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
\r
38 * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
\r
39 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
\r
40 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
\r
41 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
\r
42 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
\r
43 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
\r
44 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
\r
48 #ifndef __AVR32_NEWLIB_ADDONS_IO_H__
\r
49 #define __AVR32_NEWLIB_ADDONS_IO_H__
\r
56 typedef unsigned int u32;
\r
58 #define __raw_writeb(v,a) (*(volatile unsigned char *)(a) = (v))
\r
59 #define __raw_writew(v,a) (*(volatile unsigned short *)(a) = (v))
\r
60 #define __raw_writel(v,a) (*(volatile unsigned int *)(a) = (v))
\r
62 #define __raw_readb(a) (*(volatile unsigned char *)(a))
\r
63 #define __raw_readw(a) (*(volatile unsigned short *)(a))
\r
64 #define __raw_readl(a) (*(volatile unsigned int *)(a))
\r
66 /* As long as I/O is only performed in P4 (or possibly P3), we're safe */
\r
67 #define writeb(v,a) __raw_writeb(v,a)
\r
68 #define writew(v,a) __raw_writew(v,a)
\r
69 #define writel(v,a) __raw_writel(v,a)
\r
71 #define readb(a) __raw_readb(a)
\r
72 #define readw(a) __raw_readw(a)
\r
73 #define readl(a) __raw_readl(a)
\r
75 /* Memory segments when segmentation is enabled */
\r
76 #define P0SEG 0x00000000
\r
77 #define P1SEG 0x80000000
\r
78 #define P2SEG 0xa0000000
\r
79 #define P3SEG 0xc0000000
\r
80 #define P4SEG 0xe0000000
\r
82 /* Returns the privileged segment base of a given address */
\r
83 #define PXSEG(a) (((unsigned long)(a)) & 0xe0000000)
\r
85 /* Returns the physical address of a PnSEG (n=1,2) address */
\r
86 #define PHYSADDR(a) (((unsigned long)(a)) & 0x1fffffff)
\r
89 * Map an address to a certain privileged segment
\r
91 #define P1SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P1SEG))
\r
92 #define P2SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P2SEG))
\r
93 #define P3SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P3SEG))
\r
94 #define P4SEGADDR(a) ((__typeof__(a))(((unsigned long)(a) & 0x1fffffff) | P4SEG))
\r
97 #define cached(addr) P1SEGADDR(addr)
\r
98 #define uncached(addr) P2SEGADDR(addr)
\r
99 #define physaddr(addr) PHYSADDR(addr)
\r
101 #define BF(field, value) \
\r
104 unsigned : 32 - field ## _OFFSET - field ## _SIZE ; \
\r
105 unsigned long __val: field ## _SIZE ; \
\r
107 unsigned long __ul; \
\r
110 __tmp.__val = value; \
\r
113 #define BF_D(field, value) \
\r
116 unsigned long long : 64 - field ## _OFFSET - field ## _SIZE ; \
\r
117 unsigned long long __val: field ## _SIZE ; \
\r
119 unsigned long long __ul; \
\r
122 __tmp.__val = value; \
\r
125 #define BFINS(var, field, value) \
\r
128 unsigned : 32 - field ## _OFFSET - field ## _SIZE ; \
\r
129 unsigned long __val: field ## _SIZE ; \
\r
131 unsigned long __ul; \
\r
133 __tmp.__ul = var; \
\r
134 __tmp.__val = value; \
\r
137 #define BFEXT(var, field) \
\r
140 unsigned : 32 - field ## _OFFSET - field ## _SIZE ; \
\r
141 unsigned long __val: field ## _SIZE ; \
\r
143 unsigned long __ul; \
\r
145 __tmp.__ul = var; \
\r
148 #define BFINS_D(var, field, value) \
\r
151 unsigned long long : 64 - field ## _OFFSET - field ## _SIZE ; \
\r
152 unsigned long long __val: field ## _SIZE ; \
\r
154 unsigned long long __ul; \
\r
156 __tmp.__ul = var; \
\r
157 __tmp.__val = value; \
\r
160 #define BFEXT_D(var, field) \
\r
163 unsigned long long : 64 - field ## _OFFSET - field ## _SIZE ; \
\r
164 unsigned long long __val: field ## _SIZE ; \
\r
166 unsigned long long __ul; \
\r
168 __tmp.__ul = var; \
\r