avr-libc-dev
[Top][All Lists]
Advanced

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

Re: [avr-libc-dev] Error when using lagre memory addresses


From: E. Weddington
Subject: Re: [avr-libc-dev] Error when using lagre memory addresses
Date: Tue, 15 Feb 2005 07:35:44 -0700
User-agent: Mozilla Thunderbird 1.0 (Windows/20041206)

Per Arnold Blåsmo wrote:

Hi,
During my work with adapting avg-gcc to a new processor (AT90SC3232CS) I
have discovered a problem regarding addressing that I think is not
working in the generated code.

I would like some comments on this from some of you more expert than me
on this :-)

There are some things you can do that would probably help. See below:


Consider the following code:
----
#include <avr/io.h>
#include <avr/pgmspace.h>

#define FROMADDR 0x100000L
#define TOADDR1 (uint8_t *)0x200
#define TOADDR2    (uint8_t *)0x100

Use the "unsigned long" suffix for these addresses. You can't have a negative address, so don't use "long". If your TO addresses are 32 bit, then that should help with the problem with it not writing the RAMPZ register correctly. When you write a constant without specifying how large it is, C language will default to int which is 16 bits on the AVR. Since it's 16 bits, that is why it is writing the Z reg but not updating the RAMPZ (at least in theory, I haven't tried this).

So change the above to:
#define FROMADDR 0x100000UL
#define TOADDR1 (uint8_t *)0x200UL
#define TOADDR2    (uint8_t *)0x100UL



int main(void)
{
   uint8_t *p_to_addr1= TOADDR1;
   uint8_t *p_to_addr2= TOADDR2;
   uint32_t from_addr = FROMADDR;
   uint8_t size = 255;

   while(size--){
       *p_to_addr1++ = pgm_read_byte_far(from_addr++);

PLEASE remember that pgm_read_byte_far() is a *MACRO* and can have side effects of macros. So I would suggest, that you just give a simple parameter and not do other things inside the macro parentheses. Change this to:

  while(size--){
      *p_to_addr1++ = pgm_read_byte_far(from_addr);
      from_addr++;

All of the pgm_read*() "functions" are actually macros, so be careful.

See if these changes help.

Eric




reply via email to

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