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

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

Re: [avr-gcc-list] Access to constants via elpm


From: E. Weddington
Subject: Re: [avr-gcc-list] Access to constants via elpm
Date: Mon, 09 Sep 2002 09:36:09 -0600

On 7 Sep 2002 at 8:10, Roland Zitzke wrote:

> Hi,
> 
> > Ok, try this:
> >
> > #define __ELPM_enhanced__(addr)                \
> > (                                   \
> >     {                                   \
> >         unsigned char __result;                \
> >         __asm__ __volatile__                   \
> >         (                                   \
> >             "movw r30, %A2\n\t"                \
> >             "sts  %1, %C2\n\t"                 \
> >             "elpm %0, Z\n\t"                   \
> >             : "=r" ((unsigned char)__result),  \
> >               "=m" (RAMPZ)                     \
> >             : "r" ((unsigned long)addr)        \
> >             : "r30", "r31"                     \
> >         );                                   \
> >         __result;                              \
> >     }                                   \
> > )
> >
> > Give the macro a 32-bit address (unsigned long) and it will spit out
> > the data (unsigned char) that is programmed in the flash.

> yes, this is working, I "simulated" this for the atmega103 and 128 and
> these are the only two parts I know of with more than 64k flash. What
> I am desperately trying to do now is to create a macro which takes a
> symbol of a long flash address and returns an unsigned long "large
> pointer" which I can pass around through function calls as
> pseude-pointers: #define PRG_GETADDRESS(symname) \ (unsigned long) ...
> all this macro should do is to return the address as an unsigned long
> value i.e. not getting truncated by the compoler. This happens if you
> write something like: unsigned long mypointer = (unsigned long)
> flashdata; where flashdata is a constant in previously defined. any
> idea? /Roland

When you code a constant value that is greater than 16 bits, such as:

unsigned long value;
value = 0x81000;

the constant value will get truncated to 16 bits unless you tell the 
compiler that the constant is greater than 16 bits. Place the UL 
characters after the constant value to tell the compiler that the 
constant is an unsigned long:

unsigned long value;
value = 0x81000UL;

The compiler will then keep the full 32 bit value.

HTH,

Eric

avr-gcc-list at http://avr1.org



reply via email to

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