Is it possible to tell between data in PROGMEM or SRAM at runtime?

Go To Last Post
2 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi all,

 

If I do this:

    static const uint8_t bitmap[] __attribute__((progmem)) = {
        0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00,
    };

 

or this:

    static const uint8_t bitmap[] = {
        0x7F, 0x04, 0x08, 0x10, 0x7F, 0x00,
    };

 

(only difference is first one is in PROGMEM and the second one is in SRAM) - is there a way for a running program to tell if the data passed to it is coming from PROGMAM or SRAM (i.e. should it be read using bitmap[n] or pgm_get_byte (bitmap + n)?

 

I have been able to "fake it" by using uint8_t for stuff in PROGMEM and char for stuff in SRAM, but I don't like doing it this way and I think there must be a better, cleaner way to do it.

 

Any info will be appreciated!

 

Gentlemen may prefer Blondes, but Real Men prefer Redheads!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use __memx then you can use builtin_avr_flas_segment() on the pointer to determine which 64K flash bank it is in or whether it is RAM (in which case it returns -1)