gcc.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. #ifndef _ARCH_AVR_GCC_H_
  2. #define _ARCH_AVR_GCC_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.6 2009/02/06 15:45:04 haraldkipp
  37. * Routines using heap memory moved from c to crt module.
  38. * We now have strdup() and calloc().
  39. *
  40. * Revision 1.5 2008/08/11 11:51:20 thiagocorrea
  41. * Preliminary Atmega2560 compile options, but not yet supported.
  42. * It builds, but doesn't seam to run properly at this time.
  43. *
  44. * Revision 1.4 2008/06/16 13:03:37 haraldkipp
  45. * Added Thiago's patch to fix _SLEEP_MODE_MASK problem, which is no longer
  46. * public in the latest avrlibc.
  47. *
  48. * Revision 1.3 2007/04/12 09:20:34 haraldkipp
  49. * Added new register bit names for the ATmega2561.
  50. *
  51. * Revision 1.2 2006/01/11 08:32:21 hwmaier
  52. * Support for avr-libc >= 1.4.x
  53. *
  54. * Revision 1.1 2005/10/24 10:46:05 haraldkipp
  55. * First check in.
  56. * Contents taken from avr.h in the parent directory.
  57. *
  58. */
  59. /* ================================================================ */
  60. /* To be sorted out. */
  61. /* ================================================================ */
  62. #define CONST const
  63. #ifndef INLINE
  64. #define INLINE inline
  65. #endif
  66. #include <avr/io.h>
  67. #include <avr/interrupt.h>
  68. #if __AVR_LIBC_VERSION__ < 10400UL
  69. #include <avr/signal.h>
  70. #endif
  71. #include <avr/eeprom.h>
  72. #include <avr/pgmspace.h>
  73. #include <avr/sleep.h>
  74. #include <stdlib.h>
  75. /*
  76. * test for a macro added in avr-libc 1.2.0, if yes use different path for twi.h
  77. * note: has to be after #include <eeprom.h>
  78. */
  79. #ifdef eeprom_rb
  80. #include <avr/twi.h>
  81. #else
  82. #include <compat/twi.h>
  83. #endif
  84. #if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
  85. #if !defined(TXC)
  86. #define TXC TXC0
  87. #endif
  88. #if !defined(TXB8)
  89. #define TXB8 TXB80
  90. #endif
  91. #if !defined(UMSEL)
  92. #define UMSEL UMSEL00
  93. #endif
  94. #if !defined(U2X)
  95. #define U2X U2X0
  96. #endif
  97. #if !defined(UCSZ0)
  98. #define UCSZ0 UCSZ00
  99. #endif
  100. #if !defined(UCSZ1)
  101. #define UCSZ1 UCSZ01
  102. #endif
  103. #if !defined(UCSZ2)
  104. #define UCSZ2 UCSZ02
  105. #endif
  106. #if !defined(UPM0)
  107. #define UPM0 UPM00
  108. #endif
  109. #if !defined(UPM1)
  110. #define UPM1 UPM01
  111. #endif
  112. #if !defined(USBS)
  113. #define USBS USBS0
  114. #endif
  115. #if !defined(UPE)
  116. #define UPE UPE0
  117. #endif
  118. #if !defined(MPCM)
  119. #define MPCM MPCM0
  120. #endif
  121. #if !defined(UCPOL)
  122. #define UCPOL UCPOL0
  123. #endif
  124. #elif defined(__AVR_AT90USB1287__)
  125. #if !defined(TXC)
  126. #define TXC TXC1
  127. #endif
  128. #if !defined(TXB8)
  129. #define TXB8 TXB81
  130. #endif
  131. #if !defined(UMSEL)
  132. #define UMSEL UMSEL10
  133. #endif
  134. #if !defined(U2X)
  135. #define U2X U2X1
  136. #endif
  137. #if !defined(UCSZ0)
  138. #define UCSZ0 UCSZ10
  139. #endif
  140. #if !defined(UCSZ1)
  141. #define UCSZ1 UCSZ11
  142. #endif
  143. #if !defined(UCSZ2)
  144. #define UCSZ2 UCSZ12
  145. #endif
  146. #if !defined(UPM0)
  147. #define UPM0 UPM10
  148. #endif
  149. #if !defined(UPM1)
  150. #define UPM1 UPM11
  151. #endif
  152. #if !defined(USBS)
  153. #define USBS USBS1
  154. #endif
  155. #if !defined(UPE)
  156. #define UPE UPE1
  157. #endif
  158. #if !defined(MPCM)
  159. #define MPCM MPCM1
  160. #endif
  161. #if !defined(UCPOL)
  162. #define UCPOL UCPOL1
  163. #endif
  164. #endif
  165. #ifndef __SFR_OFFSET
  166. #define __SFR_OFFSET 0
  167. #endif
  168. #define COMPRESS_DISABLE
  169. #define COMPRESS_REENABLE
  170. #ifndef _NOP
  171. #define _NOP() __asm__ __volatile__ ("nop")
  172. #endif
  173. #ifndef atof
  174. #define atof(s) strtod(s, 0)
  175. #endif
  176. #define EEPROMReadBytes(addr, ptr, size) eeprom_read_block((char *)(addr), ptr, size)
  177. /*!
  178. * \brief Read multibyte types from the EEPROM.
  179. */
  180. #define EEPROM_READ(addr, dst) eeprom_read_block((char *)(addr), &dst, sizeof(dst))
  181. #define EEPROMread(addr) eeprom_read_byte((char *)(addr))
  182. /*!
  183. * \brief Write multibyte types to the EEPROM.
  184. */
  185. #define EEPROM_WRITE(addr, src) \
  186. { \
  187. unsigned short __i; \
  188. for(__i = 0; __i < sizeof(src); __i++) \
  189. eeprom_write_byte(((char *)(addr)) + __i, *(((char *)(&(src))) + __i)); \
  190. }
  191. #define EEPROMWriteBytes(addr, ptr, size) \
  192. { \
  193. unsigned short __i; \
  194. for(__i = 0; __i < size; __i++) \
  195. eeprom_write_byte(((char *)(addr)) + __i, *(((char *)(ptr)) + __i)); \
  196. }
  197. #define main NutAppMain
  198. /* Define internal _SLEEP_MODE_MASK that is no longer public in avrlibc. */
  199. #ifndef _SLEEP_MODE_MASK
  200. #if defined(SM) && !defined(SM0) && !defined(SM1) && !defined(SM2)
  201. #define _SLEEP_MODE_MASK _BV(SM)
  202. #elif !defined(SM) && defined(SM0) && defined(SM1) && !defined(SM2)
  203. #define _SLEEP_MODE_MASK (_BV(SM0) | _BV(SM1))
  204. #elif !defined(SM) && defined(SM0) && defined(SM1) && defined(SM2)
  205. #define _SLEEP_MODE_MASK (_BV(SM0) | _BV(SM1) | _BV(SM2))
  206. #endif
  207. #endif
  208. #if defined(__AVR_LIBC_VERSION__)
  209. extern void *calloc(size_t num, size_t size);
  210. extern char *strdup(const char *str);
  211. #endif
  212. #endif /* _ARCH_AVR_GCC_H_ */