X86平台的看门狗驱动,在内核中开线程喂狗

1、X86平台的看门狗驱动:

相关文件为:drivers/watchdog/iTCO_wdt.c

相关配置选项为:

 Device Drivers  --->

    [*] Watchdog Timer Support  --->

        [*] Intel TCO Timer/Watchdog

在intel的CPU中,只要内核中选择该选项,看门狗变可以使用了

 

2、如何在内核中开一个线程,启动看门狗

/* 启动看门狗,设置超时时间 */
static void wdt_thread_handler(void)
{
	int timeoutVal = 30;
	
	iTCO_wdt_start();

	if (iTCO_wdt_set_heartbeat(timeoutVal))
			return -EINVAL;

	/* 每10秒喂狗一次 */
	while(1)
	{
		iTCO_wdt_keepalive();
		msleep(10);
	}
}


/* 在内核开启线程 */
static void wdt_thread_create(void)
{
	struct task_struct *task;

	task = kthread_create(wdt_thread_handler, NULL,	"wdt_thread_handler");

	if (IS_ERR(task))
		return PTR_ERR(task);
}

static int __init iTCO_wdt_init_module(void)
{

	......
	
	/* 在一个合适的地方调用该创建线程的函数 */
	wdt_thread_create();

	return 0;
}

你可能感兴趣的:(X86平台的看门狗驱动,在内核中开线程喂狗)