avr.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. #ifndef _ARCH_AVR_H_
  2. #define _ARCH_AVR_H_
  3. /*
  4. * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. 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
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * $Log$
  36. * Revision 1.15 2008/08/11 11:51:20 thiagocorrea
  37. * Preliminary Atmega2560 compile options, but not yet supported.
  38. * It builds, but doesn't seam to run properly at this time.
  39. *
  40. * Revision 1.14 2006/02/08 15:20:22 haraldkipp
  41. * ATmega2561 Support
  42. *
  43. * Revision 1.13 2005/10/24 10:42:48 haraldkipp
  44. * Definitions distributed to avr/icc.h and avr/gcc.h.
  45. *
  46. * Revision 1.12 2005/10/04 05:21:52 hwmaier
  47. * Added TIFR definition for AT09CAN128
  48. *
  49. * Revision 1.11 2005/08/02 17:46:48 haraldkipp
  50. * Major API documentation update.
  51. *
  52. * Revision 1.10 2005/02/22 17:03:02 freckle
  53. * changed avr-libc-1.2 test to use eeprom_rb, as other test was wrong on
  54. * 1.0.5
  55. *
  56. * Revision 1.9 2005/02/22 16:22:21 freckle
  57. * Added cpp test to guess avr-libc-version required to specify twi.h path
  58. *
  59. * Revision 1.8 2005/02/10 07:06:48 hwmaier
  60. * Changes to incorporate support for AT90CAN128 CPU
  61. *
  62. * Revision 1.7 2005/01/10 12:40:15 olereinhardt
  63. * Included check if atof is just defined (needed by new avr-libc versions on debian unstable)
  64. *
  65. * Revision 1.6 2004/07/09 19:51:34 freckle
  66. * Added new function NutThreadSetSleepMode to tell nut/os to set the MCU
  67. * into sleep mode when idle (avr-gcc && avr128 only)
  68. *
  69. * Revision 1.5 2004/05/23 14:30:32 drsung
  70. * Added some macros, because they are no longer available since version 1.1.0 of avr-libc.
  71. *
  72. * Revision 1.4 2004/03/18 15:53:42 haraldkipp
  73. * ICCAVR failed to compile
  74. *
  75. * Revision 1.3 2004/03/18 09:57:01 haraldkipp
  76. * Architecture required in UserConf.mk
  77. *
  78. * Revision 1.2 2004/03/17 14:54:00 haraldkipp
  79. * Compiling for AVR works again
  80. *
  81. * Revision 1.1 2004/03/16 16:48:28 haraldkipp
  82. * Added Jan Dubiec's H8/300 port.
  83. *
  84. * Revision 1.1 2004/02/01 18:49:47 haraldkipp
  85. * Added CPU family support
  86. *
  87. */
  88. #if defined(__IMAGECRAFT__)
  89. #include <arch/avr/icc.h>
  90. #elif defined(__GNUC__)
  91. #include <arch/avr/gcc.h>
  92. #else
  93. #error "Unable to determine AVR compiler."
  94. #endif
  95. /*!
  96. * \brief Specify AVR target.
  97. *
  98. * Only GCC provides this as a predefined macro. Nut/OS explicitly
  99. * re-defines this, so that it will be available for all compilers.
  100. */
  101. #undef __AVR__
  102. #define __AVR__
  103. /*
  104. * Since version 1.1.0 of avr-libc, some former deprecated macros are deleted.
  105. * But we need them futher on, so they are defined here.
  106. */
  107. #ifndef cbi
  108. #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
  109. #endif
  110. #ifndef sbi
  111. #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
  112. #endif
  113. #ifndef inb
  114. #define inb(sfr) _SFR_BYTE(sfr)
  115. #endif
  116. #ifndef outb
  117. #define outb(sfr, val) (_SFR_BYTE(sfr) = (val))
  118. #endif
  119. #ifndef BV
  120. #define BV(bit) _BV(bit)
  121. #endif
  122. #ifndef inw
  123. #define inw(sfr) _SFR_WORD(sfr)
  124. #endif
  125. #ifndef outw
  126. #define outw(sfr, val) (_SFR_WORD(sfr) = (val))
  127. #endif
  128. #ifndef PRG_RDB
  129. #define PRG_RDB(addr) pgm_read_byte(addr)
  130. #endif
  131. #define __bss_end __heap_start
  132. extern void *__heap_start;
  133. #ifdef __AVR_ENHANCED__
  134. /* Nut/OS is still using the original ATmega103 register names for
  135. backward compatibility. */
  136. #if defined(__AVR_AT90USB1287__)
  137. /* AT90USB1287 without USART0 */
  138. #ifndef UDR
  139. #define UDR UDR1
  140. #endif
  141. #ifndef UBRR
  142. #define UBRR UBRR1L
  143. #endif
  144. #ifndef USR
  145. #define USR UCSR1A
  146. #endif
  147. #ifndef UCR
  148. #define UCR UCSR1B
  149. #endif
  150. #ifndef EICR
  151. #define EICR EICRB
  152. #endif
  153. #ifndef RXC
  154. #define RXC RXC1
  155. #endif
  156. #ifndef UDRE
  157. #define UDRE UDRE1
  158. #endif
  159. #ifndef FE
  160. #define FE FE1
  161. #endif
  162. #ifndef DOR
  163. #define DOR DOR1
  164. #endif
  165. #ifndef RXCIE
  166. #define RXCIE RXCIE1
  167. #endif
  168. #ifndef TXCIE
  169. #define TXCIE TXCIE1
  170. #endif
  171. #ifndef UDRIE
  172. #define UDRIE UDRIE1
  173. #endif
  174. #ifndef RXEN
  175. #define RXEN RXEN1
  176. #endif
  177. #ifndef TXEN
  178. #define TXEN TXEN1
  179. #endif
  180. #else
  181. #ifndef UDR
  182. #define UDR UDR0
  183. #endif
  184. #ifndef UBRR
  185. #define UBRR UBRR0L
  186. #endif
  187. #ifndef USR
  188. #define USR UCSR0A
  189. #endif
  190. #ifndef UCR
  191. #define UCR UCSR0B
  192. #endif
  193. #ifndef EICR
  194. #define EICR EICRB
  195. #endif
  196. #ifndef RXC
  197. #define RXC RXC0
  198. #endif
  199. #ifndef UDRE
  200. #define UDRE UDRE0
  201. #endif
  202. #ifndef FE
  203. #define FE FE0
  204. #endif
  205. #ifndef DOR
  206. #define DOR DOR0
  207. #endif
  208. #ifndef RXCIE
  209. #define RXCIE RXCIE0
  210. #endif
  211. #ifndef TXCIE
  212. #define TXCIE TXCIE0
  213. #endif
  214. #ifndef UDRIE
  215. #define UDRIE UDRIE0
  216. #endif
  217. #ifndef RXEN
  218. #define RXEN RXEN0
  219. #endif
  220. #ifndef TXEN
  221. #define TXEN TXEN0
  222. #endif
  223. #endif
  224. /* Some ATC90CAN128 SFR names are different to ATMEGA128. Define some
  225. compatibilty macros. */
  226. #if defined(__AVR_AT90CAN128__) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_AT90USB1287__)
  227. #ifndef ADCW
  228. #define ADCW ADC
  229. #endif
  230. #ifndef ADCSR
  231. #define ADCSR ADCSRA
  232. #endif
  233. #ifndef ADFR
  234. #define ADFR ADATE
  235. #endif
  236. #ifndef OCIE0
  237. #define OCIE0 OCIE0A
  238. #endif
  239. #ifndef TCCR0
  240. #define TCCR0 TCCR0A
  241. #endif
  242. #ifndef TCCR2
  243. #define TCCR2 TCCR2A
  244. #endif
  245. #ifndef OCR0
  246. #define OCR0 OCR0A
  247. #endif
  248. #ifndef TIMSK
  249. #define TIMSK TIMSK0
  250. #endif
  251. #ifndef TIFR
  252. #define TIFR TIFR0
  253. #endif
  254. #endif /* __AVR_AT90CAN128__ || __AVR_ATmega2560__ || __AVR_ATmega2561__ || __AVR_AT90USB1287__)*/
  255. #endif /* __AVR_ENHANCED__ */
  256. #endif /* _ARCH_AVR_H_ */