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

Corrupt scratch variable (18F8720, PCWH 3.190)

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



Joined: 09 Sep 2003
Posts: 95
Location: UK

View user's profile Send private message Send e-mail Visit poster's website

Corrupt scratch variable (18F8720, PCWH 3.190)
PostPosted: Tue Mar 01, 2005 2:03 pm     Reply with quote

Tough one to explain, but here goes ...

I have the following (simplified) snippet of code ...

Code:

void barcode_check(void) {
   int8 i;

   /* if any chars rxed from com2 */
   if (!queue_empty(&serial.com2.qrx)) {
      // ... do stuff ...
   }
}

int1 queue_empty(queue_struct *q) {
   return(q->size == 0);
}

I also have a timer interrupt occuring at non-regular intervals.

Under MPLAB, I can breakpoint at the "do stuff" section and, when it breaks, I check the q->size value. It's zero.

This is a large piece of code, and I have several instances where this has happened, and not just with the queue_empty() function. It happens with other functions that return int1.

So, I have then changed the ...

Code:

   if (!queue_empty(&serial.com2.qrx)) {

... to ...
Code:

   if (serial.com2.qrx.size != 0) {

... and, hey presto, the problem goes away.

I have concluded that ...
(1) the queue_empty() function has just returned, with its true/false value returned in the 0x01 scratch variable
(2) my timer interrupt then occurs
(3) when the interrupt returns, somehow the 0x01 scratch variable gets corrupt

I have also tested this by placing global flags in the queue_empty() function that hold a copy of the true/false value the function is returning. When the "problem" occurs, the function appears to have returned false, but the global flag says otherwise Shocked

Turning off the interrupt gets rid of the problem (i.e. no false true/false values).

I am going to try and code a smaller, more concrete, example for others to try.

But in the meantime, has anyone ever encountered this before ?[/code]
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 01, 2005 2:31 pm     Reply with quote

Not recently, but it did happen once:
http://www.pic-c.com/forum/old/messages/2089.html

One question. You said you can break on it. Are you using ICE
or ICD2 ? Potentially, the problem could be in there.
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