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

  1. The following macros can be configured to modify the RTC prescaler value.

    • #define RTC_PRESCALER_VALUE         4095

  2. 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

  3. 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

  1. Press the Reset button on the EVB, the system is in idle state and will enter DLPS mode.

  2. 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.

  1. Call RTC_DeInit() to reset the RTC peripheral.

  2. Call RTC_SetPrescaler() to set the RTC prescaler.

  3. Call NVIC_Init() to enable NVIC of RTC.

  4. Call RTC_RunCmd() to enable the RTC.

DLPS Mode Initialization

  1. Call bt_power_mode_set() to set Bluetooth MAC deep sleep mode.

  2. Call io_dlps_register() to initialize IO store/restore and do not need to worry about which IO peripheral requires specific handling.

  3. Call io_dlps_register_enter_cb() to register callbacks to DLPS enter stage. Function app_dlps_enter_callback will be executed while entering from DLPS:

    1. 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.

    2. 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.

    3. Call RTC_SystemWakeupConfig() to enable the RTC system wakeup function.

    4. Call RTC_GetCounter() to get counter value of RTC.

    5. Call RTC_SetComp() to set the RTC comparator channel 0 value.

  4. Call io_dlps_register_exit_cb() to register callbacks to DLPS exit stage. Function app_dlps_exit_callback will be executed while exiting from DLPS:

    1. Print the following log.

      app_dlps_exit_callback
      
  5. 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:

  1. Call RTC_GetINTStatus() to check interrupt status flag.

  2. Call RTC_ClearCompINT() to clear the RTC comparator channel 0 interrupt.

  3. Call RTC_ClearCompWkINT() to clear wake up interrupt of the comparator channel 0 of RTC.