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.

CC1312R: How to use RTC channel 1 and 2 with TI-RTOS7?

Part Number: CC1312R
Other Parts Discussed in Thread: SYSBIOS, SYSCONFIG

Hi,

I have a project still under development base on ''old" TI-RTOS (not 7) that uses hooks provided by RTOS to work with RTC CH1 and CH2 hardware. 

The below snippets show an example of using Channel 1, with Driverlib API calls to configure an RTC event at 4 seconds after boot.
First, in the application .cfg file a hook function is defined for Channel 1:
    var Timer = xdc.module('ti.sysbios.family.arm.cc26xx.Timer');
    Timer.funcHookCH1 = "&myHookCH1";
In main(), Channel 1 is first cleared, a compare (match) value of 4 seconds is set, the channel is enabled:
    AONRTCEventClear(AON_RTC_CH1);
    AONRTCCompareValueSet(AON_RTC_CH1, 0x40000);
    AONRTCChannelEnable(AON_RTC_CH1);
With the above, myHookCH1() will be called when the RTC reaches a count of 4 seconds. At that time, a new compare value can be written for the next interrupt that should occur for Channel 1.

There is a plan to migrate at later stage of the project to the new TI-RTOS7, so please provide me some information how could RTC CH1 and CH2 be used with new TI-RTOS7?  

Regards,

Dimitar Devedzhiev

  • Hi Dimitar,

    In TI-RTOS7 I suggest you use the tiposix layer to access the RTC. In particular you should use the ClockP module to set timers and manage delays. 

    Below an example on how to set up a 1 second periodic callback using ClockP, but you can tweak the parameters to set it up as a one-shot as well.

    This is just a modified version of the empty example to toggle the RED led using ClockP instead of sleep().

    /*
     * Copyright (c) 2015-2019, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /*
     *  ======== empty.c ========
     */
    
    /* For usleep() */
    #include <unistd.h>
    #include <stdint.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    // #include <ti/drivers/I2C.h>
    // #include <ti/drivers/SPI.h>
    // #include <ti/drivers/Watchdog.h>
    
    /* Driver configuration */
    #include "ti_drivers_config.h"
    
    #include <ti/drivers/dpl/ClockP.h>
    
    
    void clkCallback(uintptr_t arg0){
    
        GPIO_toggle(CONFIG_GPIO_LED_0);
    }
    
    
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        /* 1000 second delay */
        uint32_t time = 1000;
    
        ClockP_Struct clkStruct;
        ClockP_Params clkParams;
        ClockP_Handle clkHandle = NULL;
    
        ClockP_Params_init(&clkParams);
    
        clkParams.period = 100000; // 100k RTC ticks (10us each) = 1s
        clkParams.startFlag = true; // start clock immediately after instance is created
    
        clkHandle = ClockP_construct(&clkStruct, clkCallback, 0, &clkParams);
    
        /* Call driver init functions */
        GPIO_init();
        // I2C_init();
        // SPI_init();
        // Watchdog_init();
    
        /* Configure the LED pin */
        GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        /* Turn on user LED */
        GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
    
        while (1)
        {
            sleep(time);
        }
    }
    

    You can find additional documentation on the tiposix calls in <SDK directory>/source/ti/drivers/dpl/ClockP.h

    Regards,

    Fausto

  • Hi Fausto,

    I am not asking how to use Clock object, I am asking about direct use of RTC channel 1 and chanel 2 with TI_RTOS7.

    I am using RTC CH1 capture to capture RTC time on external events and CH2 auto compare load capabilities to generate time periods which time will not drifts as a result on HWI or SWI enter latency (there could be jitter, but not drift).    

    Previous version of TI-RTOS provide this with hooks functions within module ti.sysbios.family.arm.cc26xx.Timer.

    So my question is how RTC CH1 and CH2 hardware could be used with new TI-RTOS7, not the clock object ?  

    Regards,

    Dimitar

  • Hi DImitar,

    I apologize then, I had misunderstood your question.

    You can find the hooks for RTC channel 1 and Channel 2 inside the sysconfig interface as below:

    Actually if you took the snippet in your original post from the file "SDK_dir\kernel\tirtos7\packages\ti\sysbios\family\arm\cc26xx\Timer.h", that documentation is imprecise and will be updated in the next SDK 6.30, soon to be released, to the following:

     * The below snippets show an example of using Channel 1, with Driverlib API
     * calls to configure an RTC event at 4 seconds after boot.
     *
     * With Syscfg open, the hook function for Channel 1 can be set to a user-defined
     * function under:
     * Clock->Other Dependencies->Clock Support->Other Dependencies->RTC Timer->
     * RTC Channel 1 function hook
     *
     * In main(), Channel 1 is first cleared, a compare (match) value of 4 seconds
     * is set, the channel is enabled:
     *
     * @code
     *    AONRTCEventClear(AON_RTC_CH1);
     *    AONRTCCompareValueSet(AON_RTC_CH1, 0x40000);
     *    AONRTCChannelEnable(AON_RTC_CH1);
     * @endcode

    Hope this helps.

    Regards,

    Fausto