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.

66AK2E05: Hardware Timer to get precise time

Expert 1010 points
Part Number: 66AK2E05


we have a 66ak2e05 with default Linux image on it (MCSDK 3.01.04_04). Instead of unprecise std::chrono::steady_clock::now() to measure time between events in code, I want to switch to hardware timer to get high precision timer.

This is exactly what is stated in documentation:

"The timers can be used to time events, count events, generate pulses, interrupt the C66x CorePacs and ARM CorePac and send synchronization events to the EDMA3 channel controller."

Still according to documentation, I can use Timer16 for core A15-0 or Timer8 to Timer15 as general purpose timer:

"The 66AK2E0x device has up to twenty 64-bit timers in total, but only 13 timers are used in 66AK2E05 and 12 timers are used in 66AK2E02, of which Timer0 is dedicated to the C66x CorePacs Core 0 as watchdog timers and can also be used as general-purpose timers. Timer16 and Timer17 (66AK2E02) or Timer16 through Timer19 (66AK2E05) are dedicated to each of the Cortex-A15 processor cores as a watchdog timer and can also be used as general-purpose timers. The Timer8 through Timer15 can be configured as general-purpose timers only, with each timer programmed as a 64-bit timer or as two separate 32-bit timers."

I found code example with CSL library:

// Clear local data structures
memset(&tmrObj_, 0, sizeof(CSL_TmrObj));

hTmr_ = CSL_tmrOpen(&tmrObj_, 0, NULL, &status_);

if (hTmr_ == NULL){return false;}
timeCountMode_ = CSL_TMR_ENAMODE_CONT;

/* Set the timer mode to 64bit GP Timer Mode and set the PRD registers */
hwSetup_.tmrTimerMode     = CSL_TMR_TIMMODE_GPT;
hwSetup_.tmrTimerPeriodLo = 0x0f;
hwSetup_.tmrTimerPeriodHi = 0x00;

CSL_tmrHwSetup(hTmr_, &hwSetup_);
/* Reset the Timer */
CSL_tmrHwControl(hTmr_, CSL_TMR_CMD_RESET64, NULL);
/* Start the timer in CONTINUOUS Mode. */
CSL_tmrHwControl(hTmr_, CSL_TMR_CMD_START64, (void *)&timeCountMode_);

It compiles but linker has issues since I did not link to the right library.

Is it the right way to do? If yes, which library do I need to link to? If no, where can I find a project code example for Timer 64 for Cortex-A15 of 66AK2E05 soc (either for MCSDK or Processor SDK)?


  • I think that I should link to ti.csl.aa15fg but  there is no folder a15 at pdk_keystone2_3_01_04_07/packages/ti/csl/lib/k2e, only a c66 folder.

    How can I get this library?

  • Dpa,

    There is a CSL Timer example available for the ARM core of K2H in the pdk of Processor SDK.

    Let me try to build successfully and get back to you.

    Thanks for your patience,

    Shankari G

  • Dpa,

    For precide TIme calculation, this is how i use in my code and it worked promisingly. Please try this....

    This will make use of the clock ticks/cycles of DSP core running at  1000  MHz and it will be precise...

    Here you go.....

    Code snippet: 

    //Shankari-Start-Declaration  for time ticks

    #include "C:\ti\pdk_keystone2_3_01_04_07\packages\ti\csl\csl_tsc.h"


    extern uint32_t utilReadTime32();

    //Shankari-End-Declaration  for time ticks


    /*Throughput calculation initialization */

    unsigned int StartTime = 0;
    unsigned int EndTime = 0;
    unsigned int Total_cycle_ticks = 0;

    /*Throughput calculation initialization Ends */



    StartTime = utilReadTime32();

    // Please insert your code here 

    sauConnDmPktTest(tf, pat,
    100, /* Number of packets per connection */
    512, /* initial payload length */
    0, /* payload llength increment step */
    SAU_PAYLOAD_INC8 /* payload pattern */

    EndTime = utilReadTime32();

    Total_cycle_ticks = EndTime-StartTime;

     System_printf("StartTime = %d \n", StartTime);
     System_printf("EndTime = %d \n", EndTime);

     System_printf("Total_cycle_ticks = %d \n", Total_cycle_ticks);

    // System_printf(" sauConnDmPktTest 2048 PacketSize, 100 packets -Total_cycle_ticks = %d \n", Total_cycle_ticks);


    Time tick calculation , you can use according to the number of Total_cycle_ticks, you get......

    Total no of CPU cycles =    cycles 

    DSP core frequency = 1000 MHz


    Time = 1 / Freq ( General formula )

              = 1 / 1000 MHz ( DSP core frequency )

              = 0.001 us ( Micro seconds) 


    1000000000 cycles = 1 sec

    =>32149501  cycles =  0.032 sec


  • Hi Shankari,

    Thanks for the complete answer. Which library are you linking to ? I do not have ti.csl.aa15fg and ti.csl.ae66 is for DSP and my code runs on ARM A15.

  • dpa,

    I am including the header file of tsc. It comes under CSL library.

    #include "C:\ti\pdk_keystone2_3_01_04_07\packages\ti\csl\csl_tsc.h"

    This is on the DSP core...

    Search something similar to this On ARM core.


    Shankari G

  • Hi,

    Thanks Shankari for the fast answer. I tried to find something similar for A15 to what you described above. I did not find anything better than Timestamp_get32 or  Clock_getTicks but it seems both functions are in kernel space modules and I am programming in a user space application.

     Do you know any code example for these? 

    I did not find the CSL Timer example for the ARM core of K2H in the pdk of Processor SDK you mentionned before.

    Which version of the Processor SDK do you have?

  • Let me find and get back.

  • dpa,

    In testutil.c, For ARM core, I could see "__asm__ __volatile__ ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(timeVal));" 

    may be we can do a #undef _TMS320C6X and check, whether it fetches the timeval.

    * Function: Utility function a cycle clock
    uint32_t utilReadTime32()
    uint32_t timeVal;

    #if defined (_TMS320C6X)
    timeVal = TSCL;
    __asm__ __volatile__ ("MRC p15, 0, %0, c9, c13, 0\t\n": "=r"(timeVal));
    return timeVal;

    And also in the same file, testutil.c ( I use PROCESSOR-SDK-RTOS-K2E  06_03_00_106


    Please look for the code if "ARM11" is defined....



    /* Delay number of cycles */
    void utilCycleDelay (int count)
    if (count <= 0)


    while (count)

    uint32_t utilgAddr(uint32_t x)
    #if ARM11SIM_ON_NYSH /* Only for ARM11 testing on the simulator */

    if ((x >= 0x800000) && (x < 0x900000))
    x = (1 << 28) | (DNUM << 24) | x;

    return (x);



    Shankari G