本文主要是介绍AML_看门狗驱动分析,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
看门狗的工作原理是,定时器中断,设定的时间递减完了,如果此时没有重新启动定时器开始计数,也就是所谓的“喂狗”,模块就会拉低引脚,让平台重启复位
看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)));/*延时*/
}
这篇关于AML_看门狗驱动分析的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!