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

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

Re: [avr-libc-dev] RFC: index-redirection with PROGMEM and linker symbol


From: Tero Sinervo
Subject: Re: [avr-libc-dev] RFC: index-redirection with PROGMEM and linker symbol use
Date: Wed, 18 Feb 2009 10:27:05 +0200
User-agent: Thunderbird 2.0.0.19 (Windows/20081209)

Stu Bell wrote:
I have an interesting idea/problem and I'm looking for ideas.

I would like to place et_ERR_NO_ERROR and et_ERR_TIMEOUT in high flash
(easy), BUT I then want to place the index dereferenced from .proghigh
(where all of these constants are placed) in ErrorTextTable[].

Here's my suggestion. Not fancy because you have to give the section start address and define by hand but what's being done is a hack anyway.


This is given to compiler (byte address):
-DEXTPROGMEM_START=0x10008UL

And this to linker (byte address too):
-Wl,-section-start=.extprogmem=0x10008


#include <avr/pgmspace.h>

const char et_ERR_NO_ERROR [] __attribute__((section (".extprogmem"))) = "No Error"; const char et_ERR_TIMEOUT [] __attribute__((section (".extprogmem"))) = "Timeout";


#define FARTONEAR(a)    ((uint16_t) ((a) - EXTPROGMEM_START))
#define NEARTOFAR(a)    ((uint32_t) (a) + EXTPROGMEM_START)


uint16_t ErrorTextTable[2] PROGMEM = {
    FARTONEAR(et_ERR_NO_ERROR),
    FARTONEAR(et_ERR_TIMEOUT)
};


int main(void)
{
        volatile uint32_t farp = NEARTOFAR(pgm_read_word(&ErrorTextTable[1]));
        volatile char c = pgm_read_byte_far(farp);
}




-Tero




reply via email to

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