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.

TM4C1294NCPDT: TI-RTOS - Timestamp - How to setup clock source other than system clock?

Part Number: TM4C1294NCPDT
Other Parts Discussed in Thread: SYSBIOS

Dear SupportTeam,

How to make Timestamp module to use ticks other than system tick.
We have set system clock frequency to 120 MHz but for timestamp application we would like to use lower frequency.

Thanks & Regards

Abhijit

  • Hi Abhijit,

    Which version of TI-RTOS are you using?

    The Timestamp can be modified to not use the Clock timer. Try modifying your kernel configuration (*.cfg) file with the following.

    var TimestampProvider = xdc.useModule('ti.sysbios.family.arm.lm4.TimestampProvider');
    TimestampProvider.useClockTimer = false;


    Derrick

  • Hi,

    Thank you for your reply. TI-RTOS version 2.16.

    After making the change that you suggested, what will be the clock source for timestamp provider?

    Thanks 

    Abhijit

    #include

  • Hi Abhijit,

    After looking into this further, I realized that changing the TimeStampProvider will not change the timestamp's frequency.

    In fact, SYSBIOS currently does not have support for doing so; therefore, the timestamp's source frequency will always be the same as the system clock (typically 120 MHz for TM4C).

    However, I do have an alternative I can suggest.
    You can implement your own timestamp provider inside your application using the ti/sysbios/family/arm/lm4/Timer.h module.

    To do so, first add the following to your kernel configuration (*.cfg). This will statically create a kernel Timer instance.:

    var Timer = xdc.useModule('ti.sysbios.family.arm.lm4.Timer');
    var params = new Timer.Params;
    
    /* Timer will run continuously */
    params.runMode = Timer.RunMode_CONTINUOUS;
    
    /* Timer will start automatically */
    params.startMode = Timer.StartMode_AUTO;
    
    /* Set the period to the max value */
    params.period = 0xFFFFFFFF;
    params.periodType = Timer.PeriodType_COUNTS;
    
    /* For TM4C devices, this will be a 16 MHz tick source */
    params.altclk = true;
    
    /*
     * myTimerHandle will be a symbol globally accessible. Your application
     * just needs to include #include <xdc/cfg/global.h>
     * This handle can be used with any of the SYSBIOS timer APIs.
     */
    Program.global.myTimerHandle = Timer.create(Timer.ANY, null, params);

    Next, try using the simple example below in an application. It simply uses the timer created in the kernel configuration (*.cfg). The task sleeps for a second and then gets the current timer count.

    /* XDC module Headers */
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    
    /* BIOS module Headers */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Task.h>
    
    #include <xdc/cfg/global.h>
    #include <xdc/runtime/Types.h>
    #include <ti/sysbios/family/arm/lm4/Timer.h>
    
    #include <ti/drivers/Board.h>
    
    Void task0Fxn(UArg arg0, UArg arg1);
    
    Types_FreqHz freq;
    Task_Struct task0Struct;
    Task_Handle taskHandle;
    Char taskStack[512];
    
    /*
     *  ======== main ========
     */
    int main()
    {
        /* Construct BIOS Objects */
        Task_Params taskParams;
    
        /* Call driver init functions */
        Board_init();
    
        Task_Params_init(&taskParams);
        taskParams.stack = &taskStack;
        taskParams.stackSize = 512;
        Task_construct(&task0Struct, task0Fxn, &taskParams, NULL);
    
        /* Get the timer frequency. We expect freq.lo to return 16 MHz */
        Timer_getFreq(myTimerHandle, &freq);
    
        BIOS_start();    /* does not return */
        return(0);
    }
    
    Void task0Fxn(UArg arg0, UArg arg1)
    {
        UInt count, timeSec, timeUsec, i = 0;
    
        while (1) {
            /*
             * Get the current timer ticks, this will return 0 if called before
             * BIOS_start(). This should be comparable to calling Timestamp_get32().
             */
            count = 0xFFFFFFFF - Timer_getCount(myTimerHandle);
    
            /* Calculate time elapsed since BIOS_start() */
            timeSec = count / freq.lo;
            timeUsec = count / (freq.lo / 1000000);
    
            System_printf("Timestamp[%d]: Sec %d\tuSec %d\n", i, timeSec, timeUsec);
            System_flush();
    
            i++;
            Task_sleep(1000);
        }
    }

    This can be used as a good starting point. One idea is to configure the timer to be periodic and increment a volatile counter in a timer callback. That way, your could always have uSecs, Secs, Hours, Days.....etc.

    Derrick

  • Hello Derrick,

    Thank your giving detailed response. Honestly speaking, at this time, I don't have time to try out your solution but will keep that in mind. Very sorry for that. However I got the message that we can't change timestamp provider source frequency. 

    Once again thank you for taking time to respond to my query.

    Regards

    Abhijit