[Top][All Lists]

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

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

From: Stu Bell
Subject: [avr-libc-dev] RFC: index-redirection with PROGMEM and linker symbol use
Date: Tue, 17 Feb 2009 15:08:04 -0700

I have an interesting idea/problem and I'm looking for ideas.

I'm using an ATmega2560 and my string tables are getting large enough to
be bumping real code out of the bottom page of flash.  So far,
everything has been done with the standard PROGMEM macros/calls and I've
been happy.  However, I'm thinking of adding quite a few more strings
and I'm not happy with dedicating all of my most precious bottom flash
to "constants".

I'm quite familiar with the standard PROGMEM macros and routines.  I'm
also familiar with Carlos Lamas' morepgmspace.h routines and use them
with my bootloader.  This is not a request for instructions on their
use. (Or, maybe it is, if the below can be done with them.)

The idea is this:  PROGMEM is based on the idea that we can represent
all the direct addressing to flash constants in the 16-bit GCC pointer
value.  So far, so good.  What I want to do is generate a relocation
offset for all flash constants.  I would place all of PROGMEM (or some
other related call, perhaps "PROGMEM_INDEXED" or "PROGMEM_HIGH")
starting at address 0x37000 (byte address), for example.  Then 16-bit
pointers to constants would be a direct offset from the linker address
of the base of this table.  Perhaps I would call the section .proghigh.
Finally, the functions used to dereference pointers to this area would
auto-magically add the .proghigh offset to the passed in 16-bit
"pointer", to generate the real 24-bit (okay, 32-bit) address to hand
off to the ELPM intruction.

In other words, I want an indexed-dereference of the pointer passed in
from the based of the constant table.  Even more important, I want the
linker to store this index in my flash table instead of the standard
variable pointer I use now.

Placing the constants up in my special section is a no-brainer.  I can
do it with a section attribute.  I do it now with my boot string table.

I think I can generate the proper assembly, although I'm not quite sure
how to bring in the relocation address.  That could be done simply
enough with a symbol define, I think.

The hard part is generating the 16-bit offset values and placing those
in the tables referencing the constants.  For example, my error string
table looks something like:

const char et_ERR_NO_ERROR [] PROGMEM = "No Error";
const char et_ERR_TIMEOUT  [] PROGMEM = "Timeout; 

PGM_P ErrorTextTable[2] PROGMEM = {

So, in the current code, I have defined two strings in program flash and
placed pointers to those strings in ErrorTextTable.

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[].

The reason for this request is (I hope) obvious.  A good portion my
strings are accessed through pointer tables (think error text and
parsing command text).  If those pointer tables suddenly go from being
2-byte based to 4-byte based (of which the top byte for every entry will
*always* be zero!), my tables will get significantly bigger.

For the moment, I'm ignoring the problem and using PROGMEM.  My flash
table size is currently around 9 Kbytes, so I have plenty of more room.
But I'm going to be adding quite a bit more (a logging function was
requested and I don't eant to store the strings real time in my external
SRAM), so the problem is looming.

Ideas?  Suggestions?  I'm open!  BTW, this is not a request for code
(but I'll take it if you have it!), just ideas

Best regards,

Stu Bell
DPHI, Inc. (DataPlay)

reply via email to

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