前言
当linux内核启动时,它会从rtc中读取时间与日期,作为基准值。然后通过软件来维护系统时间和日期。linux系统中提供了rtc核心层,对于驱动开发者而言,操作起来就变得很简单了。我们来看看整体框架。
驱动框架
下面是整体框架图 :
与rtc核心有关的文件有:
文件描述
/drivers/rtc/class.c 这个文件向linux设备模型核心注册了一个类rtc,然后向驱动程序提供了注册/注销接口
/drivers/rtc/rtc-dev.c 这个文件定义了基本的设备文件操作函数,如:open,read等
/drivers/rtc/interface.c 这个文件主要提供了用户程序与rtc驱动的接口函数,用户程序一般通过ioctl与rtc驱动交互,这里定义了每个ioctl命令需要调用的函数
/drivers/rtc/rtc-sysfs.c 与sysfs有关
/drivers/rtc/rtc-proc.c 与proc文件系统有关
/include/linux/rtc.h 定义了与rtc有关的数据结构
重要结构体
rtc_device//rtc设备struct rtc_device { struct device dev; struct module *owner; int id; 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; struct fasync_struct *async_queue; int irq_freq; int max_user_freq; struct timerqueue_head timerqueue; struct rtc_timer aie_timer; struct rtc_timer uie_rtctimer; struct hrtimer pie_timer; /* sub second exp, so needs hrtimer */ int pie_enabled; struct work_struct irqwork; /* some hardware can't support uie mode */ int uie_unsupported; long set_offset_nsec; bool registered; struct nvmem_device *nvmem; /* old abi support */ bool nvram_old_abi; struct bin_attribute *nvram; time64_t range_min; timeu64_t range_max; time64_t start_secs; time64_t offset_secs; bool set_start_time;#ifdef config_rtc_intf_dev_uie_emul struct work_struct uie_task; struct timer_list uie_timer; /* those fields are protected by rtc->irq_lock */ unsigned int oldsecs; unsigned int uie_irq_active:1; unsigned int stop_uie_polling:1; unsigned int uie_task_active:1; unsigned int uie_timer_active:1;#endif};上面的结构体表示一个rtc设备,比较简单,主要就是中断信息,字符设备对象,操作函数等。
rtc_class_ops//rtc操作函数struct rtc_class_ops { int (*ioctl)(struct device *, unsigned int, unsigned long); int (*read_time)(struct device *, struct rtc_time *); int (*set_time)(struct device *, struct rtc_time *); int (*read_alarm)(struct device *, struct rtc_wkalrm *); int (*set_alarm)(struct device *, struct rtc_wkalrm *); int (*proc)(struct device *, struct seq_file *); int (*set_mmss64)(struct device *, time64_t secs); int (*set_mmss)(struct device *, unsigned long secs); int (*read_callback)(struct device *, int data); int (*alarm_irq_enable)(struct device *, unsigned int enabled); int (*read_offset)(struct device *, long *offset); int (*set_offset)(struct device *, long offset);};就是一些设置时间和读取时间,以及闹钟等接口函数。
rtc_time//时间结构体struct rtc_time { int tm_sec; int tm_min; int tm_hour; int tm_mday; int tm_mon; int tm_year; int tm_wday; int tm_yday; int tm_isdst;};api函数
// 注册rtc classstatic struct rtc_device *rtc_device_register(const char *name, struct device *dev, const struct rtc_class_ops *ops, struct module *owner)struct rtc_device *devm_rtc_device_register(struct device *dev, const char *name, const struct rtc_class_ops *ops, struct module *owner)//注销rtc static void rtc_device_unregister(struct rtc_device *rtc) void devm_rtc_device_unregister(struct device *dev, struct rtc_device *rtc)总结
rtc也是字符设备驱动,只是进行了封装,封装完之后我们调用起来其实就很简单了。只要实现好接口函数,填充好结构体,然后进行注册即可。
浅谈通往自动驾驶路上那些雷达技术
最新芯片龙头股排名前十
是何原因造成芯片产业烂尾潮?
中国移动李晗表示在推动超100G标准及验证测试上需要从多方面来解决
FPGA+x86可以将时延的精度控制在2.5ns数量级别
Linux驱动分析之RTC框架
OPPO全渠道服务24小时在线 获度知道2019年用户口碑奖
浅谈大功率电压型逆变器新型组合式IGBT过流保护方案
语音芯片怎么录音 以及如何选择合适的录音芯片
车用锂电池全球研发热点
Vyond现已推出突破性的人工智能脚本和视频创建器
如何进一步激发5G发展新动能,从这三方面出发
小米MIX2发布时间正式确认,小米Note3也要来?
数据挖掘技术在交通事故分析中设计
使用单片机设计红外遥控器的资料说明
为鼓励AR游戏开发者,Niantic将提供100万美元奖励
红外线报警器工作原理
量子计算机:未来的计算革命
传特斯拉明年11月生产ModelY_与Model3同一平台
Molex推出最新互连技术MediSpec产品系列