首页 > 系统相关 >linux驱动编写(看门狗)

linux驱动编写(看门狗)

时间:2022-11-23 23:32:32浏览次数:38  
标签:s3c2410 linux watchdog s3c2410wdt 看门狗 wdt S3C2410 WATCHDOG 编写




    看门狗是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、找到设备注册函数、函数结构基本就算结束了,当然有中断的话,也可以确认一下

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、有兴趣的话,可以找一个函数阅读一下。比如下面这个重启函数,可以和spec对比者来看

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;
}


标签:s3c2410,linux,watchdog,s3c2410wdt,看门狗,wdt,S3C2410,WATCHDOG,编写
From: https://blog.51cto.com/feixiaoxing/5881992

相关文章

  • linux驱动编写(dma驱动)
      linux下面的驱动虽然什么样的情形都有,但是dma驱动却并不少见。dma可以有很多的好处,其中最重要的功能就是能够帮助我们将数据搬来搬去,这个时候cpu就由时间去做别的事情......
  • linux驱动编写(电源管理驱动)
      对于嵌入式设备来说,合适的电源管理,不仅可以延长电池的寿命,而且可以省电,延长设备运行时间,在提高用户体验方面有很大的好处。所以,各个soc厂家在这方面花了很多的功夫。......
  • linux驱动编写(摄像头驱动)
       对于现代嵌入式设备,特别是手机来说,摄像头是很重要的一个设备。很多同学买手机,一看颜值,第二就看摄像头拍照如何。所以,从某个角度来说,摄像头是各个厂家主打的应用功能......
  • linux驱动编写(nand flash驱动)
      很长一段时间,nandflash都是嵌入式的标配产品。nandflash价格便宜,存储量大,适用于很多的场景。现在很普及的ssd,上面的存储模块其实也是由一块一块nandflash构成的。......
  • 实体类编写时需要注意的细节——为什么字段需要用包装类型而不用基本数据类型
    最近在学习做微服务的项目,总结了一些平常没有注意到的细节,记录于此实体类涉及到的属性如果是int这样的基本数据类型,那么要使用其包装类型,因为包装类型默认为null,而基本......
  • 在Ubuntu Linux上安装Deb文件的三种方法
    https://zhuanlan.zhihu.com/p/339632982?ivk_sa=1024320u方法一:在.deb文件夹下(应该是Downloads文件夹),双击.deb文件方法二:使用Gdebi应用程序来安装deb软件包及其依赖项......
  • 简述linux系统中软件包管理系统
    前几篇文章一一介绍了LINUX进程管理控制命令,详细介绍了静态查看ps命令和动态查看top命令,以及中断、停止命令在实际管理控制过程中的一些实践操作等这篇文章主要简单介绍下......
  • Testbench 的编写与应用
    1.Testbench的概念Testbench是一种用任意语言编写的程序或模块,用于在模拟过程中执行和验证硬件模型的功能正确性。Verilog主要用于硬件建模(模拟),该语言包含各种资源,用于......
  • linux命令风格与mysql启动
    Linux三种风格(Unix、BSD、GNU)下的ps的参数说明mysqld_safe是什么使用mysqld_safe启动mysql服务,mysqld_safe为mysqld的守护进程,在BSD风格的unix系统上,常用mysqld_safe脚......
  • Linux 性能分析命令 -top
     linux文件结构/boot核相关文件/bin存放系统中可用的命令/etc系统管理所需要的所有配置文件 /usrunixsharedresource用户共享程序文件夹/opt......