本篇文章主要介绍了详解linux 看门狗驱动编写,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧 看门狗是linux驱动的一个重要环节。某些特殊的设备,有时候需要放在一些环境恶劣的地方,比如电信设备。但是,任何软件都不可能100%没有bug。如何保证软件在遇到严重bug、死机的时候也能正常运行呢,那么看门狗就是有效的一种方法。看门狗一般要求用户定时喂狗,如果一段时间没有喂狗的话,那么系统就会自动重启。今天,我们就来看看这个看门狗驱动怎么编写? 1、代码目录 drivers/watchdog2、阅读目录下的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_wdt3、S3C2410_WATCHDOG主要依赖WATCHDOG_CORE,VPS云主机可以继续跟踪Makefile obj-$(CONFIG_S3C2410_WATCHDOG) += s3c2410_wdt.o4、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、找到设备注册函数、函数结构基本就算结束了
|