i.MX6ULL终结者Linux RTC驱动实验Linux内核RTC驱动简介

在Linux内核中,RTC设备驱动也是一个标准的字符设备驱动,在应用程序中通过open、close、read、write和ioctl等函数来操作RTC设备。
在Linux内核中,RTC设备也有一个自己的设备结构体rtc_device,所以在RTC设备驱动的流程就是rtc_device结构体的申请、初始化,然后将rtc_device结构体注册到内核中。可以看出大多数设备都是这样一个流程,只不过对用的设备结构体和函数不同罢了。
rtc_device 结构体定义在 include/linux/rtc.h 文件中,内容如下:

104 struct rtc_device 
105 {
    
106        struct device dev; /* 设备 */ 
107        struct module *owner; 
108 
109        int id; /* ID */ 
110        char name[RTC_DEVICE_NAME_SIZE]; /* 名字 */ 
111 
112      const struct rtc_class_ops *ops; /* RTC 设备底层操作函数 */ 
113        struct mutex ops_lock; 
114 
115        struct cdev char_dev; /* 字符设备 */ 
116      unsigned long flags; 
117 
118        unsigned long irq_data; 
119        spinlock_t irq_lock; 
120        wait_queue_head_t irq_queue; 
121        struct fasync_struct *async_queue; 
122 
123        struct rtc_task *irq_task; 
124        spinlock_t irq_task_lock; 
125        int irq_freq; 
126        int max_user_freq; 
127 
128        struct timerqueue_head timerqueue; 
129        struct rtc_timer aie_timer; 
130        struct rtc_timer uie_rtctimer; 
131        struct hrtimer pie_timer; /* sub second exp, so needs hrtimer */ 
132        int pie_enabled; 
133        struct work_struct irqwork; 
134        /* Some hardware can't support UIE mode */ 
135        int uie_unsupported; 
......
147 };

rtc_device 结构体中虽然有很多成员变量,但是大多数都不用我们操心,我们需要重点关心的是ops成员变量,这是一个rtc_class_ops类型的指针变量。rtc_class_ops结构体是RTC设备最底层的操作函数的集合,包括读取、写入时间等功能。因此rtc_class_ops结构体中实现的功能函数在不同的RTC设备中有所不同,rtc_class_ops此结构体定义在include/linux/rtc.h 文件中,内容如下:

71 struct rtc_class_ops {
    
72         int (*open)(struct device *); 
73       void (*release)(struct device *); 
74   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值