Nut/OS  4.10.3
API Reference
icc.h
Go to the documentation of this file.
00001 #ifndef _ARCH_AVR_ICC_H_
00002 #define _ARCH_AVR_ICC_H_
00003 
00004 /*
00005  * Copyright (C) 2001-2005 by egnite Software GmbH. All rights reserved.
00006  *
00007  * Redistribution and use in source and binary forms, with or without
00008  * modification, are permitted provided that the following conditions
00009  * are met:
00010  *
00011  * 1. Redistributions of source code must retain the above copyright
00012  *    notice, this list of conditions and the following disclaimer.
00013  * 2. Redistributions in binary form must reproduce the above copyright
00014  *    notice, this list of conditions and the following disclaimer in the
00015  *    documentation and/or other materials provided with the distribution.
00016  * 3. Neither the name of the copyright holders nor the names of
00017  *    contributors may be used to endorse or promote products derived
00018  *    from this software without specific prior written permission.
00019  *
00020  * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
00021  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
00024  * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
00027  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
00028  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00029  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
00030  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * For additional information see http://www.ethernut.de/
00034  */
00035 
00036 /*
00037  * $Log$
00038  * Revision 1.11  2009/02/06 15:58:08  haraldkipp
00039  * We now have strdup() and calloc().
00040  *
00041  * Revision 1.10  2008/09/18 09:48:07  haraldkipp
00042  * The old Marv_XXX do no longer work with ICCAVR 7.18B.
00043  *
00044  * Revision 1.9  2008/08/11 11:51:20  thiagocorrea
00045  * Preliminary Atmega2560 compile options, but not yet supported.
00046  * It builds, but doesn't seam to run properly at this time.
00047  *
00048  * Revision 1.8  2008/08/11 06:59:58  haraldkipp
00049  * BSD types replaced by stdint types (feature request #1282721).
00050  *
00051  * Revision 1.7  2008/06/25 08:37:56  freckle
00052  * escape realloc for icc
00053  *
00054  * Revision 1.6  2006/09/29 12:22:07  haraldkipp
00055  * Corrected internal RAM size and check compiler environment for ATmega2561.
00056  *
00057  * Revision 1.5  2006/07/10 08:48:03  haraldkipp
00058  * Distinguish between enhanced and extended AVR.
00059  *
00060  * Revision 1.4  2006/05/25 09:35:27  haraldkipp
00061  * Dummy macros added to support the avr-libc special function register
00062  * definitions.
00063  *
00064  * Revision 1.3  2006/02/08 15:20:56  haraldkipp
00065  * ATmega2561 Support
00066  *
00067  * Revision 1.2  2005/10/24 18:04:25  haraldkipp
00068  * Duplicate macro definitions removed.
00069  * Parameter order of cstrcmp() corrected.
00070  * Generic port and flag names added for ATmega103 support.
00071  *
00072  * Revision 1.1  2005/10/24 10:46:05  haraldkipp
00073  * First check in.
00074  * Contents taken from avr.h in the parent directory.
00075  *
00076  */
00077 
00078 /*
00079  * Include some basic header files of the ImageCraft runtime library.
00080  */
00081 #include <stddef.h>
00082 #include <macros.h>
00083 #include <eeprom.h>
00084 
00085 /* ICCV7 incompatibility nightmare. */
00086 #if defined(_MCU_Enhanced) && !defined(_MCU_enhanced)
00087 #define _MCU_enhanced
00088 #endif
00089 
00090 #if defined(_MCU_Extended) && !defined(_MCU_extended)
00091 #define _MCU_extended
00092 #endif
00093 
00101 #if defined(_MCU_enhanced) || defined(_MCU_extended)
00102 #undef __AVR_ENHANCED__
00103 #define __AVR_ENHANCED__ /* Generic test for enhanced AVRs like ATMEGA128, AT09CAN128 */
00104 #endif
00105 
00113 #ifndef CONST
00114 #define CONST   const
00115 #endif
00116 
00123 #ifndef INLINE
00124 #define INLINE
00125 #endif
00126 
00136 #define printf      printf_M
00137 #define puts        puts_M
00138 #define sprintf     sprintf_M
00139 #define vprintf     vprintf_M
00140 #define scanf       scanf_M
00141 #define gets        gets_M
00142 #define malloc      malloc_M
00143 #define calloc      calloc_M
00144 #define realloc     realloc_M
00145 #define free        free_M
00146 
00153 #define cprintf     printf_P
00154 #define csprintf    sprintf_P
00155 #define cscanf      scanf_P
00156 #define csscanf     sscanf_P
00157 
00158 #define memcpy_P(dst, src_P, n) cmemcpy(dst, src_P, n)
00159 #define strcat_P(s1, s2_P)      cstrcat(s1, s2_P)
00160 #define strcmp_P(s1, s2_P)      (-cstrcmp(s2_P, s1))
00161 #define strlen_P(s_P)           cstrlen(s_P)
00162 #define strncat_P(s1, s2_P, n)  cstrncat(s1, s2_P, n)
00163 #define strncmp_P(s1_P, s2, n)  cstrncmp(s1_P, s2, n)
00164 #define strcpy_P(dst, src_P)    cstrcpy(dst, src_P)
00165 #define strncpy_P(x,y,z)        cstrncpy(x,y,z)
00166 
00175 #define strcasecmp(s1, s2)  strcmp(s1, s2)
00176 #define strncasecmp(s1, s2, n)  strncmp(s1, s2, n)
00177 
00178 
00182 #define __heap_start   _bss_end
00183 
00189 #define __attribute__(x)
00190 
00196 #define PSTR(p)     (p)
00197 
00201 #define PRG_RDB(p)  (*((__flash char *)(p)))
00202 
00206 #define prog_char __flash char
00207 
00211 #define prog_int __flash int
00212 
00216 #define PGM_P prog_char *
00217 
00218 
00219 /* ================================================================ */
00220 /* To be sorted out.                                                */
00221 /* ================================================================ */
00222 
00223 #define wdt_enable(tmo) \
00224 { \
00225     register unsigned char s = _BV(WDCE) | _BV(WDE); \
00226     register unsigned char r = tmo | _BV(WDE); \
00227     asm("in R0, 0x3F\n"     \
00228         "cli\n"             \
00229         "wdr\n"             \
00230         "out 0x21, %s\n"    \
00231         "out 0x21, %r\n"    \
00232         "out 0x3F, R0\n");  \
00233 }
00234 
00235 #define wdt_disable() \
00236 { \
00237     register unsigned char s = _BV(WDCE) | _BV(WDE); \
00238     register unsigned char r = 0;  \
00239     asm("in R0, $3F\n"      \
00240         "cli\n"             \
00241         "out 0x21, %s\n"    \
00242         "out 0x21, %r\n"    \
00243         "out 0x3F, R0\n");  \
00244 }
00245 
00246 #define wdt_reset() \
00247 { \
00248     _WDR(); \
00249 }
00250 
00251 
00252 #define __SFR_OFFSET 0
00253 #define SFR_IO_ADDR(sfr) ((sfr) - __SFR_OFFSET)
00254 #define SFR_MEM_ADDR(sfr) (sfr)
00255 #define SFR_IO_REG_P(sfr) ((sfr) < 0x40 + __SFR_OFFSET)
00256 
00257 #define _SFR_MEM8(addr)     (addr)
00258 #define _SFR_MEM16(addr)    (addr)
00259 
00260 #define BV(x)       BIT(x)
00261 #define _BV(x)      BIT(x)
00262 
00263 #define cli()           CLI()
00264 #define sei()           SEI()
00265 #define cbi(reg, bit)   (reg &= ~BIT(bit))
00266 #define sbi(reg, bit)   (reg |= BIT(bit))
00267 
00268 
00269 #define loop_until_bit_is_set(reg, bit) while((reg & BIT(bit)) == 0)
00270 
00271 #define bit_is_clear(reg, bit)  ((reg & BIT(bit)) == 0)
00272 #define bit_is_set(reg, bit)    ((reg & BIT(bit)) != 0)
00273 
00274 /* FIXME */
00275 #define parity_even_bit(x)  (0)
00276 
00277 /* FIXME */
00278 #define SIGNAL(x)   void x(void)
00279 
00280 #define outp(val, reg)  (reg = val)
00281 #define outb(reg, val)  (reg = val)
00282 
00283 #define inp(reg)        (reg)
00284 #define inb(reg)        (reg)
00285 
00286 #include <eeprom.h>
00287 
00288 #if defined(_MCU_enhanced) || defined(_MCU_extended)
00289 
00290 #ifdef ATMega2560
00291 #include <iom2560v.h>
00292 #define __AVR_ATmega2560__
00293 #ifndef _EE_EXTIO
00294 #error "Looks like wrong platform. Select avrext-icc, not avr-icc."
00295 #endif
00296 #elif defined(ATMega2561)
00297 #include <iom2561v.h>
00298 #define __AVR_ATmega2561__
00299 #ifndef _EE_EXTIO
00300 #error "Looks like wrong platform. Select avrext-icc, not avr-icc."
00301 #endif
00302 #else
00303 #include <iom128v.h>
00304 #define __AVR_ATmega128__
00305 #endif
00306 
00307 #ifndef RAMEND
00308 #if defined(ATMega2560) || defined(ATMega2561)
00309 #define RAMEND  0x21FF
00310 #else
00311 #define RAMEND  0x10FF
00312 #endif
00313 #endif
00314 
00315 #ifndef SRW
00316 #define SRW  6
00317 #endif
00318 
00319 /* ICC doesn't define generic ports and flags. */
00320 #ifndef TXC
00321 #define TXC     TXC0
00322 #endif
00323 #ifndef ADCSR
00324 #define ADCSR   ADCSRA
00325 #endif
00326 
00327 /* Master */
00328 #define TW_START                    0x08
00329 #define TW_REP_START            0x10
00330 /* Master Transmitter */
00331 #define TW_MT_SLA_ACK           0x18
00332 #define TW_MT_SLA_NACK          0x20
00333 #define TW_MT_DATA_ACK          0x28
00334 #define TW_MT_DATA_NACK         0x30
00335 #define TW_MT_ARB_LOST      0x38
00336 /* Master Receiver */
00337 #define TW_MR_ARB_LOST      0x38
00338 #define TW_MR_SLA_ACK           0x40
00339 #define TW_MR_SLA_NACK          0x48
00340 #define TW_MR_DATA_ACK          0x50
00341 #define TW_MR_DATA_NACK         0x58
00342 /* Slave Transmitter */
00343 #define TW_ST_SLA_ACK           0xA8
00344 #define TW_ST_ARB_LOST_SLA_ACK  0xB0
00345 #define TW_ST_DATA_ACK          0xB8
00346 #define TW_ST_DATA_NACK         0xC0
00347 #define TW_ST_LAST_DATA         0xC8
00348 /* Slave Receiver */
00349 #define TW_SR_SLA_ACK           0x60
00350 #define TW_SR_ARB_LOST_SLA_ACK  0x68
00351 #define TW_SR_GCALL_ACK         0x70
00352 #define TW_SR_ARB_LOST_GCALL_ACK 0x78
00353 #define TW_SR_DATA_ACK          0x80
00354 #define TW_SR_DATA_NACK         0x88
00355 #define TW_SR_GCALL_DATA_ACK    0x90
00356 #define TW_SR_GCALL_DATA_NACK   0x98
00357 #define TW_SR_STOP              0xA0
00358 /* Misc */
00359 #define TW_NO_INFO              0xF8
00360 #define TW_BUS_ERROR            0x00
00361 
00362 
00363 #else                           /* ATmega103 */
00364 
00365 #include <iom103v.h>
00366 #define __AVR_ATmega103__
00367 
00368 #ifndef DOR
00369 #define DOR  OVR
00370 #endif
00371 
00372 #ifndef RAMEND
00373 #define RAMEND  0x0FFF
00374 #endif
00375 
00376 #ifndef WDCE
00377 #define WDCE    WDTOE
00378 #endif
00379 
00380 #endif
00381 
00382 #define eeprom_read_block(dst, addr, size)  EEPROMReadBytes((int)addr, dst, size)
00383 #define eeprom_write_byte(addr, src)        EEPROMwrite((int)addr, src)
00384 #define eeprom_read_byte(addr)              EEPROMread((int)addr)
00385 
00386 extern void *calloc(size_t num, size_t size);
00387 extern char *strdup(CONST char *str);
00388 
00389 #include <string.h>
00390 
00391 
00392 #endif /* _ARCH_AVR_ICC_H_ */
00393 
00394