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.
Tool/software: TI-RTOS
Hello,
I am using Timestamp_get64() to get the time stamp and Timestamp_GetFreq() to get the cpu frequency.
My cpu frequency is 80Mhz.
I am trying to get the execution time in milliseconds. I tried to use as below.
Timestamp_get64(&ts);
...
My code Here
....
Timestamp_get64(&te);
start64 = ts.hi << 32;
start 64 |= ts.lo;
end64 = te.hi << 32;
end64 |= te.lo;
millisec = (end64 - start64) / 80000; // My cpu clock is 80MHz received by Timestamp_getFreq()
But in every 1minute, the milisecs value get overflowed.
How can I find the millisecs correctly.
Thanks
Jagan
>> What do you have start64 and end64 defined as? What compiler version and SYS/BIOS are you using?
both start64 and end64 are defined as unsigned long long. (64bit).
>> Also, just to confirm..."start 64 |= ts.lo;" is a typo in the thread. You meant "start64 |= ts.lo;".
You are correct. It was a typo.
Thanks
Jagan
Hi Jaganath,
Here is an example of how you can timestamp your code:
#include <xdc/runtime/Timestamp.h>
#include <xdc/runtime/Types.h>
uint64_t ts_1, ts_2;
Types_Timestamp64 ts64_1, ts64_2;
Types_FreqHz freq;
uint64_t delta;
uint64_t deltaMS;
Void heartBeatFxn(UArg arg0, UArg arg1)
{
Timestamp_getFreq(&freq);
while (1) {
Timestamp_get64(&ts64_1);
Task_sleep((unsigned int)arg0);
GPIO_toggle(Board_LED0);
Timestamp_get64(&ts64_2);
ts_1 = ((uint64_t)ts64_1.hi << 32) | ts64_1.lo;
ts_2 = ((uint64_t)ts64_2.hi << 32) | ts64_2.lo;
delta = ts_2 - ts_1;
deltaMS = delta / (freq.lo / 1000);
}
}
I'm not seeing any overflow with this code. I also tried using 'long long' in place of uint64_t, but could still not reproduce the problem. My CPU frequency is 150MHz, so the 'hi' field of ts64_1 and ts64_2 becomes non-zero after about 28 seconds. I just added time stamping to the TIRTOS empty example. You also need to add this line to your .cfg file:
var Timestamp = xdc.useModule('xdc.runtime.Timestamp');
Best regards,
Janet
Hello Janet,
Thank you for explaining with the sample code.
I also observed in almost every 50 sec, in my 80Mhz clock, the ts64_1.hi gets non-zero. I was considering only ts64_1.lo for my calculation. So I observed it is getting reset as the delta was getting negative in every 50 sec approx.
that means, Timestamp_get32() will never give me accurate result, as it gives a 32bit timestamp.
Can you let me know what is the unit of timestamp that means how frequently it is updated ?
When shall i use the timestamp_get64() ?
Thanks
Jagan
Hi Jagannath,
You can still use Timestamp32() to benchmark code, as long as the section of code you are benchmarking takes less time to execute than the time it takes for the timestamp counter to wrap. For example, this code works because the section I am benchmarking takes less than 2 seconds to execute:
uint32_t ts32_1, ts32_2;
uint32_t delta32, deltaMS32;
Void heartBeatFxn(UArg arg0, UArg arg1)
{
Timestamp_getFreq(&freq);
while (1) {
ts32_1 = Timestamp_get32();
Task_sleep((unsigned int)arg0);
GPIO_toggle(Board_LED0);
ts32_2 = Timestamp_get32();
delta32 = ts32_2 - ts32_1;
deltaMS32 = delta32 / (freq.lo / 1000);
}
}
Even if ts32_2 is less than ts32_1, because they are unsigned types, the math works out. The timestamp frequency, obtained by calling Timestamp_getFreq(), tells you how many times the timestamp tick count is updated in one second. I am running my test on an F28M36, so my Timestamp frequency (.lo) is 150,000,000. This means the Timestamp counter will wrap about every 28 seconds (4294967296 / 150000000).
Best regards,
Janet