国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統 > Linux > 正文

詳解linux 看門狗驅動編寫

2024-08-28 00:01:04
字體:
來源:轉載
供稿:網友
本篇文章主要介紹了詳解linux 看門狗驅動編寫,小編覺得挺不錯的,現在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

看門狗是linux驅動的一個重要環節。某些特殊的設備,有時候需要放在一些環境惡劣的地方,比如電信設備。但是,任何軟件都不可能100%沒有bug。如何保證軟件在遇到嚴重bug、死機的時候也能正常運行呢,那么看門狗就是有效的一種方法。看門狗一般要求用戶定時喂狗,如果一段時間沒有喂狗的話,那么系統就會自動重啟。今天,我們就來看看這個看門狗驅動怎么編寫?

1、代碼目錄

drivers/watchdog 

2、閱讀目錄下的Kconfig,可以找一個s3c模塊macro

config HAVE_S3C2410_WATCHDOG   bool   help    This will include watchdog timer support for Samsung SoCs. If    you want to include watchdog support for any machine, kindly    select this in the respective mach-XXXX/Kconfig file.  config S3C2410_WATCHDOG   tristate "S3C2410 Watchdog"   depends on HAVE_S3C2410_WATCHDOG || COMPILE_TEST   select WATCHDOG_CORE   select MFD_SYSCON if ARCH_EXYNOS   help    Watchdog timer block in the Samsung SoCs. This will reboot    the system when the timer expires with the watchdog enabled.     The driver is limited by the speed of the system's PCLK    signal, so with reasonably fast systems (PCLK around 50-66MHz)    then watchdog intervals of over approximately 20seconds are    unavailable.     The driver can be built as a module by choosing M, and will    be called s3c2410_wdt 

3、S3C2410_WATCHDOG主要依賴WATCHDOG_CORE,可以繼續跟蹤Makefile

obj-$(CONFIG_S3C2410_WATCHDOG) += s3c2410_wdt.o 

4、macro只依賴一個s3c2410_wdt.c文件,繼續查看

static SIMPLE_DEV_PM_OPS(s3c2410wdt_pm_ops, s3c2410wdt_suspend,       s3c2410wdt_resume);  static struct platform_driver s3c2410wdt_driver = {   .probe   = s3c2410wdt_probe,   .remove   = s3c2410wdt_remove,   .shutdown  = s3c2410wdt_shutdown,   .id_table  = s3c2410_wdt_ids,   .driver   = {     .name  = "s3c2410-wdt",     .pm = &s3c2410wdt_pm_ops,     .of_match_table = of_match_ptr(s3c2410_wdt_match),   }, };  module_platform_driver(s3c2410wdt_driver); 

5、確認driver為platform類型,繼續在probe函數中查找有用的code

ret = watchdog_register_device(&wdt->wdt_device); if (ret) {   dev_err(dev, "cannot register watchdog (%d)/n", ret);   goto err_cpufreq; } 

6、網上繼續查找,尋找到和watchdog有關的數據結構

static const struct watchdog_info s3c2410_wdt_ident = {   .options     =   OPTIONS,   .firmware_version = 0,   .identity     = "S3C2410 Watchdog", };  static const struct watchdog_ops s3c2410wdt_ops = {   .owner = THIS_MODULE,   .start = s3c2410wdt_start,   .stop = s3c2410wdt_stop,   .ping = s3c2410wdt_keepalive,   .set_timeout = s3c2410wdt_set_heartbeat,   .restart = s3c2410wdt_restart, };  static const struct watchdog_device s3c2410_wdd = {   .info = &s3c2410_wdt_ident,   .ops = &s3c2410wdt_ops,   .timeout = S3C2410_WATCHDOG_DEFAULT_TIME, }; 

7、找到設備注冊函數、函數結構基本就算結束了,當然有中斷的話,也可以確認一下

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 保定市| 宜川县| 宿州市| 十堰市| 宁远县| 泽库县| 凌源市| 翼城县| 金川县| 门头沟区| 霍林郭勒市| 墨竹工卡县| 泰和县| 翁牛特旗| 洪雅县| 浦江县| 庆元县| 阿鲁科尔沁旗| 常熟市| 富蕴县| 正阳县| 繁峙县| 南平市| 拉萨市| 娱乐| 黄浦区| 宜昌市| 黄梅县| 罗平县| 工布江达县| 花莲市| 甘孜| 潍坊市| 无锡市| 墨玉县| 莆田市| 九龙县| 隆林| 邢台县| 巍山| 江孜县|