[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] [discussion] lpm support in avr-gcc
From: |
Svein E. Seldal |
Subject: |
Re: [avr-gcc-list] [discussion] lpm support in avr-gcc |
Date: |
Fri, 23 Aug 2002 23:32:31 +0200 |
User-agent: |
Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1b) Gecko/20020721 |
Hi Harald,
Would we have to rewrite stdlib.h then,
Like 'atoi(const char *)' to 'atoi(char *)'?
No, of course not... When I said const, I ment const in the
implementation of variables, not to functions. But I get your point, so
let me think aloud:
Instead of using const, lets use some other kind of tagging, lets call
it 'PMEM'. This tag is a part of the decleration of pointers. When
transferred across functions, this tag should be kept intact as a part
of its decl. Example is shown below.
Please note the difference between the PMEM and PROGMEM directives.
PROGMEM instansiates a variable in flash, as usual. PMEM is a directive
which should used on pointers to indicate that they point on progmem
data. (We dont have to call it PMEM, but let's do it for the example.)
struct foo {
const char PMEM *string; // 1.
int num;
};
const struct foo PROGMEM bar[] = {
{ P"Memory in flash", 100 } // 2.
{ NULL, 0 }
};
void puts_P(const char PMEM *); // 3.
void puts(const char *); // 3.
struct foo PMEM *ptr = bar; // 4.
struct foo *err = bar; // 5. INVALID
const char PMEM *str = bar->string; // 6.
puts_P(str); // 7.
puts(str); // 8. INVALID
while((c=*str++)) { // 9.
putc(c);
}
1. This decleration must be present in definitions
2. This is a special thing! Why not use 'P' in the string prefix to
indicate a flash storing? Its is basically the same principles as you
would use L" " on wide strings. Why? Because you cant use the PSTR()
macro inside that struct implemenation.
3. You will still require two sets of libc functions - one for accessing
data memory and one for program memory.
4. This is legal because the PMEM tag is used in this line.
5. This fails because 'err' has not been declared with the PMEM directive.
6. This line is valid because 'bar's PMEM directive ensure the it reads
the contents of the flash instead of data memory.
7. This is valid because the decleration matches.
8. This in invalid because the decleation does not match.
9. And finally. This works because the compiler knows that it must use a
LPM function to access a pointer declared with the PMEM tag.
Do you understand me?
Regards,
Svein
avr-gcc-list at http://avr1.org