Charles Barnes

Data misalign and codewarrior acting funny

Discussion created by Charles Barnes on Jul 17, 2008
Latest reply on Jul 24, 2008 by Charles Barnes
Codewarrior IDE version and the 56F8367 chip

Alright, funky things are happening to me and I am at a loss right now because of the way Codewarrior is acting.

First things first.  I noticed I had a problem when I was trying to communicate over the SCI interface into the chip.  I had my communication interface bug free for a while.  I did do some updates (which I will get into later).  However, I noticed that whenever I would use the interface some of the data would get corrupted.  The right data would still get stored from the communication, but it appeared an LUT I had was getting corrupted.  I then found that if I tried to send enough packets to the chip, I would eventually hop out into the interrupt handler for "misaligned long word access interrupt."

So I started to put some break points into my code to find out where the problem was.  So I would put a breakpoint on line 1 of function foo().  Even though I should not be getting into foo() I was still hitting the break point.  The weird thing is that every time I would start the program again, it would just immediately stop on that break point.  I put a break point on the line 10 of foo() and it stopped on it which makes sense.  However, every time I hit play again it would stop on line 10 of foo() even though it HAD to go over line 1 of foo() and line 1 still had a break point and there are no conditionals or loops in the code I am working in.  WTF?

So I went back further in the code.  I went right back to the beginning of this function (which is where it should have blocked me from getting into this code in the first place) and put a break point there.  So this code is blocked by an if statement comparing two pointers (into the receive queue), msgQ_in and msgQ_out.  If they do not equal each other, I go into the block "if (msgQ_in != msgQ_out){".  So I put the break point right after it INSIDE the {}.  It hits this break point without fail.  I view the variables and they are equal, yet I still get into this code block.  I set them equal to each other on the line BEFORE the if statement and commented out every other assignment to them in the code (other than the initialization of them, of course) and it STILL gets into the code block.

Considering that this is incredibly frustrating to debug I have been trying a number of things.  One thing I tried was putting a static test variable in these functions that counts everytime it gets into it.  For some reason this stops Codewarrior from jumping into the misalign, however, I am still inappropriately getting into that block of code.  If I remove it the static count variable, the misalign pops back up again.

The only major change I made to the code between when it was working and when it was not is that I replaced the updating the pointer into the queue, which was a couple of lines of code to make sure you go back to the beginning of the queue when you get to the end (more for readability than anything), with a subroutine that gets the pointer value, updates it, and then returns the updated value.

Does anyone have any suggestions?  Does this remotely make any sense?

Message Edited by Charlie on 2008-07-17 09:06 PM