AML_看门狗驱动分析
2016-04-18 14:37
375 查看
看门狗的工作原理是,定时器中断,设定的时间递减完了,如果此时没有重新启动定时器开始计数,也就是所谓的“喂狗”,模块就会拉低引脚,让平台重启复位
看linux driver从module_init函数开始
module_init(aml_wdt_driver_init);
里面注册了一个平台设备驱动
模块在上电匹配设备层也就是dtd的compatible后,运行probe回调函数
这样timer会每隔一段时间去喂狗,如果系统繁忙或者其他原因造成系统卡顿没有喂狗,那系统就会被看门狗拉低重启
看linux driver从module_init函数开始
module_init(aml_wdt_driver_init);
里面注册了一个平台设备驱动
static struct platform_driver aml_wdt_driver = { .probe = aml_wdt_probe, .remove = aml_wdt_remove, .shutdown = aml_wdt_shutdown, .suspend = aml_wdt_suspend, .resume = aml_wdt_resume, .driver = { .owner = THIS_MODULE, .name = "aml_wdt", .of_match_table = aml_wdt_of_match, }, }
模块在上电匹配设备层也就是dtd的compatible后,运行probe回调函数
static int aml_wdt_probe(struct platform_device *pdev) { struct watchdog_device *aml_wdt; /*watchdog的核心结构体*/ struct aml_wdt_dev *wdev;/*pri data*/ int ret; aml_wdt = devm_kzalloc(&pdev->dev, sizeof(*aml_wdt), GFP_KERNEL);/*alloc space*/ if (!aml_wdt) return -ENOMEM; wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL); if (!wdev) return -ENOMEM; wdev->dev = &pdev->dev; mutex_init(&wdev->lock); /*init mutex lock*/ aml_init_pdata(wdev); /*init platform data*/ aml_wdt->info = &aml_wdt_info; aml_wdt->ops = &aml_wdt_ops;/*ops is important*/ aml_wdt->min_timeout = wdev->min_timeout; aml_wdt->max_timeout = wdev->max_timeout; aml_wdt->timeout = 0xffffffff; wdev->timeout = 0xffffffff; watchdog_set_drvdata(aml_wdt, wdev); platform_set_drvdata(pdev, aml_wdt);/*save 平台数据*/ if (wdev->reset_watchdog_method == 1) { INIT_DELAYED_WORK(&wdev->boot_queue, boot_moniter_work); mod_delayed_work(system_freezable_wq, &wdev->boot_queue, round_jiffies(msecs_to_jiffies(wdev->reset_watchdog_time*1000))); enable_watchdog(wdev);/*启动定时器用到喂狗*/ set_watchdog_cnt(wdev, wdev->default_timeout * wdev->one_second);/*设置喂狗时间间隔*/ dev_info(wdev->dev, "creat work queue for watch dog\n"); } ret = watchdog_register_device(aml_wdt);/*注册接口*/ if (ret) return ret; awdtv = wdev; register_pm_notifier(&aml_wdt_pm_notifier); register_reboot_notifier(&aml_wdt_reboot_notifier); dev_info(wdev->dev, "AML Watchdog Timer probed done\n"); return 0; }
这样timer会每隔一段时间去喂狗,如果系统繁忙或者其他原因造成系统卡顿没有喂狗,那系统就会被看门狗拉低重启
static void boot_moniter_work(struct work_struct *work) { struct aml_wdt_dev *wdev = container_of(work, struct aml_wdt_dev, boot_queue.work); reset_watchdog(wdev); /*喂狗*/ mod_delayed_work(system_freezable_wq, &wdev->boot_queue, round_jiffies(msecs_to_jiffies(wdev->reset_watchdog_time*1000)));/*延时*/ }
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程
- Linux 下无损图片压缩小工具介绍