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.

How to use RTC on cc3200

Other Parts Discussed in Thread: CC3200

Hi,

I need my cc3200 app to do things at certain times of the day. Is there a RTC I can use? or a sample app that shows this?  or what's the best way to do this?

Thanks, Tom

  • It depends on the interval you require, if you do not require scheduling down to the second, then the best way to achieve this would be to use an SNTP server to obtain the time on a periodic basis. There is actually an example of how to do most of this with the CC3200 SDK, check out the get_time example.

    If you require scheduling down to the second, you could use the SNTP server to update the clock on a regular basis and then use one of the clock sources (xtal or internal oscillator) to work out how much time has past since the last update. Using a SNTP server is a better option then trying to keep things accurate through using a clock source alone, so long as you are connected to the Internet, as it means you do not need a battery or other such option to deal with reboots, power lose etc.

    Glenn.

  • Glenn,

    Thanks, I wasn't sure if there was an easier way of doing this. I currently pull the time over the web and sync my local time keeper to it...So that should work fine.

    Thanks, Tom

  • Tom,

    Once you have pulled the time over the web you can also consider using the SlowClockCounter as the resource for local timekeeping.

    This can be done by invoking the PRCMRTC* APIs in prcm.h. These are the low level APIs.

    We also have a high level software timer interface - cc3200-sdk\middleware\framework\timer and cc3200-sdk\middleware\driver\hal\rtc_hal.c -. h that you could also consider using. This can work in conjunction with the power management framework. You may refer to the section "Working with time of day (real time)" in the document cc3200-sdk\docs\CC3200-Power_Management_Framework.pdf .

    Best regards,

    Naveen

  • Naveen,

    I am trying to use the code example in Power Mana Framework doc, and cant seem to find the correct data type for:

    /* Setup the RTC initial value obtained from NTP */
    init_time.secs = NTP_TIME_SECS;
    init_time.nsec = NTP_TIME_NSECS;
    cc_rtc_set(&init_time);

    the cc_rtc_set() takes a u64_time var, but the compile gives an error that u64_time is undefined. I have include all .h files.

    Thanks, Tom

  • Naveen,

    I was able to get the rtc code to compile, but now it returns -1 on the cc_timer_create function at the line where hwt->ops == NULL. Where do I set the ops and how? There seems to be some init functions missing in the RTC solution mentioned in the Power Management Framework docs

    hwt = get_hwt(cfg->source);

    if((NULL == hwt) || (NULL == hwt->ops))
    goto cc_timer_create_exit1;

    My code is below:

    	u64_time init_time, interval_time;
    	hw_timer_cfg hw_timer;
    	cc_timer_cfg realtime_timer;
    	cc_hndl timer_hndl;
    	
          		  hw_timer.cb.timeout_cb = &timer_intr_hndlr;
          		  hw_timer.cb_param = NULL;
          		  hw_timer.source = HW_REALTIME_CLK;
          		  hw_timer.user_tfw = 0;
          		  hw_timer.set_irq = &timer_isr_hndlr;
          		  res = cc_rtc_init(&hw_timer);
    
    	      	  /* Setup the RTC initial value obtained from NTP */
    	      	  init_time.secs = 14561000;//NTP_TIME_SECS;
    	      	  init_time.nsec = 3283770;//NTP_TIME_NSECS;
    	      	  cc_rtc_set(&init_time);
    	      	  /* Create a real time timer */
    	      	  realtime_timer.source = HW_REALTIME_CLK;
    	      	  realtime_timer.timeout_cb = &timer_intr_hndlr;
    	      	  realtime_timer.cb_param = NULL;
    	      	  timer_hndl = cc_timer_create(&realtime_timer);
    	      	  /* Configure the timer for a periodic wakeup */
    	      	  interval_time.secs = 30;//WAKEUP_SEC_TIMEOFDAY;
    	      	  interval_time.nsec = 0;//WAKEUP_NSEC_TIMEOFDAY;
    	      	  res = cc_timer_start(timer_hndl, &interval_time, OPT_TIMER_PERIODIC);
    

    Thanks, Tom

  • Hi Tom,

    Yes the Power management framework doc gives only a high level overview and does not cover all the timer APIs in detail. The two reference implementations as described in the doc (idle_profile and sensor_profile) are the best sources for the implementation details.

    Please find the necessary init routines in the file cc3200-sdk\example\idle_profile\lp3p0_board.c.

    The lines of code of interest will be the following (The subfunctions invoked are also a part of the file). Please include them as well.

    -----------------------------------------------------------------------------------

    /* Register the power management ISR : This is also required to capture SlowClockCounter interrupts*/

    register_isr(INT_PRCM, prcm_interrupt_handler, NULL);

    /* Initialize the platform specific services */

    timer_setup.enbl_irqc = osi_ExitCritical;

    timer_setup.dsbl_irqc = osi_EnterCritical;

    retval = cc_timer_module_init(&timer_setup);

    /* Initialize RTC services */

    retval = rtc_module_init();

    -------------------------------------------------------------------------------

    Best regards,

    Naveen

  • I have a very similar issue: I need two periodic timers, one 32 seconds and the other 50ms

    cc_hndl SetTimer()
    {
        cc_hndl tTimerHndl;
        struct cc_timer_cfg sHighResTimer;
        struct u64_time  sIntervalTimer;
    
        sHighResTimer.source = HW_REALTIME_CLK;
        sHighResTimer.timeout_cb = TimerCallback;
        sHighResTimer.cb_param = NULL;
    
        tTimerHndl = cc_timer_create(&sHighResTimer);
    
        sIntervalTimer.secs = 32;
        sIntervalTimer.nsec = 0;
        cc_timer_start(tTimerHndl, &sIntervalTimer, OPT_TIMER_PERIODIC);
        return(tTimerHndl);
    }
    
    
    
    cc_hndl SetTimer2()
    {
        cc_hndl tTimerHndl;
        struct cc_timer_cfg sHighResTimer;
        struct u64_time  sIntervalTimer;
    
        sHighResTimer.source = HW_REALTIME_CLK;
        sHighResTimer.timeout_cb = Timer2Callback;
        sHighResTimer.cb_param = NULL;
    
        tTimerHndl = cc_timer_create(&sHighResTimer);
    
        sIntervalTimer.secs = 0;
        sIntervalTimer.nsec = 50000000;
        cc_timer_start(tTimerHndl, &sIntervalTimer, OPT_TIMER_PERIODIC);
        return(tTimerHndl);
    }

    These two timers cannot work together.  why this happens?

    I tried to change the timer2's clock source to HW_MONOTONE_CTR.  

     sHighResTimer.source = HW_MONOTONE_CTR;

    Then these two timers work together for a while. after I did some changes on other modules and recompiled multiple times, this approach cannot work anymore.  the timer2's call back is never called.  It's because timer2's clock is not enabled? but which physical timer is used for my timer2? Thanks.

  • what actually makes the rtc start ticking?