AnsweredAssumed Answered

Aggressive Optimizing?

Question asked by Laz on Oct 7, 2009
Latest reply on Oct 8, 2009 by Laz

I have a set of routines for simple low-precision timers.  In the following code with only minimal optimization (=30), the while-loop in delay_ms does not call isTimeout() in the loop, so it gets stalled.  I have examined the asembler and it really only calls isTimeout once, and then sits in jump (pc, 0);.  It works correctly with no optimization.  I understand the need for volatile declarations for variables, but do I need to do this for functions?  I am using a SHARC 21368 with VDSP 5.0.6.

 

// --------------------------------------------------------
// these are timeout functions, counting is done on every Sync
// useful for non-critical long duration timers
UINT timerCounter[NUM_TIMERS];
void startTimer (int channel, int mSec)
{
timerCounter[channel] = mSec * SYNC_PER_MSEC; // convert to Sync ticks
}

 

// called by the Sync ISR
void tickTimers (void)
{
UINT channel;

for (channel = 0; channel < NUM_TIMERS; channel++)
{
  if (timerCounter[channel] > 0)
   timerCounter[channel]--;
}
}

 

boolean isTimeout (UINT channel)
{
return (timerCounter[channel] == 0);
}

 

void delay_ms (int mSec)
{
startTimer(DELAY_TIMER, mSec);

while (!isTimeout(DELAY_TIMER)); // wait until the time expires
}

Outcomes