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

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

[avr-gcc-list] [discussion] lpm support in avr-gcc


From: Svein E. Seldal
Subject: [avr-gcc-list] [discussion] lpm support in avr-gcc
Date: Fri, 23 Aug 2002 17:19:50 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1b) Gecko/20020721

Hi,

Are there any plans on making the use of LPM built natively into gcc? When programming and using variables that are located into the program.data segment, accessing it is a *bit* troublesome. Look at the code on the bottom. It demonstrates how "complex" the avr-gcc's LPM function can make programming, while the second example shows my suggested implementation.

The principes of Harvard arch's isn't exactly new and other developers have solved this problem before and I've seen many excellent solutions to the challenges that the AVR architecture makes!

My suggestion is that when a string/struct/variable is declared as 'const' it should be placed into the progmem.data segment. In 99% precent of the applications, things like strings are read-only and can/shold be placed in flash. And for the remaining 1% cases, just omit the const and the data will be placed in SRAM.

To be able to do it like this, changes to the compiler must be made. It needs to keep track of where the variable is stored and use either ld or lpm where appropriate, but my academic guess is that this is just a matter of attributes.

I know this has performance impacts, but wouldn't it be the coder's responsibility to decide when to use initialized data or using flash-stored consts?

Keep up the *good* work. avr-gcc is a very good acheivement and very useful tool. avr-gcc is being used in development ranging from private projects to commercial product development! Thanks.

Let the discussion begin.
Regards,
Svein


AVR Example:
-------------

  struct test {
    int number;
    const char *string;
  };

  const char PROGMEM string1[] = "string";
  const char PROGMEM string2[] = "string2";

  const struct test PROGMEM foo[] {
    { 344, string1 },
    { 945, string2 },
    { 0, NULL }
  };

  // This function prints the string 'str' from flash
  void puts_P(const char *str);

  void func(void) {
    struct test *f = foo;

    while(foo &&
          (str = (const char *)_LPM16(&foo->string)) )
    {
      puts_P(str);
      foo++;
    }
  }


Improved code:
--------------

  struct test {
    int number;
    const char *string;
  };

  const struct test foo[] {
    { 344, "string" },
    { 945, "string2" },
    { 0, NULL }
  };

  void func(void) {
    while(foo && foo->string)
    {
      puts(foo->string);
      foo++;
    }
  }

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



reply via email to

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