RTC 也就是实时时钟,用于记录当前系统时间,对于 Linux 系统而言时间是非常重要的, 就和我们使用 Windows 电脑或手机查看时间一样,我们在使用 Linux 设备的时候也需要查看时 间。
一、Linux 内核 RTC 驱动简介
- RTC 设备驱动是标准的字符设备驱动,应用程序通过 open、release、read、write 和 ioctl 等函数完成对 RTC 设备的操作。
- Linux 内核将 RTC 设备抽象为 rtc_device 结构体,RTC 设备驱动申请并初始化 rtc_device,将 rtc_device 注册到内核。
- RTC 设备的操作肯定是用一个操作集合(结构体)来表示的,rtc_device 结构体,此结构体定义在 include/linux/rtc.h 文件中。
- drivers/rtc/rtc-dev.c 是Linux 内核提供的 RTC 通用字符设备驱动文件,此结构体定义在 include/linux/rtc.h 文件中。
struct rtc_device
{
struct device dev; /* 设备 */
struct module *owner;
int id; /* ID */
char name[RTC_DEVICE_NAME_SIZE]; /* 名字 */
const struct rtc_class_ops *ops; /* RTC 设备底层操作函数 */
struct mutex ops_lock;
struct cdev char_dev; /* 字符设备 */
unsigned long flags;
unsigned long irq_data;
spinlock_t irq_lock;
wait_queue_head_t irq_queue;