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函数:

  1. static int s3c2410wdt_open(struct inode *inode, struct file *file)  
  2. {  
  3.     if (test_and_set_bit(0, &open_lock))  
  4.         return -EBUSY;  
  5.   
  6.     if (nowayout)  
  7.         __module_get(THIS_MODULE);  
  8.   
  9.     expect_close = 0;  
  10.   
  11.     /* start the timer */  
  12.     s3c2410wdt_start();  
  13.     return nonseekable_open(inode, file);  
  14. }  
release函数:
  1. static int s3c2410wdt_release(struct inode *inode, struct file *file)  
  2. {  
  3.     /* 
  4.      *  Shut off the timer. 
  5.      *  Lock it in if it's a module and we set nowayout 
  6.      */  
  7.   
  8.     if (expect_close == 42)  
  9.         s3c2410wdt_stop();  
  10.     else {  
  11.         dev_err(wdt_dev, "Unexpected close, not stopping watchdog\n");  
  12.         s3c2410wdt_keepalive();  
  13.     }  
  14.     expect_close = 0;  
  15.     clear_bit(0, &open_lock);  
  16.     return 0;  
  17. }  
write函数:
  1. static ssize_t s3c2410wdt_write(struct file *file, const char __user *data,  
  2.                 size_t len, loff_t *ppos)  
  3. {  
  4.     /* 
  5.      *  Refresh the timer. 
  6.      */  
  7.     if (len) {  
  8.         if (!nowayout) {  
  9.             size_t i;  
  10.   
  11.             /* In case it was set long ago */  
  12.             expect_close = 0;  
  13.   
  14.             for (i = 0; i != len; i++) {  
  15.                 char c;  
  16.   
  17.                 if (get_user(c, data + i))  
  18.                     return -EFAULT;  
  19.                 if (c == 'V')  
  20.                     expect_close = 42;  
  21.             }  
  22.         }  
  23.         s3c2410wdt_keepalive();  
  24.     }  
  25.     return len;  
  26. }  

看门狗只能被一个进程打开,打开函数中先判断了一下,然后启动了看门狗;再看write函数,写入的如果是V则允许关闭看门狗,如果不是V仅仅喂狗一次;最后是release函数,如果允许关闭则关闭看门狗,如果不允许关闭,打印"Unexpectedclose, not stopping watchdog",喂狗一次。此时看门狗并没有关闭,所以系统会复位的,如果输入V则看门狗被关闭,这样系统就不复位了。  

  • 1
  • 2
  • 下一页

相关内容