RTC
Sample List
This chapter introduces the details of the RTC sample code. The SDK provides the following samples for the RTC peripheral.
Functional Overview
RTC is an independent timer. RTC has a set of continuous counting counters to provide a calendar clock. It can be converted into the current time and date of the system by querying the counter value.
Feature List
32KHz clock source.
12-bits pre-scale counter.
24-bit read-only RTC counter (RTL87x3E and RTL87x3EP), 32-bit read-only RTC counter (RTL87x3D).
Incremental counter.
Support comparator interrupt.
Support overflow interrupt, indicating that the counter overflows and wraps around to 0.
Support tick interrupt.
Support wake-up system from DLPS/power down mode.
4 independent comparators (COMP0-3). + RTC_CMP0-3_NV — interrupt the CPU. + RTC_CMP0-3_WK — can wake up the system from DLPS/power down mode.
4 independent comparators (COMP0-3GT). + RTC_CMP0-3GT — can wake up the system from DLPS/power down mode.
Block Diagram
Here is the overall IPs block diagram for RTC IP¹, which including ‘PAD/PINMUX’ for IO function configuration, ‘RTC IP’ for RTC protocol.

System Block Diagram of RTC
Clock and Prescale
The schematic diagram of the RTC clock is shown in the figure.

RTC Clock
RTC contains two counters: a pre-scaler counter and the RTC counter.
The 32kHz clock source is converted to RTC_CLK after pre-scaling, for use by the RTC counter.
The pre-scaler value can be set by calling RTC_SetPrescaler()
.
When the RTC is running, the pre-scaler counter begins counting. Each time it counts to the set pre-scaler value, the RTC counter increments by 1. Every time the RTC counter increases by 1, a tick interrupt is triggered.
Comparator and Interrupt
RTC supports 8 independent comparators, 4 comparators (COMP0-3GT) can only be used to trigger wake-up, 4 comparators (COMP0-3) can be used to trigger wake-up and CPU NVIC.
The comparator’s comparison value can be set using RTC_SetComp()
. When the RTC counter value reaches the comparison value, it will trigger the RTC interrupt for the corresponding channel.
Power Manager
The RTC peripheral is located in the AON domain, it will be powered off in ship mode.
All comparison channels and interrupts of the RTC support DLPS/power down mode wake-up function.
Among them, COMP0-3GT can only be used for DLPS/power down mode wake-up and not for CPU interrupts, while other channels support both DLPS/power down mode wake-up and CPU interrupt functions simultaneously.
Call RTC_SystemWakeupConfig()
function to set RTC wake-up functionality.