Nut/OS  4.10.3
API Reference
gcc.h
Go to the documentation of this file.
00001 #ifndef _ARCH_AVR_GCC_H_
00002 #define _ARCH_AVR_GCC_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.6  2009/02/06 15:45:04  haraldkipp
00039  * Routines using heap memory moved from c to crt module.
00040  * We now have strdup() and calloc().
00041  *
00042  * Revision 1.5  2008/08/11 11:51:20  thiagocorrea
00043  * Preliminary Atmega2560 compile options, but not yet supported.
00044  * It builds, but doesn't seam to run properly at this time.
00045  *
00046  * Revision 1.4  2008/06/16 13:03:37  haraldkipp
00047  * Added Thiago's patch to fix _SLEEP_MODE_MASK problem, which is no longer
00048  * public in the latest avrlibc.
00049  *
00050  * Revision 1.3  2007/04/12 09:20:34  haraldkipp
00051  * Added new register bit names for the ATmega2561.
00052  *
00053  * Revision 1.2  2006/01/11 08:32:21  hwmaier
00054  * Support for avr-libc >= 1.4.x
00055  *
00056  * Revision 1.1  2005/10/24 10:46:05  haraldkipp
00057  * First check in.
00058  * Contents taken from avr.h in the parent directory.
00059  *
00060  */
00061 
00062 
00063 /* ================================================================ */
00064 /* To be sorted out.                                                */
00065 /* ================================================================ */
00066 
00067 
00068 #define CONST   const
00069 #define INLINE  inline
00070 
00071 
00072 #include <avr/io.h>
00073 #include <avr/interrupt.h>
00074 #if __AVR_LIBC_VERSION__ < 10400UL
00075 #include <avr/signal.h>
00076 #endif
00077 #include <avr/eeprom.h>
00078 #include <avr/pgmspace.h>
00079 #include <avr/sleep.h>
00080 #include <stdlib.h>
00081 
00082 
00083 /*
00084  * test for a macro added in avr-libc 1.2.0, if yes use different path for twi.h
00085  * note: has to be after #include <eeprom.h>
00086  */
00087 #ifdef eeprom_rb
00088 #include <avr/twi.h>
00089 #else
00090 #include <compat/twi.h>
00091 #endif
00092 
00093 #if defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__)
00094 #if !defined(TXC)
00095 #define TXC     TXC0
00096 #endif
00097 #if !defined(TXB8)
00098 #define TXB8     TXB80
00099 #endif
00100 #if !defined(UMSEL)
00101 #define UMSEL     UMSEL00
00102 #endif
00103 #if !defined(U2X)
00104 #define U2X     U2X0
00105 #endif
00106 #if !defined(UCSZ0)
00107 #define UCSZ0     UCSZ00
00108 #endif
00109 #if !defined(UCSZ1)
00110 #define UCSZ1     UCSZ01
00111 #endif
00112 #if !defined(UCSZ2)
00113 #define UCSZ2     UCSZ02
00114 #endif
00115 #if !defined(UPM0)
00116 #define UPM0     UPM00
00117 #endif
00118 #if !defined(UPM1)
00119 #define UPM1     UPM01
00120 #endif
00121 
00122 #if !defined(USBS)
00123 #define USBS     USBS0
00124 #endif
00125 #if !defined(UPE)
00126 #define UPE     UPE0
00127 #endif
00128 #if !defined(MPCM)
00129 #define MPCM     MPCM0
00130 #endif
00131 #if !defined(UCPOL)
00132 #define UCPOL     UCPOL0
00133 #endif
00134 #endif
00135 
00136 #ifndef __SFR_OFFSET
00137 #define __SFR_OFFSET    0
00138 #endif
00139 
00140 #define COMPRESS_DISABLE
00141 #define COMPRESS_REENABLE
00142 
00143 #ifndef _NOP
00144 #define _NOP() __asm__ __volatile__ ("nop")
00145 #endif
00146 
00147 #ifndef atof
00148 #define atof(s)     strtod(s, 0)
00149 #endif
00150 
00151 #define EEPROMReadBytes(addr, ptr, size)    eeprom_read_block((char *)(addr), ptr, size)
00152 
00155 #define EEPROM_READ(addr, dst)              eeprom_read_block((char *)(addr), &dst, sizeof(dst))
00156 #define EEPROMread(addr)                    eeprom_read_byte((char *)(addr))
00157 
00161 #define EEPROM_WRITE(addr, src)                                                 \
00162 {                                                                               \
00163     unsigned short __i;                                                         \
00164     for(__i = 0; __i < sizeof(src); __i++)                                      \
00165         eeprom_write_byte(((char *)(addr)) + __i, *(((char *)(&(src))) + __i)); \
00166 }
00167 
00168 #define EEPROMWriteBytes(addr, ptr, size)                                       \
00169 {                                                                               \
00170     unsigned short __i;                                                         \
00171     for(__i = 0; __i < size; __i++)                                             \
00172         eeprom_write_byte(((char *)(addr)) + __i, *(((char *)(ptr)) + __i));    \
00173 }
00174 
00175 #define main    NutAppMain
00176 
00177 /* Define internal _SLEEP_MODE_MASK that is no longer public in avrlibc. */
00178 #ifndef _SLEEP_MODE_MASK
00179 #if defined(SM) && !defined(SM0) && !defined(SM1) && !defined(SM2)
00180 #define _SLEEP_MODE_MASK _BV(SM)
00181 #elif !defined(SM) && defined(SM0) && defined(SM1) && !defined(SM2)
00182 #define _SLEEP_MODE_MASK (_BV(SM0) | _BV(SM1))
00183 #elif !defined(SM) && defined(SM0) && defined(SM1) && defined(SM2)
00184 #define _SLEEP_MODE_MASK (_BV(SM0) | _BV(SM1) | _BV(SM2))
00185 #endif
00186 #endif
00187 
00188 #if defined(__AVR_LIBC_VERSION__)
00189 extern void *calloc(size_t num, size_t size);
00190 extern char *strdup(CONST char *str);
00191 #endif
00192 
00193 #endif /* _ARCH_AVR_GCC_H_ */
00194