For details about RTC programming in the Linux operating system kernel, refer to general Linux technology-Linux programming and kernel information. Programming RTC in Linux Kernel
The MC146818 RTC chip (or other compatible chip, such as DS12887) can generate periodic interruptions on IRQ8, with the Interruption Frequency ranging from 2Hz ~ Between 8192HZ. The device driver corresponding to MC146818 RTC is implemented in include/linux/rtc. h and drivers/char/rtc. in the c file, the corresponding device file is/dev/rtc (major = 10, minor = 135, read-only character device ). Therefore, the user process can program her to activate the IRQ8 line when RTC reaches a specific time value, so that RTC can be used as an alarm clock.
The only purpose of the Linux kernel for RTC is to use RTC as the "offline" or "background" time and date maintainer. When the Linux kernel is started, it reads the benchmark values of time and date from RTC. Then, during the running period, the kernel will completely discard RTC, so as to maintain the current time and date of the system in the form of software, and write the time back to the RTC chip as needed.
Linux in include/linux/mc146818rtc. h and include/asm-i386/mc146818rtc. the h header file defines the meaning of each register of the mc146818 RTC chip and the I/O port operations of the RTC chip on the i386 platform. The general RTC interface is declared in the include/linux/rtc. h header file.
7.2.1 I/O port operation of the RTC Chip
Linux defines the I/O port operation of the RTC chip in the include/asm-i386/mc146818rtc. h header file. Port 0x70 is called "RTC port 0" and port 0x71 is called "RTC Port 1", as shown below: