avr32.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #ifndef _ARCH_AVR32_H_
  2. #define _ARCH_AVR32_H_
  3. /*!
  4. * Copyright (C) 2001-2010 by egnite Software GmbH
  5. *
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * 1. Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in the
  16. * documentation and/or other materials provided with the distribution.
  17. * 3. Neither the name of the copyright holders nor the names of
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  30. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  31. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  32. * SUCH DAMAGE.
  33. *
  34. * For additional information see http://www.ethernut.de/
  35. *
  36. * Portions Copyright Atmel Corporation, see the following note.
  37. */
  38. /*This file is prepared for Doxygen automatic documentation generation.*/
  39. /*! \file *********************************************************************
  40. *
  41. * \brief Compiler file for AVR32.
  42. *
  43. * This file defines commonly used types and macros.
  44. *
  45. * - Compiler: IAR EWAVR32 and GNU GCC for AVR32
  46. * - Supported devices: All AVR32 devices can be used.
  47. * - AppNote:
  48. *
  49. * \author Atmel Corporation: http://www.atmel.com \n
  50. * Support and FAQ: http://support.atmel.no/
  51. *
  52. ******************************************************************************/
  53. /* Copyright (c) 2009 Atmel Corporation. All rights reserved.
  54. *
  55. * Redistribution and use in source and binary forms, with or without
  56. * modification, are permitted provided that the following conditions are met:
  57. *
  58. * 1. Redistributions of source code must retain the above copyright notice, this
  59. * list of conditions and the following disclaimer.
  60. *
  61. * 2. Redistributions in binary form must reproduce the above copyright notice,
  62. * this list of conditions and the following disclaimer in the documentation
  63. * and/or other materials provided with the distribution.
  64. *
  65. * 3. The name of Atmel may not be used to endorse or promote products derived
  66. * from this software without specific prior written permission.
  67. *
  68. * 4. This software may only be redistributed and used in connection with an Atmel
  69. * AVR product.
  70. *
  71. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  72. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  73. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  74. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  75. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  76. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  77. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  78. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  79. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  80. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  81. *
  82. */
  83. /*
  84. * $Log: avr32.h,v $
  85. *
  86. */
  87. #include <cfg/arch.h>
  88. /* AVR32 is big endian core */
  89. #if !defined(__BIG_ENDIAN__)
  90. #define __BIG_ENDIAN__
  91. #endif
  92. #ifdef __GNUC__
  93. # define CONST const
  94. # define INLINE inline
  95. #else
  96. # ifndef CONST
  97. # define CONST const
  98. # endif
  99. # ifndef INLINE
  100. # define INLINE
  101. # endif
  102. #endif
  103. #define PSTR(p) (p)
  104. #define PRG_RDB(p) (*((const char *)(p)))
  105. #define prog_char const char
  106. #define PGM_P const char *
  107. #define strlen_P(x) strlen((char *)(x))
  108. #define strcpy_P(x,y) strcpy(x,(char *)(y))
  109. #define strcmp_P(x, y) strcmp((char *)(x), (char *)(y))
  110. #define memcpy_P(x, y, z) memcpy(x, y, z)
  111. #define SIGNAL(x) __attribute__((__interrupt__)) void x(void)
  112. /* -------------------------------------------------------------------------
  113. * redefine main
  114. * ------------------------------------------------------------------------- */
  115. #if !defined(__cplusplus)
  116. # define main NutAppMain
  117. #endif
  118. #define strlen_P(x) strlen((char *)(x))
  119. #define strcpy_P(x,y) strcpy(x,(char *)(y))
  120. #define strcmp_P(x, y) strcmp((char *)(x), (char *)(y))
  121. #define memcpy_P(x, y, z) memcpy(x, y, z)
  122. #ifndef __ASSEMBLER__
  123. /*!
  124. * \brief End of uninitialized data segment. Defined in the linker script.
  125. */
  126. extern void *__bss_end;
  127. #endif
  128. #ifndef _NOP
  129. # ifdef __GNUC__
  130. # define _NOP() __asm__ __volatile__ ("nop")
  131. # else
  132. # define _NOP() asm("nop")
  133. # endif
  134. #endif
  135. #define outb(_reg, _val) (*((volatile unsigned char *)(_reg)) = (_val))
  136. #define outw(_reg, _val) (*((volatile unsigned short *)(_reg)) = (_val))
  137. #define outr(_reg, _val) (*((volatile unsigned long *)(_reg)) = (_val))
  138. #define inb(_reg) (*((volatile unsigned char *)(_reg)))
  139. #define inw(_reg) (*((volatile unsigned short *)(_reg)))
  140. #define inr(_reg) (*((volatile unsigned long *)(_reg)))
  141. #define _BV(bit) (1 << (bit))
  142. #ifdef __IMAGECRAFT__
  143. # define __attribute__(x)
  144. #endif
  145. #define _SFR_MEM8(addr) (addr)
  146. #define _SFR_MEM16(addr) (addr)
  147. /*! \brief Reads the bits of a value specified by a given bit-mask.
  148. *
  149. * \param value Value to read bits from.
  150. * \param mask Bit-mask indicating bits to read.
  151. *
  152. * \return Read bits.
  153. */
  154. #define Rd_bits( value, mask) ((value) & (mask))
  155. /*! \brief Tests the bits of a value specified by a given bit-mask.
  156. *
  157. * \param value Value of which to test bits.
  158. * \param mask Bit-mask indicating bits to test.
  159. *
  160. * \return \c 1 if at least one of the tested bits is set, else \c 0.
  161. */
  162. #define Tst_bits( value, mask) (Rd_bits(value, mask) != 0)
  163. /*!
  164. * \brief Gets the value of the \a sysreg system register.
  165. *
  166. * \param sysreg Address of the system register of which to get the value.
  167. *
  168. * \return Value of the \a sysreg system register.
  169. */
  170. #if __GNUC__
  171. # define Get_system_register(sysreg) __builtin_mfsr(sysreg)
  172. #elif __ICCAVR32__
  173. # define Get_system_register(sysreg) __get_system_register(sysreg)
  174. #endif
  175. /*!
  176. * \brief Sets the value of the \a sysreg system register to \a value.
  177. *
  178. * \param sysreg Address of the system register of which to set the value.
  179. * \param value Value to set the \a sysreg system register to.
  180. */
  181. #if __GNUC__
  182. # define Set_system_register(sysreg, value) __builtin_mtsr(sysreg, value)
  183. #elif __ICCAVR32__
  184. # define Set_system_register(sysreg, value) __set_system_register(sysreg, value)
  185. #endif
  186. /*! \brief Tells whether interrupts are globally enabled.
  187. *
  188. * \return \c 1 if interrupts are globally enabled, else \c 0.
  189. */
  190. #define Is_global_interrupt_enabled() (!Tst_bits(Get_system_register(AVR32_SR), AVR32_SR_GM_MASK))
  191. /*! \brief Disables interrupts globally.
  192. */
  193. #if (defined __GNUC__)
  194. #define Disable_global_interrupt() ({__asm__ __volatile__ ("ssrf\t%0" : : "i" (AVR32_SR_GM_OFFSET));})
  195. #elif (defined __ICCAVR32__)
  196. #define Disable_global_interrupt() (__disable_interrupt())
  197. #endif
  198. /*! \brief Enables interrupts globally.
  199. */
  200. #if (defined __GNUC__)
  201. #define Enable_global_interrupt() ({__asm__ __volatile__ ("csrf\t%0" : : "i" (AVR32_SR_GM_OFFSET));})
  202. #elif (defined __ICCAVR32__)
  203. #define Enable_global_interrupt() (__enable_interrupt())
  204. #endif
  205. #endif // _ARCH_AVR32_H_