CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Pointer to function problem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
smanzer



Joined: 14 Sep 2009
Posts: 24
Location: Ontario, Canada

View user's profile Send private message Visit poster's website

Pointer to function problem
PostPosted: Sat Jul 17, 2010 6:21 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Jul 17, 2010 10:58 am     Reply with quote

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

View user's profile Send private message Visit poster's website

PostPosted: Sun Jul 18, 2010 7:35 am     Reply with quote

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
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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