4.5.19. RTC Test
4.5.19.1. Test Principle
RTC (Real-Time Clock) keeps time after system power-off, powered by a coin cell battery through the PMIC VRTC pin. It records year/month/day/hour/minute/second and synchronizes hardware time to the Linux system clock at boot.
Time Synchronization Principle:
During power-off: The RTC is powered independently by PMIC VRTC, continuously maintaining the hardware time (year, month, day, hour, minute, second), independent of the main system power state.
At system boot: The kernel RTC driver reads the RTC hardware registers and writes the hardware time as the initial value to the Linux system clock (CLOCK_REALTIME), completing the initial RTC → system clock synchronization.
Alarm workflow:
Software sets the alarm via
/sys/class/rtc/rtc0/wakealarm(relative time such as+10, or an absolute epoch value)When the alarm expires, the PMIC sets ALARM_F internally and sends an interrupt to the CPU through the ALARM_N pin
The kernel driver clears wakealarm after handling the interrupt; userspace can verify the IRQ count change in
/proc/interrupts
4.5.19.2. Preparation
Driver Verification
Ensure the HPU3501 RTC driver is loaded and the following messages appear in the kernel log:
# dmesg | grep rtc
[ 0.589787] hpu3501 2-001c: Found hpu3501-rtc node, register rtc
[ 0.593254] hpu3501-rtc hpu3501-rtc.1.auto: registered as rtc0
[ 0.594082] hpu3501-rtc hpu3501-rtc.1.auto: setting system clock to 2026-06-10T11:34:32 UTC (1749555272)
Verify that the device node exists:
# ls /dev/rtc0
/dev/rtc0
Script Path
The test script is located on the board at:
/app/platform_samples/chip_base_test/15_rtc_test/rtc_test.sh
Script Usage
rtc_test.sh supports the -h option to display help information:
# ./rtc_test.sh --help
usage: ./rtc_test.sh <command>
commands:
info show RTC hardware information
read read hardware RTC time
setsys <datetime> set system time
example: ./rtc_test.sh setsys "2025-06-09 14:30:00"
setrtc <datetime> set RTC time (system time also updated)
example: ./rtc_test.sh setrtc "2025-06-09 14:30:00"
alarm [-s seconds] set RTC alarm and verify by interrupt count
default: 10s
examples:
./rtc_test.sh info
./rtc_test.sh read
./rtc_test.sh setsys "2025-06-09 14:30:00"
./rtc_test.sh setrtc "2025-06-09 14:30:00"
./rtc_test.sh alarm -s 10
Parameter description:
| Command | Description |
|---|---|
info |
Show RTC hardware information (device node, driver, current time, alarm IRQ, etc.) |
read |
Read hardware RTC time |
setsys <datetime> |
Set system time only (date -s), e.g. "2025-06-09 14:30:00" |
setrtc <datetime> |
Set RTC time (date -s + hwclock -w; system time is updated as well) |
alarm [-s seconds] |
Set RTC alarm and verify by IRQ count; default 10 seconds |
-h / --help |
Show help |
4.5.19.3. Test Steps
View RTC Information
# ./rtc_test.sh info
========================================
RTC Hardware Info
========================================
Device node : /dev/rtc0 # RTC device node
Sysfs path : /sys/class/rtc/rtc0 # sysfs interface path
Name : hpu3501-rtc hpu3501-rtc.1.auto # device name
Date : 2025-06-09 # RTC date (sysfs)
Time : 14:30:00 # RTC time (sysfs)
Since epoch : 1749479400 sec # seconds since Unix epoch
Wakealarm : # alarm setting; empty if unset
Driver : hpu3501-rtc # kernel driver name
Hwclock : Mon Jun 9 14:30:00 2025 0.000000 seconds # hardware RTC time via hwclock
System date : Mon Jun 9 14:30:00 UTC 2025 # current system time
Alarm IRQ : 46: 0 0 0 0 0 0 0 0 gpio-dwapb 1 Edge hpu3501_alarm_irq # alarm IRQ line and count
========================================
Read RTC Time
# ./rtc_test.sh read
Hardware RTC: Mon Jun 9 14:30:05 2025 0.000000 seconds
Set System Time
Changes the system clock only; hardware RTC is not affected:
# ./rtc_test.sh setsys "2025-06-09 14:30:00"
Set datetime : 2025-06-09 14:30:00
System time : Mon Jun 9 14:30:00 UTC 2025
PASS: system time set
Set RTC Time
Updates both system time and hardware RTC (retained after power-off):
# ./rtc_test.sh setrtc "2025-06-09 14:30:00"
Set datetime : 2025-06-09 14:30:00
Hardware RTC : Mon Jun 9 14:30:00 2025 0.000000 seconds
System time : Mon Jun 9 14:30:00 UTC 2025
PASS: RTC time set
RTC Alarm Test
Set a relative alarm with -s 10 and verify that the interrupt count increases:
# ./rtc_test.sh alarm -s 10
========================================
RTC Alarm Test
========================================
Alarm delay : 10s
IRQ line : 46: 0 0 0 0 0 0 0 0 gpio-dwapb 1 Edge hpu3501_alarm_irq
IRQ before : 0
Set at : 2025-06-09 14:29:50
Waiting for alarm (delay 10s, max wait 15s) ...
countdown: 1s left | IRQ +1
Trigger at : 2025-06-09 14:30:00
Latency : 10.052s (set -> trigger)
Error : +0.052s
IRQ after : 1
========================================
PASS: RTC alarm interrupt detected (+1), latency 10.052s
Output field description:
| Field | Description |
|---|---|
| Alarm delay | Relative alarm interval in seconds (-s) |
| Waiting for alarm | delay: expected time until alarm fires; max wait: script timeout (delay + 5s margin) |
| IRQ line | RTC alarm interrupt line in /proc/interrupts |
| IRQ before / after | IRQ count before and after the test; after > before means the alarm IRQ fired |
| Set at | Time when the alarm was set (system time) |
| Trigger at | Time when the alarm fired (system time) |
| Latency | Actual time from set to trigger (seconds, millisecond precision) |
| Error | Latency error = Latency − Alarm delay |
| countdown | Seconds remaining until Alarm delay elapses (tracks delay, not max wait) |
4.5.19.4. Test Criteria
| Test Item | Command | Pass Criteria |
|---|---|---|
| Device detection | info |
/dev/rtc0 exists, driver probe succeeds, IRQ line visible |
| Read time | read |
Returns valid RTC time |
| Set system time | setsys |
System time matches the set value |
| Set RTC time | setrtc |
RTC and system time match the set value (±2 s settling delay allowed) |
| Alarm | alarm |
IRQ count +1, wakealarm cleared, Latency ≈ Alarm delay (Error recommended ≤ ±1 s) |
Pass rule: All mandatory items (info / read / setsys / setrtc / alarm) must PASS for the RTC function test to pass.