View previous topic :: View next topic |
Author |
Message |
Edstroyer Guest
|
turning off BRA when calling a function |
Posted: Wed Aug 06, 2008 7:41 pm |
|
|
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! |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Aug 06, 2008 9:02 pm |
|
|
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
} |
|
|
![](templates/subSilver/images/spacer.gif) |
Edstroyer Guest
|
|
Posted: Thu Aug 07, 2008 3:54 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: turning off BRA when calling a function |
Posted: Fri Aug 08, 2008 4:54 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|