[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] unexpected compiler behaviour
From: |
Brian Dean |
Subject: |
Re: [avr-gcc-list] unexpected compiler behaviour |
Date: |
Tue, 3 Sep 2002 08:31:23 -0400 |
User-agent: |
Mutt/1.4i |
On Tue, Sep 03, 2002 at 01:19:10PM +0200, Joerg Wunsch wrote:
> Perhaps it would make some sense to
> write a second lcd_putstring_p() for this purpose.
I've found that I end up doing this type of thing a lot, so instead of
writing sister functions for the PROGMEM case, I wrote an accessor
function in which you pass in the memory type and the address, and it
returns the data byte at that address, i.e.:
unsigned char memio_r(unsigned char memtype, uint16_t addr)
{
unsigned char c;
if (memtype == MT_RAM) {
c = *((unsigned char *)addr);
}
else if (memtype == MT_FLASH) {
c = __lpm_inline(addr);
}
else if (memtype == MT_EEPROM) {
c = eeprom_rb(addr);
}
else {
c = 0;
}
return c;
}
Then, in your various 'puts()' routines, do something like this:
void puts(uint8_t memtype, const char *s)
{
uint16_t a = (uint16_t)s;
char c;
for (c = memio_r(memtype, a); c; c = memio_r(memtype, ++a)) {
putc(c);
}
}
Thus, you can use the same function(s) whether your output data is
coming from RAM, FLASH, or EEPROM.
I find this handy ... just thought I'd share it.
Cheers,
-Brian
--
Brian Dean address@hidden
avr-gcc-list at http://avr1.org