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.

Setting clock tick period from main()

Other Parts Discussed in Thread: SYSBIOS

Hi all,

I want to ask about clock module configuration. How I can reconfigure clock module in main() with new tick period value ? We are using SYSBIOS and OMAP-L137 device.

Regards Grzegorz

  • Hi Grzegorz,

    The Clock.tickPeriod is a config param and cannot be changed at runtime. It has to be changed at build time through the application's *.cfg script.

    If you would like to change the tick period at runtime, an alternative is to change the clock tick source to USER and create your own timer to provide the clock tick (Clock module cdoc has an example showing how to change the tick source to USER). This way you own the timer and can change the timer period effectively changing the clock tickPeriod.

    Best,

    Ashish

  • Thanks Ashish, we will try to create solution with custom clock trigger as you proposed.

  • Hi Ashish,

    I suppose you're referring to this example:

     var Clock = xdc.useModule('ti.sysbios.knl.Clock');
    
      // Tell the Clock module that YOU are providing the periodic interrupt
      Clock.tickSource = Clock.TickSource_USER;
    
      // this example uses the ti.sysbios.timers.dmtimer.Timer module
      var Timer = xdc.useModule('ti.sysbios.timers.dmtimer.Timer');
    
      // create a dmtimer config parameter object
      var timerParams = new Timer.Params();
    
      // make sure you set the period to 1000 us (1ms)
      timerParams.period = 1000;
    
      // custom dmtimer config parameters here...
      timerParams.twer.ovf_wup_ena = 1;
    
      // Create the timer.
      // This example uses timer id 3.
      // The timer interrupt handler must be set to 'Clock.tick'. 
      Timer.create(3, Clock.tick, timerParams);
    If I understand correctly, the above code goes into the .cfg file.
    I still have a few questions:
    1) Can I use any name for the clock, or does it have to be "var Clock" like the example shows?
    2) Does this affect the default clock settings for the whole module? For example, if I am using an RDK with existing code that uses BIOS clocks, will the code be affected by the above change?
    3) Can you show an example of how can I can use this custom clock in my C code?
    Thanks,
    Eli
  • Hi Eli,

    Regarding your #3 question, I use following C code:

        Timer_Params user_sys_tick_params;
        Timer_Handle user_sys_tick_timer;

        /* Create timer for user system tick */
        Timer_Params_init(&user_sys_tick_params);
        user_sys_tick_params.period = 1000;
        user_sys_tick_params.periodType = Timer_PeriodType_MICROSECS;
        user_sys_tick_params.arg = 1;
        user_sys_tick_timer = Timer_create(1,
                (ti_sysbios_hal_Timer_FuncPtr)Clock_tick, &user_sys_tick_params, NULL);

        if(user_sys_tick_timer == NULL)
        {
            System_abort("Unable to create user system tick timer!");
        }

    Regards Grzegorz