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

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

Re: [avr-gcc-list] array of floats in program memory


From: Joerg Wunsch
Subject: Re: [avr-gcc-list] array of floats in program memory
Date: Tue, 8 Apr 2003 10:17:38 +0200 (MET DST)

Ernst den Broeder <address@hidden> wrote:

> This piece of code does not compile (winavr-20030312).  I get a 
> __progmem__ attribute ignored warning message, ...

Strange.  It works here:

#include <avr/pgmspace.h>

float getv(int i)
{
  static float PROGMEM afr_vs_voltage[62]=
    {
        1.40, 10.08,
        1.45, 10.23, 
        2.85, 19.66,
        2.90, 20.66
    };
  float f;

  memcpy_P(&f, afr_vs_voltage + i, sizeof(float));
  return f;
}

The following yields slightly more efficient code:

#include <avr/pgmspace.h>

float getv(int i)
{
  static float PROGMEM afr_vs_voltage[62]=
    {
        1.40, 10.08,
        1.45, 10.23, 
        2.85, 19.66,
        2.90, 20.66
    };
  union
    {
      unsigned char b[4];
      float f;
    }
  u;
  unsigned char *p;

  p = (unsigned char *)(afr_vs_voltage + i);

  u.b[0] = PRG_RDB(p++);
  u.b[1] = PRG_RDB(p++);
  u.b[2] = PRG_RDB(p++);
  u.b[3] = PRG_RDB(p);

  return u.f;
}

-- 
J"org Wunsch                                           Unix support engineer
address@hidden        http://www.interface-systems.de/~j/


reply via email to

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