|
|
View previous topic :: View next topic |
Author |
Message |
Guest
|
"Volatile" is it possible to use the keyword in CC |
Posted: Sun Mar 22, 2009 9:32 am |
|
|
Hi all,
I have a query related to CCS C optimisation.
Does it support "volatile" key word.
I have a chuck of code as follows
Code: | tmRPS = RPS;
handleKeypad();//may change the value of RPS by user from keypad
if(tmpRPS != RPS)
{
//perform controll action
//Control loop
} |
the memory being alocated for both RPS and tmpRPS is different , RPS is global variable , and tmpRPS is local variable.
if the value of RPS is changed within the function handleKeypad() then the value of tmpRPS automaticaly changes to the new value of RPS. Thus the program execution never enters the control loop as both are always equal.
I tried making both RPS,tmpRPS as volatile int32 variables but it dose not work.
Is there any way out to prevent the compiler to do such an optimisation.
My set optimisation level is 0. I have done it through the MPLAB Ide options.
Or is it require to specificaly use #opt option in the code.
I have one more question,
in a particular function i have a for loop counting up to 3
inside this for loop i have a permenent while loop scanning for a particular key press. when i detect a key press i increment a particular variable and break from the while loop by using the key word "break;".
It is expected that the for loop is executed for 2 more times, but some how after the "break" is executed for the first time the for loop is also exited. whihc is quite strange. Can any body help me out os these strange issues.
Thanks and regards
Rohit |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sun Mar 22, 2009 10:10 am |
|
|
What version are you using? The memory allocation problem sounds like one CCS had back in version 3. How about providing some code we can drop in and test? |
|
|
RLScott
Joined: 10 Jul 2007 Posts: 465
|
Re: "Volatile" is it possible to use the keyword i |
Posted: Sun Mar 22, 2009 10:17 am |
|
|
Anonymous wrote: | Hi all,
I have a query related to CCS C optimisation.
Does it support "volatile" key word.
I have a chuck of code as follows
tmRPS = RPS;
handleKeypad();//may change the value of RPS by user from keypad
if(tmpRPS != RPS)
{
//perform controll action
//Control loop
}
the memory being alocated for both RPS and tmpRPS is different , RPS is global variable , and tmpRPS is local variable.
if the value of RPS is changed within the function handleKeypad() then the value of tmpRPS automaticaly changes to the new value of RPS. Thus the program execution never enters the control loop as both are always equal.
I tried making both RPS,tmpRPS as volatile int32 variables but it dose not work.
|
I don't think the problem is what you think it is. Take a look at the generated .LST file to see for sure what the compiler is doing with your "if" statement.
Quote: |
in a particular function i have a for loop counting up to 3
inside this for loop i have a permenent while loop scanning for a particular key press. when i detect a key press i increment a particular variable and break from the while loop by using the key word "break;".
It is expected that the for loop is executed for 2 more times, but some how after the "break" is executed for the first time the for loop is also exited.. |
A break executed in the inner "while" loop will only take you out of that "while" loop. It will not force an exit from the "for" loop, unless you did something in the "while" loop that changes the variable being used in the "for" loop. _________________ Robert Scott
Real-Time Specialties
Embedded Systems Consulting |
|
|
|
|
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
|