Tool/software: Code Composer Studio
This code never exits the loop. LongCount is incremented in an interrupt
void mSWait( unsigned int WaitDuration ) // measured in units of 1 ms
{
unsigned int msTimer = LongCount;
while((LongCount - msTimer) < WaitDuration);
}
This is the dissassembly
mSWait():
b208: 421E 0488 MOV.W &LongCount,R14
$C$L2:b20c: 4E0F MOV.W R14,R15
b20e: 8E0F SUB.W R14,R15
b210: 9C0F CMP.W R12,R15
b212: 2BFC JLO ($C$L2)
b214: 4130 RET
no surprise that it never exits since &LongCount is not read inside the loop
Same with this code:
void mSWait( unsigned int WaitDuration ) // measured in units of 1 ms
{
unsigned int msTimer = LongCount;
unsigned int x;
do x=LongCount - msTimer - WaitDuration;
while( x );
}
however changing the while to while(x<0) works. The irony is that the compiler says that it is a pointless comparison. Help!