icc.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. #ifndef TOOLCHAIN_ICC_H_
  2. #define TOOLCHAIN_ICC_H_
  3. /*
  4. * Copyright (C) 2012 by egnite GmbH
  5. * Copyright (C) 2001-2005 by egnite Software GmbH
  6. *
  7. * All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in the
  17. * documentation and/or other materials provided with the distribution.
  18. * 3. Neither the name of the copyright holders nor the names of
  19. * contributors may be used to endorse or promote products derived
  20. * from this software without specific prior written permission.
  21. *
  22. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  23. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  24. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  25. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  26. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  27. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  28. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  29. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  30. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  31. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  32. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. * SUCH DAMAGE.
  34. *
  35. * For additional information see http://www.ethernut.de/
  36. */
  37. #ifndef _TOOLCHAIN_H_
  38. #error "Do not include this file directly, include <toolchain.h> instead."
  39. #endif
  40. /*
  41. * Include some basic header files of the ImageCraft runtime library.
  42. */
  43. #include <stddef.h>
  44. #include <macros.h>
  45. #include <eeprom.h>
  46. /* ICCV7 incompatibility nightmare. */
  47. #if defined(_MCU_Enhanced) && !defined(_MCU_enhanced)
  48. #define _MCU_enhanced
  49. #endif
  50. #if defined(_MCU_Extended) && !defined(_MCU_extended)
  51. #define _MCU_extended
  52. #endif
  53. /*!
  54. * \brief Specify enhanced AVR target.
  55. *
  56. * For backward compatibility this macro is automatically defined if
  57. * _MCU_enhanced is defined.
  58. *
  59. */
  60. #if defined(_MCU_enhanced) || defined(_MCU_extended)
  61. #undef __AVR_ENHANCED__
  62. #define __AVR_ENHANCED__ /* Generic test for enhanced AVRs like ATMEGA128, AT09CAN128 */
  63. #endif
  64. /*!
  65. * \name General Compiler Feature Macros
  66. */
  67. /*@{*/
  68. #ifndef NUT_INLINE_FUNC
  69. #define NUT_INLINE_FUNC
  70. #endif
  71. #ifndef NUT_FORCE_INLINE
  72. #define NUT_FORCE_INLINE
  73. #endif
  74. #ifndef NUT_NAKED_FUNC
  75. #define NUT_NAKED_FUNC
  76. #endif
  77. #ifndef NUT_PURE_FUNC
  78. #define NUT_PURE_FUNC
  79. #endif
  80. #ifndef NUT_CONST_FUNC
  81. #define NUT_CONST_FUNC
  82. #endif
  83. #ifndef NUT_NORETURN_FUNC
  84. #define NUT_NORETURN_FUNC
  85. #endif
  86. #ifndef NUT_USED_FUNC
  87. #define NUT_USED_FUNC
  88. #endif
  89. #ifndef NUT_ALLOC_FUNC
  90. #define NUT_ALLOC_FUNC
  91. #endif
  92. #ifndef RAMFUNC
  93. #define RAMFUNC
  94. #endif
  95. #ifndef NUT_PACKED_TYPE
  96. #define NUT_PACKED_TYPE
  97. #endif
  98. #ifndef NUT_ALIGNED_TYPE
  99. #define NUT_ALIGNED_TYPE(bytes)
  100. #endif
  101. #ifndef NUT_LINKER_SECT
  102. #define NUT_LINKER_SECT(name)
  103. #endif
  104. #ifndef NUT_WEAK_SYMBOL
  105. #define NUT_WEAK_SYMBOL
  106. #endif
  107. #ifndef NUT_DEPRECATED
  108. #define NUT_DEPRECATED
  109. #endif
  110. #define COMPRESS_DISABLE
  111. #define COMPRESS_REENABLE
  112. /*@}*/
  113. /*!
  114. * \brief Redefined standard library routines.
  115. *
  116. * ImageCraft has a multipass linker, which is fine for complicated
  117. * dependencies in most cases. However, there is the potential risk,
  118. * that standard library calls with the same name are linked from
  119. * the wrong library. To avoid this, an additional postfix is added
  120. * to routines, which are implemented in Nut/OS libraries.
  121. */
  122. #define printf printf_M
  123. #define puts puts_M
  124. #define sprintf sprintf_M
  125. #define vprintf vprintf_M
  126. #define scanf scanf_M
  127. #define gets gets_M
  128. #define malloc malloc_M
  129. #define calloc calloc_M
  130. #define realloc realloc_M
  131. #define free free_M
  132. /* device specific functions map to special name forms so the linker
  133. * can give more meaningful error messages
  134. */
  135. #pragma device_specific_function putchar getchar
  136. /*!
  137. * \brief Redirected stdio routines.
  138. *
  139. * Native stdio routines with format strings in program space are
  140. * redirected to their Nut/OS implementation.
  141. */
  142. #define cprintf printf_P
  143. #define csprintf sprintf_P
  144. #define cscanf scanf_P
  145. #define csscanf sscanf_P
  146. #define memcpy_P(dst, src_P, n) cmemcpy(dst, src_P, n)
  147. #define strcat_P(s1, s2_P) cstrcat(s1, s2_P)
  148. #define strcmp_P(s1, s2_P) (-cstrcmp(s2_P, s1))
  149. #define strlen_P(s_P) cstrlen(s_P)
  150. #define strncat_P(s1, s2_P, n) cstrncat(s1, s2_P, n)
  151. #define strncmp_P(s1_P, s2, n) cstrncmp(s1_P, s2, n)
  152. #define strcpy_P(dst, src_P) cstrcpy(dst, src_P)
  153. #define strncpy_P(x,y,z) cstrncpy(x,y,z)
  154. /*!
  155. * \brief Case insensitive string comparisions.
  156. *
  157. * Not supported by ICCAVR and temporarly redirected to
  158. * the case sensitive routines.
  159. *
  160. * \bug Case insensitive string comparisions fail with ICCAVR.
  161. */
  162. #define strcasecmp(s1, s2) strcmp(s1, s2)
  163. #define strncasecmp(s1, s2, n) strncmp(s1, s2, n)
  164. /*!
  165. * \brief Start of heap area.
  166. */
  167. #define __heap_start _bss_end
  168. #define PRG_RDB(p) (*((__flash char *)(p)))
  169. #define prog_char __flash char
  170. #define prog_int __flash int
  171. #define wdt_enable(tmo) \
  172. { \
  173. register unsigned char s = _BV(WDCE) | _BV(WDE); \
  174. register unsigned char r = tmo | _BV(WDE); \
  175. asm("in R0, 0x3F\n" \
  176. "cli\n" \
  177. "wdr\n" \
  178. "out 0x21, %s\n" \
  179. "out 0x21, %r\n" \
  180. "out 0x3F, R0\n"); \
  181. }
  182. #define wdt_disable() \
  183. { \
  184. register unsigned char s = _BV(WDCE) | _BV(WDE); \
  185. register unsigned char r = 0; \
  186. asm("in R0, $3F\n" \
  187. "cli\n" \
  188. "out 0x21, %s\n" \
  189. "out 0x21, %r\n" \
  190. "out 0x3F, R0\n"); \
  191. }
  192. #define wdt_reset() \
  193. { \
  194. _WDR(); \
  195. }
  196. #define __SFR_OFFSET 0
  197. #define SFR_IO_ADDR(sfr) ((sfr) - __SFR_OFFSET)
  198. #define SFR_MEM_ADDR(sfr) (sfr)
  199. #define SFR_IO_REG_P(sfr) ((sfr) < 0x40 + __SFR_OFFSET)
  200. #define _SFR_MEM8(addr) (addr)
  201. #define _SFR_MEM16(addr) (addr)
  202. #define BV(x) BIT(x)
  203. #define _BV(x) BIT(x)
  204. #define cli() CLI()
  205. #define sei() SEI()
  206. #define cbi(reg, bit) (reg &= ~BIT(bit))
  207. #define sbi(reg, bit) (reg |= BIT(bit))
  208. #define loop_until_bit_is_set(reg, bit) while((reg & BIT(bit)) == 0)
  209. #define bit_is_clear(reg, bit) ((reg & BIT(bit)) == 0)
  210. #define bit_is_set(reg, bit) ((reg & BIT(bit)) != 0)
  211. /* FIXME */
  212. #define parity_even_bit(x) (0)
  213. /* FIXME */
  214. #define SIGNAL(x) void x(void)
  215. #define outb(reg, val) (reg = val)
  216. #define inb(reg) (reg)
  217. #include <eeprom.h>
  218. #if defined(_MCU_enhanced) || defined(_MCU_extended)
  219. #ifdef ATMega2560
  220. #include <iom2560v.h>
  221. #define __AVR_ATmega2560__
  222. #ifndef _EE_EXTIO
  223. #error "Looks like wrong platform. Select avrext-icc, not avr-icc."
  224. #endif
  225. #elif defined(ATMega2561)
  226. #include <iom2561v.h>
  227. #define __AVR_ATmega2561__
  228. #ifndef _EE_EXTIO
  229. #error "Looks like wrong platform. Select avrext-icc, not avr-icc."
  230. #endif
  231. #else
  232. #include <iom128v.h>
  233. #define __AVR_ATmega128__
  234. #endif
  235. #ifndef RAMEND
  236. #if defined(ATMega2560) || defined(ATMega2561)
  237. #define RAMEND 0x21FF
  238. #else
  239. #define RAMEND 0x10FF
  240. #endif
  241. #endif
  242. #ifndef SRW
  243. #define SRW 6
  244. #endif
  245. /* ICC doesn't define generic ports and flags. */
  246. #ifndef TXC
  247. #define TXC TXC0
  248. #endif
  249. #ifndef ADCSR
  250. #define ADCSR ADCSRA
  251. #endif
  252. /* Master */
  253. #define TW_START 0x08
  254. #define TW_REP_START 0x10
  255. /* Master Transmitter */
  256. #define TW_MT_SLA_ACK 0x18
  257. #define TW_MT_SLA_NACK 0x20
  258. #define TW_MT_DATA_ACK 0x28
  259. #define TW_MT_DATA_NACK 0x30
  260. #define TW_MT_ARB_LOST 0x38
  261. /* Master Receiver */
  262. #define TW_MR_ARB_LOST 0x38
  263. #define TW_MR_SLA_ACK 0x40
  264. #define TW_MR_SLA_NACK 0x48
  265. #define TW_MR_DATA_ACK 0x50
  266. #define TW_MR_DATA_NACK 0x58
  267. /* Slave Transmitter */
  268. #define TW_ST_SLA_ACK 0xA8
  269. #define TW_ST_ARB_LOST_SLA_ACK 0xB0
  270. #define TW_ST_DATA_ACK 0xB8
  271. #define TW_ST_DATA_NACK 0xC0
  272. #define TW_ST_LAST_DATA 0xC8
  273. /* Slave Receiver */
  274. #define TW_SR_SLA_ACK 0x60
  275. #define TW_SR_ARB_LOST_SLA_ACK 0x68
  276. #define TW_SR_GCALL_ACK 0x70
  277. #define TW_SR_ARB_LOST_GCALL_ACK 0x78
  278. #define TW_SR_DATA_ACK 0x80
  279. #define TW_SR_DATA_NACK 0x88
  280. #define TW_SR_GCALL_DATA_ACK 0x90
  281. #define TW_SR_GCALL_DATA_NACK 0x98
  282. #define TW_SR_STOP 0xA0
  283. /* Misc */
  284. #define TW_NO_INFO 0xF8
  285. #define TW_BUS_ERROR 0x00
  286. #else /* ATmega103 */
  287. #include <iom103v.h>
  288. #define __AVR_ATmega103__
  289. #ifndef DOR
  290. #define DOR OVR
  291. #endif
  292. #ifndef RAMEND
  293. #define RAMEND 0x0FFF
  294. #endif
  295. #ifndef WDCE
  296. #define WDCE WDTOE
  297. #endif
  298. #endif
  299. #define eeprom_read_block(dst, addr, size) EEPROMReadBytes((int)addr, dst, size)
  300. #define eeprom_write_byte(addr, src) EEPROMwrite((int)addr, src)
  301. #define eeprom_read_byte(addr) EEPROMread((int)addr)
  302. extern void *calloc(size_t num, size_t size);
  303. extern char *strdup(const char *str);
  304. #include <string.h>
  305. #endif