[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] sfr_defs.h: _SFR_IO_REG_P(SMPCR)
From: |
Theodore A. Roth |
Subject: |
Re: [avr-gcc-list] sfr_defs.h: _SFR_IO_REG_P(SMPCR) |
Date: |
Thu, 29 Aug 2002 17:00:27 -0700 (PDT) |
On Thu, 29 Aug 2002, E. Weddington wrote:
:) On 29 Aug 2002 at 15:30, Theodore A. Roth wrote:
:)
:) > That example looks suspiciously like it's an asm example (not inline
:) > asm though) to me. How are you trying to use _SFR_IO_REG_P()?
:) >
:)
:) I'm using the macro to do conditional compilation as in
:) #if _SFR_IO_REG_P(SMPCR)
:) #define this that
:) #else
:) #define this other
:) #endif
:)
:) It looks like that all of these macros are written for both C and
:) assembler based on the _SFR_ASM_COMPAT switch. I just don't
:) understand why the C version of the _SFR_IO_REG_P(SMPCR) macro
:) doesn't seem to go through the preprocessor / compiler (at least on
:) my system.
Preprocessing this code:
#include <inttypes.h>
#include <avr/io.h>
#if _SFR_IO_REG_P(SPMCR)
#warning "spmcr true"
#else
#warning "spmcr false"
#endif
#if _SFR_IO_REG_P(SREG)
#warning "sreg true"
#else
#warning "sreg false"
#endif
int main(void)
{
if (_SFR_IO_REG_P(SPMCR))
return 1;
if (_SFR_IO_REG_P(SREG))
return 1;
return (0);
}
With `avr-gcc -mmcu=atmega128 -E messy.c`
I get this:
messy.c:5:24: missing binary operator before token "int"
messy.c:8:2: warning: #warning "spmcr false"
messy.c:11:23: missing binary operator before token "int"
messy.c:14:2: warning: #warning "sreg false"
# 17 "messy.c"
int main(void)
{
if ((((unsigned int) &((*(volatile unsigned char *)(0x68)))) < 0x60))
return 1;
if ((((unsigned int) &((*(volatile unsigned char *)((0x3F) + 0x20)))) <
0x60))
return 1;
return (0);
}
What I suspect is happening is that the #if parts don't like the casts in
the macros. The casts are thrown in when compiling a C program
(!_SFR_ASM_COMPAT) and don't go through the preprocessor for asm
(_SFR_ASM_COMPAT).
Is there some compelling reason you need to use the preprocessor? Can you
just use "_SFR_ADDR(SPMCR)" instead and let the compiler figure what code
to generate?
>From sfr_defs.h:
"In C programs, all 3 combinations of _SFR_ASM_COMPAT and __SFR_OFFSET are
supported - the _SFR_ADDR(SPMCR) macro can be used to get the address of
the SPMCR register (0x57 or 0x68 depending on device)."
Ted Roth
avr-gcc-list at http://avr1.org