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.

RTOS/AM5726: Using system clock for time measurement

Part Number: AM5726
Other Parts Discussed in Thread: SYSBIOS,

Tool/software: TI-RTOS

Hi everybody , 

I need to have a function in my code  doing some time measurements .  

since we are in a team , I would like to have a code that read  clocking  in the chip and allows me to do proper timing calculations . 

Where is a register or API function that tells me the actual selected system frequency of the core in order to calculate from unit [timerCounts] to [us]?

do you suggest for a time meauserment some ticking in the system ? 

thank you 

regards

carlo

  • Hi Colombo,

    Which core are you interested in? Are you using SYS/BIOS?

    Todd
  • Hi Todd ,
    I m interested on A15 , yes I m in TIrtos
    thank you
    regards
    Carlo
  • Hi Carlo,

    You can use the Timestamp module for time measurements.  You can add the following line to your .cfg file:

    var Timestamp = xdc.useModule('xdc.runtime.Timestamp');

    Since you are building for the A15 on, BIOS will select the ti.sysbios.family.arm.a15.TimestampProvider as the Timestamp delegate.  The A15 TimestampProvider uses the A15's internal PMC counter, which is running at the CPU frequency.

    In your C code, to measure time:

    #include <xdc/runtime/Timestamp.h>

    UInt32 t1, t2, delta;

    t1 = Timestamp_get32();

    ...

    t2 = Timestamp_get32();

    delta = t2 - t1;  // Number of CPU cycles taken

    Is that the sort of time measurement you were looking for?

    Best regards,

    Janet

  • Hi Janet
    great thank you very much !
    regards
    Carlo
  • Hi Janet ,
    any suggestions about the other question in this post :
    Where is a register or API function that tells me the actual selected system frequency of the core in order to calculate from unit [timerCounts] to [us]?
    thank you very much
    regards
    Carlo
  • Hi Carlo,

    You can use Timestamp_getFreq() to determine the frequency of the timestamp counter:

      #include <xdc/runtime/Timestamp.h>
      #include <xdc/runtime/Types.h>

        Void Timestamp_getFreq(Types_FreqHz *freq)

    Check the XDC tools cdoc for more information (see the xdctools release notes on documentation).  Here is an example:

        Types_FreqHz freq;

        Timestamp_getFreq(&freq);
        t1 = Timestamp_get32();
        ...
        t2 = Timestamp_get32();
        msecs = ((t2 - t1) * 1000) / freq.lo;    // Time in milliseconds

    Best regards,

    Janet

  • Part Number: AM5726

    Tool/software: TI-RTOS

    Hi everybody , 

    please I m trying to use suggestions as per previous post :  e2e.ti.com/support/arm/sitara_arm/f/791/p/694962/2566045#2566045 

    I used TimestampProvider.h instead of Timestamp.h but the situation will be most likely similar. Please look at the attached  picture.

    The Task_sleep() works in units [ms] and the u32_total_time reflects this, but I know that the example project is running at lowered speed of 1[GHz] and not 1.5[GHz].

    Any idea why TimestampProvider_getFreq() gives me 1.5[GHz] instead of 1[GHz]?  

    where am I wrong ? 

    thank you very much

    regards

    Carlo

  • Hi Carlo,

    The Timestamp frequency returns the value that BIOS thinks the CPU is running at (1500 MHz).  If your CPU is running at a lower speed (1000 MHz), you can add these lines to your .cfg file:

    var BIOS = xdc.useModule('ti.sysbios.BIOS');

    BIOS.cpuFreq.lo = 1000000000;

    Setting BIOS.cpuFreq does not actually change the CPU frequency.  It is only informational so that timestamps and Clock ticks are accurate.

    Best regards,

    Janet