Tick
该示例通过使用 RTC 外设实现TICK功能。
每经过TICK定时就会进入触发RTC中断,并打印相关log信息。
环境需求
该示例支持以下开发套件:
Hardware Platforms |
Board Name |
---|---|
RTL87x2G HDK |
RTL87x2G EVB |
更多信息请参考快速入门。
编译和下载
该示例的工程路径如下:
Project file: samples\peripheral\rtc\tick\proj\rtl87x2g\mdk
Project file: samples\peripheral\rtc\tick\proj\rtl87x2g\gcc
请按照以下步骤操作构建并运行该示例:
打开工程文件。
按照 快速入门 中 编译APP Image 给出的步骤构建目标文件。
编译成功后,在路径
mdk\bin
或gcc\bin
下会生成 app binapp_MP_xxx.bin
文件。按下复位按键,开始运行。
测试验证
设定时间到后,触发RTC中断,打印中断信息。
RTC_Handler: RTC_INT_TICK
代码介绍
该章节分为以下几个部分:
源码路径
工程路径:
sdk\samples\peripheral\rtc\tick\proj
源码路径:
sdk\samples\peripheral\rtc\tick\src
该工程的工程文件代码结构如下:
└── Project: tick
└── secure_only_app
└── Device includes startup code
├── startup_rtl.c
└── system_rtl.c
├── CMSIS includes CMSIS header files
├── CMSE Library Non-secure callable lib
├── Lib includes all binary symbol files that user application is built on
└── rtl87x2g_io.lib
├── Peripheral includes all peripheral drivers and module code used by the application
├── rtl_rcc.c
├── rtl_pinmux.c
├── rtl_nvic.c
└── rtl_rtc.c
└── APP includes the ble_peripheral user application implementation
├── main_ns.c
└── io_rtc.c
初始化
初始化流程包括了 driver_rtc_init
。
driver_rtc_init
包含了对RTC外设的初始化。
复位RTC外设。
设置RTC的分频系数为(3200-1),RTC时钟频率为10Hz(32K/3200)。
使能RTC滴答中断
RTC_INT_TICK
。复位RTC计数值。
启动RTC外设。
RTC_DeInit();
RTC_SetPrescaler(RTC_PRESCALER_VALUE);
RTC_INTConfig(RTC_INT_TICK, ENABLE);
...
RTC_NvCmd(ENABLE);
RTC_ResetCounter();
RTC_Cmd(ENABLE);
功能实现
TICK设定时间到,触发RTC中断,进入中断处理函数
RTC_Handler
。判断RTC滴答中断
RTC_INT_TICK
状态是否为SET。打印信息,清除滴答中断。
if (RTC_GetINTStatus(RTC_INT_TICK) == SET)
{
/* Notes: DBG_DIRECT function is only used for debugging demonstrations, not for application projects.*/
DBG_DIRECT("RTC_Handler: RTC_INT_TICK");
// Add application code here
RTC_ClearTickINT();
}