avr-chat
[Top][All Lists]
Advanced

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

Re: [avr-chat] far addresses


From: Rolf Pfister
Subject: Re: [avr-chat] far addresses
Date: Thu, 31 Aug 2017 19:59:31 +0200
User-agent: Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

Am 29.08.2017 um 11:54 schrieb Bob von Knobloch:
Compiler is:
avr-gcc (AVR_8_bit_GNU_Toolchain_3.5.0_1662) 4.9.2


I have the same version and tried a bit today.


code is like:

const char teststring[] PROGMEM = "some text"; // Loaded with a SECTION statement and a linker map at 0x01b000 (high memory) (and checked that it really is there)

hex32out(teststring); // Prints the hex value of the address of teststring

result: 00007187                    // No relation to the address


I couldn't reproduce this behavior.
When anding with 0xFFFF this part of the address was always correct.
The problem is the above bit. When anding with 0x1FFFF I get wrong
addresses. Sometimes even low addresses will have the upper bit set.

So my solution is to set the bit when I know to have a string above
64KB. Otherwise anding with 0xFFFF.
So my example program looks like this:

#include <avr/pgmspace.h>
typedef char String100[100];
const String100 mystrings[3] PROGMEM = {
 "mystrings 12345...",
 "123456789 12345...",
 "Last string...",
};

void print_addr_progmem(const char *b0,bool far=false)
{
 unsigned long addr = ((long)b0) & 0x0FFFF;
 if(far)  addr |= 0x10000; //should work above 64KB for Atmega1284P
 zahl_anzeigen(addr,ROT,16); //print address of string (16=Hex)
 char txt[16];
 int i;
 for(i=0;i<10;i++)
  {
   txt[i] = __ELPM_classic__(addr++);
   if(txt[i]==0) break;
  }
 txt[i]=0;
 led_print(txt); //should print the string (first 10 characters)
}

void progmem_test()
{
 //above 64KB:
 print_addr_progmem(mystrings[0],true);
 //below 64KB:
 print_addr_progmem(manystrings[0]);
}

I had to create quite a lot of strings to get above the 64KB limit.
When having not too many the compiler put them at lower addresses
and program code will go to higher addresses. So most the time
it will not be a problem.

Rolf



reply via email to

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