AnsweredAssumed Answered

How can I get the CPU tick count on an MPC5744P?

Question asked by Igor Modino on Oct 20, 2017
Latest reply on Oct 26, 2017 by Igor Modino

Dear all.

We are willing to implement time-based timeout functions and would need a consistent time reference for that. Our approach is to use the tick counter (TBR register). From an NXP document (https://www.nxp.com/docs/en/reference-manual/MPCFPE32B.pdf ), we've found that the code for doing that should be:

 

loop:

   mftbu rx #load from TBU

   mftb ry #load from TBL

   mftbu rz #load from TBU

   cmpw rz,rx #see if ‘old’ = ‘new’

   bne loop #loop if carry occurred

 

We've seem examples from other sources that are exactly the same, so our implementation code we use is as follows:

 

static uint64_t UTILS_tickCountGet (void) {
   uint64_t result=0;
   uint32_t upper, lower,tmp;
   asm(
      "0: \n\t"
      "mftbu %0 \n\t"
      "mftb %1 \n\t"
      "mftbu %2 \n\t"
      "cmpw %2,%0 \n\t"
      "e_bne 0b \n\t"
      : "=r"(upper),"=r"(lower),"=r"(tmp)
   );
   result = upper;
   result = result<<32;
   result = result|lower;

   return(result);
}

 

However, when we call this functions, the program halts as an non recoverable exception seems to be triggered.

We've tried removing code, but any "mftb" or "mftbu" instruction seems to trigger it. We've also tried using registers rather than memory references and the result is the same.

 

May it be that these instructions are not present in the MPC5744P? (should raise a compile time issue, though).

 

Anyway, how will be the right way to get the CPU tick count?

 

Thanks

Outcomes