Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of programming watchdog driver in linux

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you about the example analysis of the watchdog driver written in linux, I believe most people don't know much about it, so share this article for your reference. I hope you can learn a lot after reading this article. Let's learn about it together.

Watchdog is an important part of linux driver. Some special equipment, sometimes need to be placed in some harsh environment, such as telecommunications equipment. However, no software can be 100% without bug. How to ensure that the software can run normally in the event of a serious bug or crash? then watchdog is an effective method. Watchdogs generally require users to feed the dog regularly, and if the dog is not fed for a period of time, the system will restart automatically.

1. Code directory

Drivers/watchdog

2. By reading the Kconfig in the directory, you can find a S3C module 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 mainly depends on WATCHDOG_CORE, so you can continue to track Makefile.

Obj-$ (CONFIG_S3C2410_WATCHDOG) + = s3c2410_wdt.o

4. Macro relies on only one s3c2410_wdt.c file and continues to view

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. Confirm that driver is of type platform, and continue to find useful code in the probe function.

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

6. Continue to search the Internet and find the data structure related to 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. Find the device registration function, and even if the function structure is basically over, of course, if there is an interrupt, you can confirm it.

Ret = devm_request_irq (dev, wdt_irq- > start, s3c2410wdt_irq, 0, pdev- > name, pdev); if (ret! = 0) {dev_err (dev, "failed to install irq (% d)\ n", ret); goto err_cpufreq;}

8. If you are interested, you can find a function to read it. For example, the following restart function can be viewed with the spec comparator

Static int s3c2410wdt_restart (struct watchdog_device * wdd, unsigned long action, void * data) {struct s3c2410_wdt * wdt = watchdog_get_drvdata (wdd); void _ _ iomem * wdt_base = wdt- > reg_base; / * disable watchdog, to be safe * / writel (0, wdt_base + S3C2410_WTCON); / * put initial values into count and data * / writel (0x80, wdt_base + S3C2410_WTCNT); writel (0x80, wdt_base + S3C2410_WTDAT) / * set the watchdog to go and reset... * / writel (S3C2410_WTCON_ENABLE | S3C2410_WTCON_DIV16 | S3C2410_WTCON_RSTEN | S3C2410_WTCON_PRESCALE (0x20), wdt_base + S3C2410_WTCON); / * wait for reset to assert... * / mdelay (500); return 0;} these are all the contents of the article "Writing a watchdog-driven sample analysis in linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report