[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[avr-gcc-list] array of pointers to functions - ok in RAM, fails in flas
From: |
David McNab |
Subject: |
[avr-gcc-list] array of pointers to functions - ok in RAM, fails in flash |
Date: |
Mon, 26 Feb 2007 09:37:54 +1300 |
Hi,
I'm creating a table of pointers to functions, where each function is
like:
void func(void) { ... }
When I place the table into RAM, I can access elements, and dereference
those elements to execute the corresponding functions. This works fine.
For example:
void (*func_tab[])() = {
func1, func2, ...
};
void main () {
void (*funcptr)(void);
...
funcptr = func_tab[1];
(*funcptr)();
...
}
But when I place the table into flash instead, my program goes off into
the boonies when I try to invoke the function:
#include <avr/pgmspace.h>
void (*func_tab[])() = {
func1, func2, ...
};
void (*func_tab_flash[])() PROGMEM = {
func1, func2, ...
};
void main () {
void (*funcptr)(void);
...
funcptr = func_tab[1]; // the variable holds 0x90
(*funcptr)(); // this works just fine
funcptr = func_tab_flash[1]; // the variable holds 0
(*funcptr)(); // this sends us into the boonies
}
Surely it can't be too hard to place a table of function pointers into
flash, retrieve function pointers from this table, and 'call' them.
What am I doing wrong? Otherwise, what workarounds are available?
Cheers
David
- [avr-gcc-list] array of pointers to functions - ok in RAM, fails in flash,
David McNab <=