女人自慰AV免费观看内涵网,日韩国产剧情在线观看网址,神马电影网特片网,最新一级电影欧美,在线观看亚洲欧美日韩,黄色视频在线播放免费观看,ABO涨奶期羡澄,第一导航fulione,美女主播操b

0
  • 聊天消息
  • 系統消息
  • 評論與回復
登錄后你可以
  • 下載海量資料
  • 學習在線課程
  • 觀看技術視頻
  • 寫文章/發帖/加入社區
會員中心
創作中心

完善資料讓更多小伙伴認識你,還能領取20積分哦,立即完善>

3天內不再提示

Linux驅動分析之RTC框架

jf_78858299 ? 來源:嵌入式軟件開發交流 ? 作者:young ? 2023-05-26 15:12 ? 次閱讀

前言

圖片

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 class
static 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也是字符設備驅動,只是進行了封裝,封裝完之后我們調用起來其實就很簡單了。只要實現好接口函數,填充好結構體,然后進行注冊即可。

聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。 舉報投訴
  • Linux
    +關注

    關注

    87

    文章

    11456

    瀏覽量

    212756
  • RTC
    RTC
    +關注

    關注

    2

    文章

    607

    瀏覽量

    68281
  • 驅動開發
    +關注

    關注

    0

    文章

    133

    瀏覽量

    12250
收藏 人收藏

    評論

    相關推薦
    熱點推薦

    Linux RTC開發指南

    介紹Linux 內核中RTC 驅動的適配和DEBUG 方法,為RTC 設備的使用者和維護者提供參考。
    的頭像 發表于 03-06 10:22 ?1599次閱讀
    <b class='flag-5'>Linux</b> <b class='flag-5'>RTC</b>開發指南

    Linux平臺設備框架驅動

    ? 平臺設備框架(platform)是將一個驅動分為設備層和驅動層兩個部分,通過總線模型將設備和驅動進行綁定。在系統中每注冊一個設備,都會與
    的頭像 發表于 09-25 08:59 ?2177次閱讀
    <b class='flag-5'>Linux</b>平臺設備<b class='flag-5'>框架</b><b class='flag-5'>驅動</b>

    LinuxPWM驅動

    本文主要講述了Linux的PWM驅動框架、實現方法、驅動添加方法和調試方法。
    發表于 05-25 09:19 ?836次閱讀
    <b class='flag-5'>Linux</b><b class='flag-5'>之</b>PWM<b class='flag-5'>驅動</b>

    linux驅動框架是什么

    編寫linux驅動先看一下驅動框架是什么樣子的。驅動編寫和應用層編寫有什么區別呢?
    發表于 07-26 08:14

    RTC芯片的驅動框架是由哪些部分組成的

    如何對RTC芯片進行調試呢?RTC芯片的驅動框架是由哪些部分組成的?
    發表于 03-04 07:35

    Linux下基于I2C協議的RTC驅動開發

    首先研究了Linux環境下字符設備驅動程序框架,然后介紹12C協議,在此基礎上開發基于12C協議的RTC字符設備驅動程序。砷于
    發表于 03-02 16:15 ?48次下載
    <b class='flag-5'>Linux</b>下基于I2C協議的<b class='flag-5'>RTC</b><b class='flag-5'>驅動</b>開發

    想要駕馭Linux驅動開發,必須深刻理解Linux總線設備驅動框架

    想要駕馭Linux驅動開發,必須深刻理解Linux總線設備驅動框架。之所以會形成這樣的框架,主要
    的頭像 發表于 03-22 11:08 ?1.1w次閱讀
    想要駕馭<b class='flag-5'>Linux</b><b class='flag-5'>驅動</b>開發,必須深刻理解<b class='flag-5'>Linux</b>總線設備<b class='flag-5'>驅動</b><b class='flag-5'>框架</b>

    Linux RTC驅動模型分析rtc-sysfs.c

    rtc-sysfs文件主要的操作就是在sys下創建rtc的屬性節點,可以方便用戶方便快捷的訪問,查找問題。下來大概看看sys下的rtc節點,有個直觀的認識。
    發表于 04-27 19:43 ?2604次閱讀

    你了解linux RTC 驅動模型?

    RTC(real time clock)實時時鐘,主要作用是給Linux系統提供時間。RTC因為是電池供電的,所以掉電后時間不丟失。Linux內核把
    發表于 04-26 15:50 ?2048次閱讀
    你了解<b class='flag-5'>linux</b> <b class='flag-5'>RTC</b> <b class='flag-5'>驅動</b>模型?

    你對Linux總線設備驅動框架是否了解

    Linux的設備驅動模型,或者說,Linux的設備驅動框架,都是同一個意思。應該這樣理解,(Linux
    發表于 05-05 15:13 ?849次閱讀

    如何使用Linux內核實現USB驅動程序框架

    Linux內核提供了完整的USB驅動程序框架。USB總線采用樹形結構,在一條總線上只能有唯一的主機設備。 Linux內核從主機和設備兩個角度觀察USB總線結構。本節介紹
    發表于 11-06 17:59 ?20次下載
    如何使用<b class='flag-5'>Linux</b>內核實現USB<b class='flag-5'>驅動</b>程序<b class='flag-5'>框架</b>

    看看Linux為相機提供的驅動框架

    ? V4L2 (Video Linux Two),是為支持Linux內核設計的驅動框架驅動框架
    的頭像 發表于 08-07 16:03 ?3702次閱讀
    看看<b class='flag-5'>Linux</b>為相機提供的<b class='flag-5'>驅動</b><b class='flag-5'>框架</b>

    淺析Linux RTC實時時鐘

    內核將 RTC 設備抽象為 rtc_device 結構體,RTC設備驅動就是申請并初始化rtc_device,最后將
    的頭像 發表于 11-25 15:07 ?1789次閱讀

    Linux的PWM驅動框架及實現方法

    本文主要講述了Linux的PWM驅動框架、實現方法、驅動添加方法和調試方法。
    的頭像 發表于 05-14 15:24 ?1788次閱讀
    <b class='flag-5'>Linux</b>的PWM<b class='flag-5'>驅動</b><b class='flag-5'>框架</b>及實現方法

    Linux Regmap 驅動框架

    1、regmap 框架結構 regmap 驅動框架如下圖所示: regmap 框架分為三層: ①、底層物理總線:regmap 就是對不同的物理總線進行封裝,目前 regmap 支持的物
    的頭像 發表于 07-06 17:29 ?1360次閱讀
    <b class='flag-5'>Linux</b> Regmap <b class='flag-5'>驅動</b><b class='flag-5'>框架</b>