look

Nucleus Plus 1.2 question

Discussion created by look on Jun 27, 2012
Latest reply on Jul 11, 2012 by oman_nadeem

Hi,

I'm an engineer working on some legacy products where we have a PC104 that runs Nucleus Plus 1.2. We recently found a bug in code that freezes up the machine by creating a state in the while loop that runs for a really long time. Its basically a delay function. We have fixed the bug, but still want to find out the root cause. We would like to know from the nucleus team what the root cause is. Here is what we have seen so far. Most of the time we see that after we call new NU_Sleep(10) and check NU_Retrieve_Clock(), at the top of the while loop, it is 10 (or timeleft) ticks greater than before we slept, as expected. However, other times NU_Retrieve_Clock() returns a value greater than what the time slept was specified. And if we NU_Retrieve_Clock() is one tick greater than endtime, the while loop will run until the NU_Retrieve_Clock() value rolls back around to match endtime. We have implemented fixes in this code in the while condition but really want to know why NU_Sleep() does not always yield the expected results from NU_Retrieve_Clock(). Here is our code:

 

 

 

void Delay (delayTimeInTicks)

{

endTime=NU_Retrieve_Clock() + delayTimeInTicks;

 

while((timeLeft= (endTime - NU_Retrieve_Clock() )) > 0) //Loop ends when endTime = NU_Retrieve_Clock()

{

      /* kick the watch dog timer */

      Fault_Kick_WDT();

 

      if (timeLeft<10)

      {

           NU_Sleep(timeLeft);

      }

      else

      {

           NU_Sleep(10);

      }

}

}

Outcomes