[Top][All Lists]

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

Re: [avr-gcc-list] read Access to all of the Atmega 128 flash memory

From: Marek Michalkiewicz
Subject: Re: [avr-gcc-list] read Access to all of the Atmega 128 flash memory
Date: Sun, 2 Jun 2002 15:30:12 +0200 (CEST)

> There is the ELPM instruction but it requires of cause an address to be 
> longer than 16 bit. How do I obtain this address from within my gcc code for 
> one of my variables?

Yes, you have to use elpm - some asm code will be needed as we only
support 16-bit pointers directly.  You can get the low, high and highest
byte of a symbolic address by using lo8(), hi8() and hh8() respectively.

You could try using something like this (not tested), equivalent to

        byte = audio1[addr];  /* addr offset fits in 16 bits */

(the above would work if audio1 was not in a separate address space):

#include <io.h>

unsigned char
get_audio1_byte(unsigned int addr)
        unsigned char byte;
        unsigned int dummy;
        asm (
                "clr %1" "\n\t"
                "subi r30,lo8(-(audio1))" "\n\t"
                "sbci r31,hi8(-(audio1))" "\n\t"
                "sbci %1,hh8(-(audio1))" "\n\t"
                "out %2,%1" "\n\t"
                "elpm %1,Z"
                : "=&z" (dummy), "=&d" (byte)
                : "I" (_SFR_IO_ADDR(RAMPZ)), "0" (addr)
        return byte;

Of course, I assume you are not easily shocked by GCC asm constraints ;)

Hope this helps,

PS.  Please wrap long lines and don't send HTML - thanks!
avr-gcc-list at http://avr1.org

reply via email to

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