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.
1. Use of RTC
Taking SC-3568HA as an example, this 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

2. 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 /sys/class/rtc/rtc0/date
2024-10-21
# cat /sys/class/rtc/rtc0/time
09:48:46
Tips
In case of the "Invalid argument" returned by the cat command, you need to enter the system settings first and set the time.
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:
You can use ioctl to control /dev/rtc0
3. Commonly used commands for clocks
date //修改系统时钟,具体命令使用可以man下
hwclock -s //将硬件时间同步到系统时间
hwclock -w //将系统时间同步到硬件时间
date "2023-08-14 08:00:00" //手动设置时间
hwclock -w //系统时间同步到硬件rtc
hwclock -s //硬件rtc同步到系统
#以上手动设置时间或者网络同步时间后,-w将系统时间写入到硬件rtc,-s再将rtc时间写回系统,这样每次重启板卡都会进行rtc时间同步到系统时间。