Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » AVR-GCC
  • » [avr-gcc-list] LIBC 1.2.6 vs 1.4.0 header files, FLASH and EEPROM [RSS Feed]

#1 Dec. 6, 2005 17:39:14

Bob P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


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


/* Test for GCC < 3.4.4 */
#if __GCC_VERSION__ < 30404
#include <avr/signal.h>
#include <avr/delay.h>
#define FLASH

#endif


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

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

#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...




_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#2 Dec. 6, 2005 19:39:17

Joerg W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


"Bob Paddock" <> wrote:

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

Why not test for

#if __AVR_LIBC_VERSION__ < 10400UL
put old code here
#endif

That macro comes from <avr/version.h>, but that file didn't exist
previously, so in order to give people a transition path, we decided
to include that file from <avr/io.h> as that is usually going to be
included in virtually any AVR project anyway. (Code that is only
supposed to work with avr-libc 1.4 and above is encouraged to
explicitly #include <avr/version.h> though.)

Any C preprocessor macro that hasn't been defined but is used in a
preprocessor expression as shown above automatically evaluates to 0,
so the above test will work.

--
cheers, J"org .-.-. --... ...-- -.. . DL8DTLhttp://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#3 Dec. 6, 2005 20:16:41

Bob P.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


On Tue, 06 Dec 2005 14:37:53 -0500, Joerg Wunsch <>wrote:Why not test for

#if __AVR_LIBC_VERSION__ < 10400UL
put old code here
#endifAny C preprocessor macro that hasn't been defined but is used in a
preprocessor expression as shown above automatically evaluates to 0,
so the above test will work.Lint would not like it. In this case there is no issue with that
usage, but I don't like relying on implied evaluations as they can
lead to very subtle bugs.


_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

#4 Dec. 6, 2005 23:14:45

Joerg W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

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


"Bob Paddock" <> wrote:

> Lint would not like it. In this case there is no issue with that
> usage, but I don't like relying on implied evaluations as they can
> lead to very subtle bugs.

But implying a particular GCC version would automatically also use
some specific avr-libc version is IMHO even worse.

The ``politically correct'' way would be to use something like
autoconf, and probe for the existance of <avr/version.h>. If it's
missing, set __AVR_LIBC_VERSION__ to a low value (e.g. 1) from the
command-line.

--
cheers, J"org .-.-. --... ...-- -.. . DL8DTLhttp://www.sax.de/~joerg/NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)



_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.orghttp://lists.nongnu.org/mailman/listinfo/avr-gcc-list

Offline

  • Root
  • » AVR-GCC
  • » [avr-gcc-list] LIBC 1.2.6 vs 1.4.0 header files, FLASH and EEPROM [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support