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 CCS Technical Support

problem related to resource sharing , #locate , #reserve,ISR

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



Joined: 12 Apr 2009
Posts: 1

View user's profile Send private message

problem related to resource sharing , #locate , #reserve,ISR
PostPosted: Sun Apr 12, 2009 11:07 pm     Reply with quote

Hi ,
I am facing problems in using the interrupts (occurring every 0.2ms) along with the LCD display module.

When I disable the interrupt of timer3 occurring every 0.2ms then my LCD module is working fine, but when I enable this interrupt my LCD shows garbage data.

I am using my own version of sprintf for writing the variable values into buffer to make sprintf bit fast.

Following are the code lines
Code:
   char str[20] ;
   char str1[] = {"RPS= %d   "};          <---line 0
   sprintfR(str,str1,(U16)RPS);           <---Line 1
   //sprintf(str, (char *)"R = %d", 22 ); <---Line 2
   Display(str,(char)MAX_CHAR_DISPLAYED_BY_LCD); <---Line 3

When I call sprintfR() the function copies the str1 and value of rps into the string str successfully. I verified this by printing the contents of str onto the RS232 port. But when I pass this string to the Display() function then the str is not getting passed properly. I confirmed this by printing the passed string inside the Display function.

Point to note is that I am disabling the interrupt at compile time by not initalising the interrupt.
Also if I use sprintf() from library I am facing the same problem, but when I use sprintf() as shown in line 2, i.e. when a constant value 22 is passed it works.

I have got a feeling that the resources being used by the ISR routine are same as the one by Display() function. Either the general purpose registers used for passing the arguments are same or the stack locations.

If I call the Display() function inside the sprintf() function it works.
The problem is that this issue may come with other functions which are much more important than the display function which shows data only.

If any such important function is facing such an issue then I won't be able to detect it. I was able to detect this issue in LCD module because I was able to see the problem on LCD.

Is there any way by which I can use only specific registers for ISR and also specific stack region for AUTO/ and specific ram for static and global variables.
I have general knowledge of #locate and #reserve but I was not able to find out how the #locate be used for only a specific function. The #locate should not be applicable to the function below the ISR routine.
Also it would be help full if anybody can tell me how to use the specific register bank for ISR (in C coding), which won't be used for other functions
.

Thanks in advance
Rohit
Ttelmah
Guest







PostPosted: Mon Apr 13, 2009 2:32 am     Reply with quote

First, the in house' sprintf, will function in a completely different way to yours. You can't generate pointers to constant strings in CCS, in the default configuration, so the compiler will ignore the pointer cast, and instead use the CCS 'shortcut', extracting the characters from the constant, one at a time, not using the string functions at all. You don't show your sprintf, so we can't see what may be wrong with it.
The 'odds' are that the problem is not where you think it is. A typical 'guess', would be:
The string passed by your function, is not null terminated properly. You 'get away' with this without the ISR, but the ISR changes something further down in memory (where it is legitimately working), and makes this show a problem. Remember that your sprintf, when it gets to the null terminator, must copy this as well. Also, triple check your sizes, remember that when dealing with strings, you must always allow space for the extra terminator character. The situations you describe, where things do work, are all ones, where the compiler will have correctly terminated the strings....
The ISR, in CCS, is extremely good at not changing anything used elsewhere. They spend a lot of effort (too much a lot of the time....), saving _every_ register, before executing the ISR code, and restoring these afterwards.
You can go DIY for the ISR. You don't need locate, or reserve. Just declare an int_global, have it save every register into a static memory array. Then test what interrupt has triggered, and call the corresponding subroutine, when this returns, restore all the registers, and you have duplicated the functionality of the CCS code, and gained nothing......
The only reason for the ISR overwriting anything, or the main code behaving as if this is happening, is that something in your code (either in the ISR, or in the main), _is_ using values outside the memory areas reserved for it. Using locate and reserve, won't stop this, you need to find what is doing it. String/array operations (the former in particular, if the terminator is missed), are the 'classic' operations to do this......

Best Wishes
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