Nut/OS  4.10.3
API Reference
avr32.h
Go to the documentation of this file.
00001 #ifndef _ARCH_AVR32_H_
00002 #define _ARCH_AVR32_H_
00003 
00040 /*This file is prepared for Doxygen automatic documentation generation.*/
00056 /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
00057  *
00058  * Redistribution and use in source and binary forms, with or without
00059  * modification, are permitted provided that the following conditions are met:
00060  *
00061  * 1. Redistributions of source code must retain the above copyright notice, this
00062  * list of conditions and the following disclaimer.
00063  *
00064  * 2. Redistributions in binary form must reproduce the above copyright notice,
00065  * this list of conditions and the following disclaimer in the documentation
00066  * and/or other materials provided with the distribution.
00067  *
00068  * 3. The name of Atmel may not be used to endorse or promote products derived
00069  * from this software without specific prior written permission.
00070  *
00071  * 4. This software may only be redistributed and used in connection with an Atmel
00072  * AVR product.
00073  *
00074  * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
00075  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
00076  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
00077  * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
00078  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
00079  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00080  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00081  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00082  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00083  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
00084  *
00085  */
00086 
00087 /*
00088 * $Log: avr32.h,v $
00089 *
00090 */
00091 
00092 #include <cfg/arch.h>
00093 
00094 /* AVR32 is big endian core */
00095 #if !defined(__BIG_ENDIAN__)
00096 #define __BIG_ENDIAN__
00097 #endif
00098 
00099 #ifdef __GNUC__
00100 # define CONST      const
00101 # define INLINE     inline
00102 #else
00103 # ifndef CONST
00104 #  define CONST      const
00105 # endif
00106 # ifndef INLINE
00107 #  define INLINE
00108 # endif
00109 #endif
00110 
00111 #define PSTR(p)    (p)
00112 #define PRG_RDB(p) (*((const char *)(p)))
00113 
00114 #define prog_char  const char
00115 #define PGM_P      prog_char *
00116 
00117 #define SIGNAL(x)  __attribute__((__interrupt__)) void x(void)
00118 #define RAMFUNC __attribute__ ((long_call, section (".ramfunc")))
00119 
00120 /* -------------------------------------------------------------------------
00121 * redefine main
00122 * ------------------------------------------------------------------------- */
00123 #if !defined(__cplusplus)
00124 # define main       NutAppMain
00125 #endif
00126 
00127 #define strlen_P(x)             strlen((char *)(x))
00128 #define strcpy_P(x,y)           strcpy(x,(char *)(y))
00129 
00130 #define strcmp_P(x, y)          strcmp((char *)(x), (char *)(y))
00131 #define memcpy_P(x, y, z)       memcpy(x, y, z)
00132 
00133 #ifndef __ASSEMBLER__
00134 
00137 extern void *__bss_end;
00138 
00139 #endif
00140 
00141 #ifndef _NOP
00142 # ifdef __GNUC__
00143 #  define _NOP() __asm__ __volatile__ ("nop")
00144 # else
00145 #  define _NOP() asm("nop")
00146 # endif
00147 #endif
00148 
00149 #define outb(_reg, _val)  (*((volatile unsigned char *)(_reg)) = (_val))
00150 #define outw(_reg, _val)  (*((volatile unsigned short *)(_reg)) = (_val))
00151 #define outr(_reg, _val)  (*((volatile unsigned long *)(_reg)) = (_val))
00152 
00153 #define inb(_reg)   (*((volatile unsigned char *)(_reg)))
00154 #define inw(_reg)   (*((volatile unsigned short *)(_reg)))
00155 #define inr(_reg)   (*((volatile unsigned long *)(_reg)))
00156 
00157 #define _BV(bit)    (1 << (bit))
00158 
00159 #ifdef __IMAGECRAFT__
00160 # define __attribute__(x)
00161 #endif
00162 
00163 #define _SFR_MEM8(addr)     (addr)
00164 #define _SFR_MEM16(addr)    (addr)
00165 
00166 
00174 #define Rd_bits( value, mask)        ((value) & (mask))
00175 
00183 #define Tst_bits( value, mask)  (Rd_bits(value, mask) != 0)
00184 
00185 
00193 #if __GNUC__
00194 # define Get_system_register(sysreg)         __builtin_mfsr(sysreg)
00195 #elif __ICCAVR32__
00196 # define Get_system_register(sysreg)         __get_system_register(sysreg)
00197 #endif
00198 
00205 #if __GNUC__
00206 # define Set_system_register(sysreg, value)  __builtin_mtsr(sysreg, value)
00207 #elif __ICCAVR32__
00208 # define Set_system_register(sysreg, value)  __set_system_register(sysreg, value)
00209 #endif
00210 
00215 #define Is_global_interrupt_enabled()        (!Tst_bits(Get_system_register(AVR32_SR), AVR32_SR_GM_MASK))
00216 
00219 #if (defined __GNUC__)
00220   #define Disable_global_interrupt()          ({__asm__ __volatile__ ("ssrf\t%0" :  : "i" (AVR32_SR_GM_OFFSET));})
00221 #elif (defined __ICCAVR32__)
00222   #define Disable_global_interrupt()          (__disable_interrupt())
00223 #endif
00224 
00227 #if (defined __GNUC__)
00228   #define Enable_global_interrupt()           ({__asm__ __volatile__ ("csrf\t%0" :  : "i" (AVR32_SR_GM_OFFSET));})
00229 #elif (defined __ICCAVR32__)
00230   #define Enable_global_interrupt()           (__enable_interrupt())
00231 #endif
00232 
00233 
00234 
00235 #endif // _ARCH_AVR32_H_