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.

64bit Timer



Hi,

I have c6678, pdk 1.0.0.17

I am trying to create a simple 64 bit gp timer, I copied from timer_test.c the following code:

CSL_TmrHandle               hTmr;

CSL_TmrObj                  TmrObj;

CSL_Status                  status;

CSL_TmrHwSetup              hwSetup = CSL_TMR_HWSETUP_DEFAULTS;

CSL_TmrEnamode              TimeCountMode = CSL_TMR_ENAMODE_ENABLE;

 

/* Clear local data structures */

memset(&TmrObj, 0, sizeof(CSL_TmrObj));

printf("Debug: Testing 64bit Timer in Single Shot Mode...\n");

hTmr =CSL_tmrOpen(&tmrObj, 0, NULL, &status);

if (hTmr == NULL)      

return -1;

 

/* 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 SINGLE SHOT Mode. */

CSL_tmrHwControl(hTmr, CSL_TMR_CMD_START64, (void *)&TimeCountMode);

 

//First time

CSL_tmrGetTimHiCount(hTmr, &countHi);

CSL_tmrGetTimLoCount(hTmr, &countLo);

//Second time

CSL_tmrGetTimHiCount(hTmr, &countHi);

CSL_tmrGetTimLoCount(hTmr, &countLo);

 

In the second time I get ountHi=0 and countLo=0, is their an option that the counter will not be stopped and cleared after I read it? and what is the size of the time period?

  • It should not reset it by reading the timer values unless Time Control Register (TCR) has the READRSTMODE_HI and READRSTMODE_LO bitfields set to 1, which means that when you read the high and low counts it resets them.  These should be 0 since you're initializing hwSetup w/ CSL_TMR_HWSETUP_DEFAULTS which sets everything to their Reset values.   Can you dump the TCR register for the timer you're using (do this after calling the CSL_tmrHwSetup and again before calling the CSL_tmrGetTimHiCount's.) 

    The information on how the timer operates is detailed in the Keystone Timer64 UG and may be easiest to start there along w/ the register values for debugging this.

    Best Regards,

    Chad

  • Hi Chad,

    TCR register values are:

    After CSL_tmrHwSetup :0x00000090

    Before CSL_tmrGetTimHiCount: 0x00410050

    READRSTMODE_HI and READRSTMODE_LO  equal 0

    Thanks,

    Aviv

     

  • Aviv,

    It shouldn't be resetting the timer register with the values you provided there.  Can you attach the code you're using.  Also, can you confirm if you're working with the Simulator or real hardware?

    Best Regards,
    Chad

  • Hi Chad,

    I attached my code. I added my code to client.c file in ndk  client exanple  in row number 459.

    I am working with real hardware.

    Thanks,

    Aviv
    3343.client.zip

     

  • Aviv,

    Thanks for the code, I've asked someone to take a look at it on HW.

    Best Regards,

    Chad

  • Aviv,

    You are using the single shot mode of the Timer, which means the timer is enabled one time. The timer stops after the timer counter reaches the timer period. Please refer to the TCR register description and Section 3.5 in the Timer user guide.

    The "printf" will take hundreds of cycles and the period you defined is too short for that. So the timer already stops in the second time and returns as 0x0 in your programming.

    You can increase the period to be large enough in your applications such as

    hwSetup.tmrTimerPeriodLo = 0xffffffff;

    hwSetup.tmrTimerPeriodHi = 0x00;

    Or you can use continuous mode described in the Timer user guide as well.

    Hope it helps.

    Sincerely,

    Steven

  • Hi Steven,

    I found out that timers 1-5 got reset after reading them even if hwSetup.tmrTimerPeriodLo and  hwSetup.tmrTimerPeriodHi values were large enough.

    Timer 7 doesn't get reset after reading it. PRDHI and PRDLO registers equal 0xffffff  and setting hwSetup.tmrTimerPeriodLo and hwSetup.tmrTimerPeriodHi does not change the registers value.

    So I am using timer 7. 

    I am tying to compare os clock to the timer, I know timer ticks at cpu/6, when  I do TaskSleep(10) I get timer delta of 7.8ms is it o.k? 

    Thanks

    Aviv