RTCs and user space
On Linux systems, there are two kernel options that you need to consider in order to properly manage RTCs from the user space. These are CONFIG_RTC_HCTOSYS
and CONFIG_RTC_HCTOSYS_DEVICE
.
CONFIG_RTC_HCTOSYS
includes the drivers/rtc/hctosys.c
code file in the kernel build process, which sets the system time from the RTC on startup and resume. Once this option is enabled, the system time will be set by using the value read from the specified RTC device. RTC devices should be specified inCONFIG_RTC_HCTOSYS_DEVICE
:
CONFIG_RTC_HCTOSYS=y CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
In the preceding example, we tell the kernel to set the system time from the RTC, and we specify that the RTC to use is rtc0
.
The sysfs interface
The kernel code responsible for instantiating RTC attributes in sysfs
is defined in drivers/rtc/rtc-sysfs.c
, in the kernel source tree. Once registered, an RTC device will create a rtc<id>
directory under /sys/class/rtc
. That directory contains a set of read-only...