RTC
RTC stands for Real Time Clock. It is a hardware device specially used to record time. It can usually be integrated into the soc, or selected as an external plug-in to communicate with it through i2c.
So why do we need RTC? Because the Linux system time (also known as wall time) can only be used when the system is running. The time is lost when the system is shut down. RTC can continue to work after the system is shut down, relying on an external battery or other supply, thus saving the time.
Use of RTC
The development board uses an external RTC (hym8563), and the RTC function of rk809 is turned off by default.
When using an external RTC, a button battery is required

RTC user interface call
Linux provides three user space calling interfaces. The corresponding paths in the board are:
SYSFS interface: /sys/class/rtc/rtc0/
PROCFS interface: /proc/driver/rtc
IOCTL interface: /dev/rtc0
SYSFS Interface
cat proc/driver/rtc
rtc_time : 02:01:53
rtc_date : 2025-02-21
alrm_time : 00:00:00
alrm_date : 1970-01-01
alarm_IRQ : no
alrm_pending : no
update IRQ enabled : no
periodic IRQ enabled : no
periodic IRQ frequency : 1
max user IRQ frequency : 64
24hr : yes
PROCFS Interface
cat /proc/driver/rtc
rtc_time : 09:50:05
rtc_date : 2024-10-21
alrm_time : 00:00:00
alrm_date : 1970-01-01
alarm_IRQ : no
alrm_pending : no
update IRQ enabled : no
periodic IRQ enabled : no
periodic IRQ frequency : 1
max user IRQ frequency : 64
24hr : yes
IOCTL Interface
See the kernel documentation for an example: kernel/tools/testing/selftests/timers/rtcpie.c
Commonly used commands
date //修改系统时钟,具体命令使用可以man下
hwclock -s //将硬件时间同步到系统时间
hwclock -w //将系统时间同步到硬件时间
timedatectl //显示系统时间等
#以下手动设置时间或者网络同步时间后,-w将系统时间写入到硬件rtc,-s再将rtc时间写回系统,这样每次重启板卡都会进行rtc时间同步到系统时间。
sudo date -s "2025-02-14 08:00:00" //手动设置时间
sudo hwclock -w //系统时间同步到硬件rtc
sudo hwclock -s //硬件rtc同步到系统