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

turning off BRA when calling a function

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







turning off BRA when calling a function
PostPosted: Wed Aug 06, 2008 7:41 pm     Reply with quote

Basically CCS uses BRA instruction to execute functions (sometimes) to save the stack space usage. Then branches back when function is returned.

However, I'm developing my own pre-emptive RTOS, and I want the compiler to always use RCALL instead of BRA. That way I can manage the stack correctly.

Can i disable this feature of the compiler for PIC18 ?

I used the #separate, but it doesnt solve the problem.

Thanks in advance!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Aug 06, 2008 9:02 pm     Reply with quote

You could trick the compiler by using a 2nd call the function, but place
the 2nd call after an infinite loop so that it's never actually reached.
The following program will use RCALL to call func():
Code:
#include <18F452.h>
#fuses XT,NOWDT,NOPROTECT,BROWNOUT,PUT,NOLVP
#use delay(clock=4000000) 
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

void func(void)
{
char c;
 
c = 0x55;
}

//=========================
void main()
{

func();

while(1);
func();   // This dummy call is never executed
}
Edstroyer
Guest







PostPosted: Thu Aug 07, 2008 3:54 pm     Reply with quote

Thank you, thats exactly what I did when i noticed that functions that where called multiple times used RCALL instead so I inserted a second dummy call for all my tasks (at the end of program) and it worked, but I thought it would be unprofessional to do something like that... I was hoping for a feature option that would turn it off.

Thanks anyways, your great PCM PROG!

Ed
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: turning off BRA when calling a function
PostPosted: Fri Aug 08, 2008 4:54 am     Reply with quote

Edstroyer wrote:
Basically CCS uses BRA instruction to execute functions (sometimes) to save the stack space usage. Then branches back when function is returned.

However, I'm developing my own pre-emptive RTOS, and I want the compiler to always use RCALL instead of BRA. That way I can manage the stack correctly....


I fail to see why using the BRA instruction for entering and leaving a function that is only called from one place in the code is any threat to your pre-emptive RTOS.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
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