| Issue 3: | Harvard machines need special pointer handling | |
| 1 person starred this issue and may be notified of changes. | Back to list |
Harvard machines, like AVR, need special code for pointers stored in code ROM (e.g. flash). Only applies to strings, but affects format strings, %s and %". Also think about putting padding (space and zero) strings into ROM. Ideally a unified interface to the consumer function, rather than needing two consumer functions (messy).
One option is a data type with a union for the two pointer types and a type specifier. Wrap all this up in a struct. Could be
struct str_ptr {
union {
const char * dptr;
FLASH_MEM * cptr;
} u;
enum { DATA_PTR, CODE_PTR } access;
};
(or whatever goes in "FLASH_MEM")
Then dynamic string would be:
struct str_ptr p;
p.access = DATA_PTR;
p.u.dptr = /* pointer to string */
And ROM string would be:
struct str_ptr p;
p.access = CODE_PTR;
p.u.cptr = /* pointer to string */
Question: where does the string go:
fmt( "hello" );
And so its type is..?
Nov 24, 2010
Project Member
#1
neil.johnson71
Dec 8, 2010
In the case of AVR, the following: fmt( "hello" ); puts the string both in the .data segment in ROM, and then copied at startup into the .data segment in RAM. So the wrapper can be really simple with little waste. |