avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] LIBC 1.2.6 vs 1.4.0 header files, FLASH and EEPROM


From: Bob Paddock
Subject: [avr-gcc-list] LIBC 1.2.6 vs 1.4.0 header files, FLASH and EEPROM
Date: Tue, 06 Dec 2005 12:37:32 -0500
User-agent: Opera M2/8.50 (Win32, build 7700)


AVR-LIBC 1.4.0 has added a couple of new defines
for EEPROM and FLASH.  Both that I had defined
in my own code, leading to redefinition warnings.

Here is a code snippet that lets you work around
this type of issue.

By checking the GCC version you can load the
appropriate header files(s) from the correct
directories:

#ifdef __GNUC__

#define __GCC_VERSION__ (__GNUC__ * 10000 \
                               + __GNUC_MINOR__ * 100 \
                               + __GNUC_PATCHLEVEL__)

/* Test for GCC < 3.4.0 */
#if __GCC_VERSION__ < 30400
#include <avr/ina90.h>
#endif

/* Test for GCC >= 3.4.3 */
#if __GCC_VERSION__ >= 30403
#include <compat/ina90.h>
#endif

#include <avr/eeprom.h>
#include <avr/interrupt.h>
#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/wdt.h> /* Watch Dog */
#include <inttypes.h>

/* Test for GCC == 3.4.3 */
#if __GCC_VERSION__ == 30403
#define EEPROM __attribute__ ((section(".eeprom")))
#endif
[EEPROM was originally defined in my source code files.]

/* Test for GCC < 3.4.4 */
#if __GCC_VERSION__ < 30404
#include <avr/signal.h>
#include <avr/delay.h>
#define FLASH
[FLASH here is specific to my code, see below.]
#endif


/* Test for GCC >= 3.4.4 */
#if __GCC_VERSION__ >= 30404
#include <util/delay.h>

#undef  FLASH /* Use 'PROGMEM' */
#define FLASH

[FLASH is NULL in the GCC case for me, code not shown here defines it for IAR, so the same
source will build with both IAR and GCC.]

#endif

I put those in a file called compiler.h that I include
with every project, so all compiler issues are localized
to one file.  Makes multiple GCC version and using non-GCC compilers
work with the same source code.

Hope the technique helps someone out...






reply via email to

[Prev in Thread] Current Thread [Next in Thread]