This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC2538DK: Sleep timer will go backward?

Part Number: CC2538DK

Hello,

I am using Contiki-OS with CC2538DK to do some experiment.

I found out that some time system's clock will have strange behavior.

Contiki get CC2538's sleep timer value to calculate system time using following code: 

rtimer_clock_t
rtimer_arch_now()
{
  rtimer_clock_t rv;

  /* SMWDTHROSC_ST0 latches ST[1:3] and must be read first */
  rv = REG(SMWDTHROSC_ST0);
  rv |= (REG(SMWDTHROSC_ST1) << 8);
  rv |= (REG(SMWDTHROSC_ST2) << 16);
  rv |= (REG(SMWDTHROSC_ST3) << 24);

  return rv;
}

(

)

However, it seem like the sleep timer won't increase every time i get the value. it will go backward sometime.

EX:

First time i get the value: 1231018689

and the next time i get the value: 1231018688

This will mess up the clock time calculation.

How do i solve this issue?

Thanks

  • Hi,

    the access looks correct. Is there a possibility that this function is re-entered while being executed, for instance by an interrupt handler? If yes, you could try to protect it by locking interrupts.

  • Hi, 

    isn't CC2538 single thread? will it interrupt multiple time in the same time?

    Or is there any document say about sleep timer will not going backward?

    Thanks,

    Green

  • It doesn't need to be interrupted multiple times. It is enough that it gets interrupted once by an interrupt handler and somewhere in the interrupt handler the sleep timer is read. But I have no idea if that could be the case. You could just lock interrupts while accessing the sleep timer to see if that solves the problem.

    Make sure that nothing is reading the sleep timer while the above code executes. Concurrent read can also happen when step-debugging. So be aware.

    I am not aware of any hardware-related problem reading the sleep timer on the CC2538.