Fork me on GitHub

一 RTC
 
  RTC的英文全称是Real-Time Clock,翻译过来是实时时钟芯片。绝大多数mcu芯片都集成了这个功能。在可穿戴产品中,时间往往是非常重要的因素,怎么让时间保持一直在运行,那就是rtc时钟的功劳了。怎么让rtc超低功耗的运行,这个是其中的难点。
 
二 源码解析
 
-AMA3B2KK-KBR的rtc时钟初始化由三个函数组成,如下所示:函数注释比较简答明了,这里不做赘述了。
    //
    // Enable the XT for the RTC.
    //
    am_hal_clkgen_control(AM_HAL_CLKGEN_CONTROL_XTAL_START, 0);

    //
    // Select XT for RTC clock source
    //
    am_hal_rtc_osc_select(AM_HAL_RTC_OSC_XT);

    //
    // Enable the RTC.
    //
    am_hal_rtc_osc_enable();

 

 
接下来看一下该rtc是怎么获取时间的,从源码中来看,是直接从编译环境的pc机上获取的,假如你把刚编译好的bin文件load进去,这个rtc就会按照这个时间往下走。
    //
    // The RTC is initialized from the date and time strings that are
    // obtained from the compiler at compile time.
    //
    hal_time.ui32Hour = toVal(&__TIME__[0]);
    hal_time.ui32Minute = toVal(&__TIME__[3]);
    hal_time.ui32Second = toVal(&__TIME__[6]);
    hal_time.ui32Hundredths = 00;
    hal_time.ui32Weekday = am_util_time_computeDayofWeek(2000 + toVal(&__DATE__[9]), mthToIndex(&__DATE__[0]) + 1, toVal(&__DATE__[4]) );
    hal_time.ui32DayOfMonth = toVal(&__DATE__[4]);
    hal_time.ui32Month = mthToIndex(&__DATE__[0]);
    hal_time.ui32Year = toVal(&__DATE__[9]);
    hal_time.ui32Century = 0;

 

 
三 效果展示
 
  下面看一下笔者的rtc时钟的日志信息,每间隔1s读取rtc时钟一次,可以看出来,时间走的还挺准的。
 
四 总结
 
  至此,rtc时钟的功能完善了,再加上显示,一个手表就这样诞生了。
posted on 2022-04-02 11:42  虚生  阅读(412)  评论(0编辑  收藏  举报