mini6410 实现 看门狗移植
mini6410 实现 看门狗移植
写在移植前的:看门狗在嵌入式系统开发中占据重要的地位,管理系统的工作状态。在这里本人muge0913在参考别人的基础上,实现了mini6410看门狗的移植。
在mini6410中看门狗驱动文件为linux2.6.38/drivers/watchdog/s3c2410_wdt.c
在mini6410中linux系统默认看门狗是不开机启动,但是我们可以向/dev/watchdog写入数据来启动或关闭看门狗。
如:echo 0 >/dev/watchdog
echo这个命令启动的作用是先打开文件,再写入内容,然后关闭。也就是open->write->release。
运行效果:
一段时间后系统会自动重启。
如果执行:
echo 0 >/dev/watchdog
echo V >/dev/watchdog
系统侧不会重启。
原因分析:
open函数:
- static int s3c2410wdt_open(struct inode *inode, struct file *file)
- {
- if (test_and_set_bit(0, &open_lock))
- return -EBUSY;
- if (nowayout)
- __module_get(THIS_MODULE);
- expect_close = 0;
- /* start the timer */
- s3c2410wdt_start();
- return nonseekable_open(inode, file);
- }
- static int s3c2410wdt_release(struct inode *inode, struct file *file)
- {
- /*
- * Shut off the timer.
- * Lock it in if it's a module and we set nowayout
- */
- if (expect_close == 42)
- s3c2410wdt_stop();
- else {
- dev_err(wdt_dev, "Unexpected close, not stopping watchdog\n");
- s3c2410wdt_keepalive();
- }
- expect_close = 0;
- clear_bit(0, &open_lock);
- return 0;
- }
- static ssize_t s3c2410wdt_write(struct file *file, const char __user *data,
- size_t len, loff_t *ppos)
- {
- /*
- * Refresh the timer.
- */
- if (len) {
- if (!nowayout) {
- size_t i;
- /* In case it was set long ago */
- expect_close = 0;
- for (i = 0; i != len; i++) {
- char c;
- if (get_user(c, data + i))
- return -EFAULT;
- if (c == 'V')
- expect_close = 42;
- }
- }
- s3c2410wdt_keepalive();
- }
- return len;
- }
看门狗只能被一个进程打开,打开函数中先判断了一下,然后启动了看门狗;再看write函数,写入的如果是V则允许关闭看门狗,如果不是V仅仅喂狗一次;最后是release函数,如果允许关闭则关闭看门狗,如果不允许关闭,打印"Unexpectedclose, not stopping watchdog",喂狗一次。此时看门狗并没有关闭,所以系统会复位的,如果输入V则看门狗被关闭,这样系统就不复位了。
|
评论暂时关闭