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

Stack overflow

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



Joined: 18 Nov 2003
Posts: 14
Location: Ireland

View user's profile Send private message

Stack overflow
PostPosted: Wed Mar 24, 2004 5:58 am     Reply with quote

Hey
I am havin a problem with stack overflow in MPLAB, i keep getting a stack overflow after 7 or 8 runs of the program. I know i can disable Stack overflow warning for simulation but i need to know what is causing the problem because when i look at the call tree for the program it should'nt be using the full 8 level deep stack for pic16f877 and also My code is crashing out when i program the pic with it, but not after it has at least run once! While simulating i opened the stack window and noticed that calls were getting pushed onto the stack but didn't seem to be getting popped of after returns. Can anyone advise me on why this is so. The function that appears to causes the problem never actually returns, what i do in the function is load the program counter therefore it never returns, is this the problem?? What should i do??

Thanks
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Wed Mar 24, 2004 6:16 am     Reply with quote

Pls post a piece of code that cause the problem and the compiler version.

Humberto
Michaelc



Joined: 18 Nov 2003
Posts: 14
Location: Ireland

View user's profile Send private message

Stack overflow
PostPosted: Wed Mar 24, 2004 6:51 am     Reply with quote

Its actually an operating system iam working on so posting all the relevant code would be impossible, but i have the the code below for a typical task, as you can see its in an infinite loop, below that is the function i think maybe causing the problem again as you can see it never really returns but instead changes the pc.

void outputs()
{


for(;;)
{//printf("out");

OSM_WAIT_BIN(SEM_INPUT, OUT1, OUTPUTS_id);
write_expanded_outputs(current_status);
OSM_YIELD(OUT2 ,OUTPUTS_id);
//The function executes
//from here when it is elegible,
#asm
nop
#endasm

}
}



void OSJump()
{//printf("%x", pRunningTask->return_add_high);
//printf("%x", pRunningTask->return_add_low);
jump_label = pRunningTask->return_add_high ;
#asm
movf jump_label,w
movwf PCLATH
#endasm

jump_label = pRunningTask->return_add_low ;
#asm
movf jump_label,w
movwf PCL
#endasm
return ; //won't actually return because it changes the program counter
}


There is about 3 functions which do similar operations as shown above.

Compiler version is
IDE 2.32
PCM 2.734

Not sure if this will help!
Thanks for the reply!
Michaelc



Joined: 18 Nov 2003
Posts: 14
Location: Ireland

View user's profile Send private message

PostPosted: Wed Mar 24, 2004 6:59 am     Reply with quote

How is the stack popped on the PIC and does loading the pc in a function and not actually returning from the function in the natural way cause the stack not to be popped?
Ttelmah
Guest







Re: Stack overflow
PostPosted: Wed Mar 24, 2004 7:04 am     Reply with quote

Michaelc wrote:
Its actually an operating system iam working on so posting all the relevant code would be impossible, but i have the the code below for a typical task, as you can see its in an infinite loop, below that is the function i think maybe causing the problem again as you can see it never really returns but instead changes the pc.

void outputs()
{


for(;;)
{//printf("out");

OSM_WAIT_BIN(SEM_INPUT, OUT1, OUTPUTS_id);
write_expanded_outputs(current_status);
OSM_YIELD(OUT2 ,OUTPUTS_id);
//The function executes
//from here when it is elegible,
#asm
nop
#endasm

}
}



void OSJump()
{//printf("%x", pRunningTask->return_add_high);
//printf("%x", pRunningTask->return_add_low);
jump_label = pRunningTask->return_add_high ;
#asm
movf jump_label,w
movwf PCLATH
#endasm

jump_label = pRunningTask->return_add_low ;
#asm
movf jump_label,w
movwf PCL
#endasm
return ; //won't actually return because it changes the program counter
}


There is about 3 functions which do similar operations as shown above.

Compiler version is
IDE 2.32
PCM 2.734

Not sure if this will help!
Thanks for the reply!

If you are jumping out of a called routine, and never returning, then of course the stack will overflow. You have the following choices that I can think of:
1) 'goto' the routine, rather than calling it.
2) Switch to using one of the 18 family chips, which allow you to 'pop' the top entry on the stack.

Best Wishes
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Fri Mar 26, 2004 9:24 am     Reply with quote

Quote:

void OSJump()
{//printf("%x", pRunningTask->return_add_high);
//printf("%x", pRunningTask->return_add_low);
jump_label = pRunningTask->return_add_high ;
#asm
movf jump_label,w
movwf PCLATH
#endasm

jump_label = pRunningTask->return_add_low ;
#asm
movf jump_label,w
movwf PCL
#endasm
return ; //won't actually return because it changes the program counter
}



1) Unless a time sensitive function - may be an interrupt handler- I try to
ovoid the use of #asm mixed with C.
2) I prefer not to use an #asm call inside a function, just do it with C.
3) With C you almost always will find a way to replace an #asm routine.

Humberto
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