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.

CC1352R: Using ClockP_start(Handle)

Part Number: CC1352R

Hi,

the device is CC1352R.

There is implemented periodic clock instance shown below:

/* Construct a periodic Clock Instance */
ClockP_construct(&clk0Struct, (ClockP_Fxn)SWTick, period, &clkParams);

clk2Handle = ClockP_handle(&clk0Struct);
ClockP_start(clk2Handle);

This instance make a tick periods at, which some volatile counters changed his values.

For changing counters values in runtime the application use - ClockP_start(clk2Handle); and ClockP_stop(clk2Handle); to implement critical section.

HwiP_disable(); do not stop this tick.

When this critical section is used I see that there is error in the time base ~1.6second. Is it possible when do ClockP_stop/ClockP_start, the RTC to add error i n the time base?

Best regards,

Ilian

  • Hi Ilian,

    It's a bit hard to understand what's going on. 

    1) What version of the SimpleLink CC13x2/CC26x2 SDK are you using?

    2) Can you show the code snippet for ClockP_start(clk2Handle); and ClockP_stop(clk2Handle);, where are these called?

    3) Does the device enter standby between the clock stat and stop?

    4) How long are you measuring? 

    5) Can you rephrase the question: "Is it possible when do ClockP_stop/ClockP_start, the RTC to add error i n the time base?"

    Cheers,

    Marie H.

  • Hi,

    1. simplelink_cc13x2_26x2_sdk_4_10_00_78

    2. Example of implementing critical section.

    ClockP_stop(clk2Handle);

    counter_a = value_a;

    counter_b= value_b;

    ClockP_start(clk2Handle);

    // .....

    // Periodic clock instance created before.. Tick.

    void SWTick(uintptr_t arg0)

    {

      // .....

      counter_a--;

      counter_b--;

    }

    The tick is with period 250ms.

    On every 60sec. I see 1.6sec additional.

    3. No device do not enter in standby mode between ClockP_stop and ClockP_start.

    Best regards,

    Ilian

  • Could you provide a minimum example that show this? 

  • Basically yes. You mean working example?

  • Yes please.

  • It will be difficult. The idea is make critical section on this software tick - is this implementation is correct?

  • Hi TER,

    there is a delay from usage of a ClockP_stop and ClockP_start. and the delay is ~ 7.5ms on every 250ms.

    I did this critical section every 250ms and for 60sec the additional delay (error) is ~1.6 - 1.8 sec.

    This only for information. This delay is may connected with driver which start/stop this instance or with manner of driver work with the RTC.

    I will implemented workaround, but it will be good of we can understand reason for this.

    In general is this implementation is correct and is it possible have some issue with dynamically start/stop clock instanc?

    Best regards,

    Ilian

  • What I'm not sure about here is if you are seeing a delta due to inaccurate clock or the critical section. 

    The critical section first:

    When are you doing 

    ClockP_stop(clk2Handle);

    counter_a = value_a;

    counter_b= value_b;

    ClockP_start(clk2Handle);

    in the code? 

    Is this required since counter_a and counter_b are updated in the clock callback, or is this to prevent that counter_a is updated and then you get the call back (worst case)

    Running ClockP_stop()/ ClockP_start() has an execution time but as far as I can see from the code these only set the object active or inactive and read the current timer value:

    nowTick = TimerP_getCurrentTick(ClockP_module.timer, true);

  • Hi TER,

    I use this type of implementation of a critical section, to prevent changing the counter value in the callback (and take a  decision) during the time, when the counter value is changed/reload.

    Best regards,

    Ilian

  • Hi Ilian,

    Sorry for the delay.

    Did you find a solution?

    Cheers,

    Marie H.

  • Hi Marie,

    No for now.

    There is a delay and may be this is not from code execution of the ClockP_stop and ClockP_start.

    Best regards,

    Ilian

  • Hi Ilian,

    I’d like to help but I think that I need more information from you.

    1. Which RTOS are you using? I ask this because the clock module is implementation-dependent.

    2. Which clkParams are you using in ClockP_construct()? Are you using the default ones?

    I think you might have confused the period parameter with the timeout parameter. In ClockP_construct() the user can pass a startup timeout. This parameter only has an effect if the RTOS supports it, and it’s different from the period, which is actually defined in the clkParams struct.

    My guess is that you are actually using the Clock in one-shoot mode and not in periodic mode. The reason the code still works (albeit with some issues) is that even though the clock is in one-shoot mode and stops after the given timeout, your code keeps restarting it with ClockP_start(). This is probably leading to the issues you are seeing.

    Another thing that I’d like to understand is the intended purpose of your code. What’s the intention behind updating the values of counter_a and counter_b inside the clock callback SWTick(), and then updating them again? I’d like to understand to see if there is a more suitable way of implementing this.

    Regards,
    AndresM

  • Hi Andres,

    1. I do not use RTOS. NoRTOS driver is used.

    2. Attached here is the main_nortos.c file, you can see how clock instance is done.

    /*
     *  ======== main_nortos.c ========
     */
    #include <main_nortos.h>
    
    #include <stdint.h>
    #include <stddef.h>
    
    #include <NoRTOS.h>
    
    #include <ti/drivers/Power.h>
    #include <ti/drivers/power/PowerCC26XX.h>
    #include <ti/drivers/dpl/ClockP.h>
    
    /* Example/Board Header files */
    #include <ti/drivers/Board.h>
    
    #include <ManDown.h>
    
    uint32_t Clock_tickPeriod = 10;
    ClockP_Struct   clk0Struct, clk1Struct;
    ClockP_Handle clk2Handle;
    
    void *mainThread(void *arg0);
    
    /*
     *  ======== main ========
     */
    int main(void)
    {
        //NoRTOS_Config cfg;
    
    
        /* Call driver init functions */
        //Board_init();
        Board_Initialization();
    
        // Set config. parameters for NoRTOS.
        //NoRTOS_getConfig(&cfg);
        //cfg.idleCallback = Power_idleFunc;
        //cfg.clockTickPeriod = 250000;      // 250ms tick period.
        //cfg.clockTickPeriod = 1000000;       // 1s tick period.
        //NoRTOS_setConfig(&cfg);
    
        /* Start NoRTOS */
        NoRTOS_start();
    
        ClockP_Params clkParams;
        ClockP_Params_init(&clkParams);
    
        uint32_t period = 250000/Clock_tickPeriod;
        //uint32_t period = 0;
        clkParams.period = period;
        //clkParams.period = 0;
        clkParams.startFlag = true;
    
        /* Construct a periodic Clock Instance */
        ClockP_construct(&clk0Struct, (ClockP_Fxn)SWTick, period, &clkParams);
    
        clk2Handle = ClockP_handle(&clk0Struct);
        ClockP_start(clk2Handle);
    
    
        /* Call mainThread function */
        mainThread(NULL);
    
        while (1) {}
    
    }
    
    

    In this case SWTick is executed every 250ms.

    In this callback some counters, which are used from the main application are changed (incremented/decremented).

    When the application need to re-load some of the counter, it is needed this tick (decremented/incremented)  to be stopped and the counters to be updated correctly. (some kind of critical section)

    Best regards,

    Ilian

  • Hi Ilian,

    Thank you for the additional info and the code snippet.

    From what you share here, I think that there might be several reasons for what you are describing.

    1. You are passing a timeout value in ClockP_construct() that seems unnecessary. My suggestion would be:

    ClockP_construct(&clk0Struct, (ClockP_Fxn)SWTick, 0, &clkParams);

    Do not confuse the startup timeout with the period. The period is defined in the clkParams struct. Even though the value you are using for the timeout is the same as the one for the period, you are basically adding an additional wait period each time you stop and start the clock.

    2. You don’t specify what the clock callback is actually doing (besides modifying a couple of variables), so this might be more of a general advice, but keep the callback short, and don’t place any blocking calls inside.

    3. From your code I can’t tell how often the application needs to reload the counters (stopping and starting the clock), but the more you start and stop the clock, the more you are bound to have some timing problems. So if this happens a lot, it might be worth considering a different design approach.

    Kind regards,
    AndresM  

  • Hi Andres,

    Thank you for your answer and sorry for my delay!

    I changed the ClockP_construct, according to your advice. It work. I will try, to find were there is delay now.

    Best regards,

    Ilian