RTC in DLPS Mode
This sample code guide is designed to help users easily and comprehensively understand RTC sample. This sample demonstrates RTC works in DLPS mode.
Requirements
For hardware requirements, please refer to the Requirements.
Configurations
The following macros can be configured to modify the RTC prescaler value.
#define RTC_PRESCALER_VALUE 4095
The following macros can be configured to modify the RTC comparator channel.
#define RTC_COMP_INDEX COMP0_INDEX
#define RTC_COMP_INT_INDEX RTC_INT_CMP0
#define RTC_COMP_WK_INDEX RTC_CMP0_WK_INT
The entry function is as follows, call this function in
main()
to run this sample code. For more details, please refer to the Initialization.rtc_in_dlps_mode();
Building and Downloading
For building and downloading, please refer to the Building and Downloading.
Experimental Verification
Press the Reset button on the EVB, the system is in idle state and will enter DLPS mode.
After 10 seconds, the system will be woken up and prints the following log in Debug Analyzer.
app_dlps_exit_callback rtc_handler: RTC_INT_CMP0
Code Overview
This section introduces the code and process description for initialization and corresponding function implementation in the sample.
Source Code Directory
For project directory, please refer to Source Code Directory.
Source code directory:
sdk\src\sample\io_demo\rtc\dlps\rtc_in_dlps_mode.c
.
RTC Initialization
The initialization flow for peripherals can refer to Initialization Flow.
Call
RTC_DeInit()
to reset the RTC peripheral.Call
RTC_SetPrescaler()
to set the RTC prescaler.Call
NVIC_Init()
to enable NVIC of RTC.Call
RTC_RunCmd()
to enable the RTC.
DLPS Mode Initialization
Call
bt_power_mode_set()
to set Bluetooth MAC deep sleep mode.Call
io_dlps_register()
to initialize IO store/restore and do not need to worry about which IO peripheral requires specific handling.Call
io_dlps_register_enter_cb()
to register callbacks to DLPS enter stage. Functionapp_dlps_enter_callback
will be executed while entering from DLPS:Call
RTC_CompINTConfig()
to enable the RTC comparator channel 0 interrupt_RTC_INT::RTC_INT_CMP0
and wake up interrupt_RTC_INT::RTC_CMP0_WK_INT
.Call
RTC_MaskINTConfig()
to unmask the RTC comparator channel 0 interrupt_RTC_INT::RTC_INT_CMP0
and wake up interrupt_RTC_INT::RTC_CMP0_WK_INT
.Call
RTC_SystemWakeupConfig()
to enable the RTC system wakeup function.Call
RTC_GetCounter()
to get counter value of RTC.Call
RTC_SetComp()
to set the RTC comparator channel 0 value.
Call
io_dlps_register_exit_cb()
to register callbacks to DLPS exit stage. Functionapp_dlps_exit_callback
will be executed while exiting from DLPS:Print the following log.
app_dlps_exit_callback
Call
power_mode_set()
to switch the system to DLPS mode.
Functional Implementation
Interrupt Handle
When the comparator setting time (10s) is reached, it triggers an RTC interrupt:
Call
RTC_GetINTStatus()
to check interrupt status flag.Call
RTC_ClearCompINT()
to clear the RTC comparator channel 0 interrupt.Call
RTC_ClearCompWkINT()
to clear wake up interrupt of the comparator channel 0 of RTC.