|
|
View previous topic :: View next topic |
Author |
Message |
smanzer
Joined: 14 Sep 2009 Posts: 24 Location: Ontario, Canada
|
Pointer to function problem |
Posted: Sat Jul 17, 2010 6:21 am |
|
|
Good morning,
I have found an interesting challenge when trying to run functions when using a structure containing a function pointer. I have read everything I can about work arounds on this forum and although the posts have helped I am still having trouble.
The pic is a 18F8722, compiler is 4.093.
I have many include files as part of a home automation system. The program is becoming quite large with ROM=73% and RAM 35-44%
When I call the menu routine to save the function pointer to be called I get a pointer value that is beyond $FFFF for example $0104B2. Looking at the .lst code shows that that is where the function resides. I modified the code as suggested by PCM_Programmer to make it a 16 bit variable, but this is a 17 bit number. So, I changed it to a 32 bit number.
The function never runs. It is only the functions that have a 17bit pointer that do not execute. Here is how the function is called when using a pointer to the function that is stored in a structure:
Code: |
typedef void (* _void_fptr)(void); // note functions are passed and return void
typedef volatile struct MyMenuItem{
struct MyMenuItem *NextItem;
struct MyMenuItem *PrevItem;
struct MyMenuItem *SubMenu;
char Text[21];
int32 FunctionPtr;
} MenuItem;
temp = m->FunctionPtr; // temp is _void_fptr FunctionPtr is int32
(*temp)();// execute the code for the menu item
|
I assume the problem is that the functions that do not run are in a different memory segment. Any chance someone has a work around for accessing functions in another memory segment?
Thanks in advance,
Steven _________________ "I am always doing that which I can not do, in order that I may learn how to do it."
- Pablo Picasso |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jul 17, 2010 10:58 am |
|
|
My first thought is to use #org to put anything that involves function
pointers into the first 64KB of Flash. |
|
|
smanzer
Joined: 14 Sep 2009 Posts: 24 Location: Ontario, Canada
|
|
Posted: Sun Jul 18, 2010 7:35 am |
|
|
Thanks PCM_Programmer, that should work! I have a variable that I use to turn on/off debugging info to the pc terminal. When I turned it off, the program size dropped so the offending functions were in the first 64K and it all worked as expected.
I have never used #org, would this be correct for an 18F8722:
#org 0x0000, 0xFFFF
Looking at the data sheet, it looks like On-Chip Program memory goes from 0x00000 to 0x1FFFF, there are Reset Vectors and Interrupt vectors from 0x0000 to 0x0018, do they have to be excluded like:
#org 0x0018, 0xFFFF
Thanks for helping again PCM_Programmer!!
Steven _________________ "I am always doing that which I can not do, in order that I may learn how to do it."
- Pablo Picasso |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|