lpcware

RIT timer possible overrun

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by efiLabs on Sun Dec 14 22:29:48 MST 2014
friends :

i noticed the following code in LpcOpen rtitimer_15xx.c

/* Returns the current timer Counter value */
uint64_t Chip_RIT_GetCounter(LPC_RITIMER_T *pRITimer)
{
uint64_t val;

val = (uint64_t) pRITimer->COUNTER_H;
val = val << 32;
val |= (uint64_t) pRITimer->COUNTER;

return val;
}

how about if the timer rolls over into the high part between the 2 reads ???

i didn't find anything in the user manual stating if the high part is being read 1st the low reading following it contains a saved copy of the low part from the time of the high part read

my solution was

  ulong h0 = LPC_RITIMER->COUNTER_H ;
  ulong lo = LPC_RITIMER->COUNTER ;
  ulong h1 = LPC_RITIMER->COUNTER_H ;

and if h0 != h1 reread the low part

any other suggestions please ???

cheers efiLabs


Outcomes