Tool/software:
Timing function used in the VPS driver:
BspOsal_getCurTimeInUsec
Retrieves the current time in microseconds by reading the CPU's internal clock cycle counter register.
UInt64 BspOsal_getCurTimeInUsec(void) { static UInt64 cpuMhz = 500U; /* default */ static Bool isInit = FALSE; UInt64 cpuHz; UInt64 curTs, curTimeUsec; if (FALSE == isInit) { /* do this only once */ isInit = (Bool) TRUE; /* convert to Mhz */ cpuHz = BspOsal_getTimestampFreq(); cpuMhz = (cpuHz / (1000U * 1000U)); } curTs = BspOsal_getTimestamp64(); curTimeUsec = (curTs / cpuMhz); return (curTimeUsec); }
In RTOS, the function Utils_getCurGlobalTimeInUsec
directly reads the value from a register and divides it by 32,786 Hz (the clock is derived from a 20 MHz source divided by 610, which is not the standard 32,768 Hz) to obtain the time in microseconds.
#define COUNTER_32K_CR_REG_PHYS_ADDR (0x4AE04030) #define COUNTER_32K_CR_REF_CLK (32786U) /* Actual value used on 20M/610 610 is post div in clock tree*/ UInt64 Utils_getCurGlobalTimeInUsec(void) { UInt64 curGblTime; UInt32 oldIntState; UInt64 clk32KhzValue; UInt64 clk32KhzValue64; uint64_t temp; /* Using uint64_t datatype as UInt64 datatype causes MisraC issue while performing shift operation*/ oldIntState = Hwi_disable(); clk32KhzValue = COUNTER_32K_CR; if(clk32KhzValue < gUtils_GlobalTimerObj.oldClk32KhzValue) { gUtils_GlobalTimerObj.clk32KhzOverflow++; } temp = (uint64_t)gUtils_GlobalTimerObj.clk32KhzOverflow & 0xFFFFFFFFU; temp = temp << 32U; clk32KhzValue64 = (UInt64)clk32KhzValue | temp; curGblTime = (1000000U*clk32KhzValue64)/COUNTER_32K_CR_REF_CLK; gUtils_GlobalTimerObj.oldClk32KhzValue = clk32KhzValue; Hwi_restore(oldIntState); return (curGblTime); }
Through debugging output, I found that the two timestamps are not the same. I would like to know: do the two functions access the same register? Which one provides more accurate timing? Could the fact that my timestamp intervals are not exactly 100 ms be related to the clock source inside the MMWCAS-DSP-EVM?