mini6410实现 看门狗移植
来源:互联网 发布:时光知味 编辑:程序博客网 时间:2024/06/05 20:10
看门狗是嵌入式系统中最常见的功能之一,一旦启动了看门狗,它就无法停止了,
只有不停的去喂它,否则系统就会复位重启。Reboot和“看门狗”是完全不同的功能,“看门狗”属于“冷”启
动,它不会逐项关闭各个应用和服务,而是直接复位重启。
S3C2440芯片本身就带有看门狗,最新的内
核中已经包含了它的驱动,现在我们就在应用程序中启动它。
写在移植前的:
看门狗在嵌入式系统开发中占据重要的地位,管理系统的工作状态。在这里本人muge0913在参考别人的基础上,实现了mini6410看门狗的移植。本文章仅供技术交流请勿商用,转载请标明地址:
http://blog.csdn.net/muge0913/article/details/7063001
在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);
- }
release函数:
- 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;
- }
write函数:
- 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则看门狗被关闭,这样系统就不复位了。
看门狗在mini6410上的移植过程:
首先配置:make menuconfig
在drivers/watchdog/s3c2410_wdt.c中进行修改:
- #define CONFIG_S3C2410_WATCHDOG_ATBOOT (1)
- #define CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME (15)
注:
- #define CONFIG_S3C2410_WATCHDOG_ATBOOT (0)//系统启动时不开启看门狗
- #define CONFIG_S3C2410_WATCHDOG_DEFAULT_TIME (15)//复位时间
设置成系统启动就启动看门狗,并且看门狗到期时间为15s。这样系统复位后每15s系统就会复位一次,所以我们在用户空间进行喂狗,驱动中的那个中断函数是当看门狗作为定时器时用的,所以没有实现喂狗,所以只能在用户程序中喂狗,下面是源码:
- #include <stdio.h>
- #include <unistd.h>
- #include <sys/stat.h>
- #include <sys/types.h>
- #include <fcntl.h>
- #include <stdlib.h>
- #include <errno.h>
- #include <linux/watchdog.h>
- int main(int argc, char **argv){
- int fd;
- fd = open("/dev/watchdog",O_RDONLY);
- if(fd < 0){
- perror("/dev/watchdog");
- return -1;
- }
- for(;;){
- ioctl(fd, WDIOC_KEEPALIVE);
- sleep(3);
- }
- close(fd);
- return 0;
- }
编译:
- arm-linux-gcc wdt.c -o wdt
把wdt拷贝到root-2.6.30.4/sbin/下,并修改root-2.6.38/etc/init.d/rcS文件,添加wdt&这么一句,让系统启动后这个应用程序在后台运行。
- #! /bin/sh
- PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:
- runlevel=S
- prevlevel=N
- umask 022
- export PATH runlevel prevlevel
- #
- # Trap CTRL-C &c only in this shell so we can interrupt subprocesses.
- #
- trap ":" INT QUIT TSTP
- /bin/hostname FriendlyARM
- [ -e /proc/1 ] || /bin/mount -n -t proc none /proc
- [ -e /sys/class ] || /bin/mount -n -t sysfs none /sys
- [ -e /dev/tty ] || /bin/mount -t ramfs none /dev
- /bin/mount -n -t usbfs none /proc/bus/usb
- echo /sbin/mdev > /proc/sys/kernel/hotplug
- /sbin/mdev -s
- /bin/hotplug
- # mounting file system specified in /etc/fstab
- mkdir -p /dev/pts
- mkdir -p /dev/shm
- /bin/mount -n -t devpts none /dev/pts -o mode=0622
- /bin/mount -n -t tmpfs tmpfs /dev/shm
- /bin/mount -n -t ramfs none /tmp
- /bin/mount -n -t ramfs none /var
- mkdir -p /var/empty
- mkdir -p /var/log
- mkdir -p /var/lock
- mkdir -p /var/run
- mkdir -p /var/tmp
- /sbin/hwclock -s
- syslogd
- /etc/rc.d/init.d/netd start
- echo " " > /dev/tty1
- echo "Starting networking..." > /dev/tty1
- sleep 1
- /etc/rc.d/init.d/httpd start
- echo " " > /dev/tty1
- echo "Starting web server..." > /dev/tty1
- sleep 1
- /etc/rc.d/init.d/leds start
- echo " " > /dev/tty1
- echo "Starting leds service..." > /dev/tty1
- echo " "
- sleep 1
- echo " " > /dev/tty1
- /etc/rc.d/init.d/alsaconf start
- echo "Loading sound card config..." > /dev/tty1
- echo " "
- /sbin/ifconfig lo 127.0.0.1
- /etc/init.d/ifconfig-eth0
- /sbin/wdt&
- /bin/qtopia &
- echo " " > /dev/tty1
- echo "Starting Qtopia, please waiting..." > /dev/tty1
查看进程已经运行
- mini6410实现 看门狗移植
- mini6410 看门狗源码分析
- mini6410成功移植OPENCV-2.0.0实现人脸检测
- mini6410成功移植OPENCV-2.0.0实现人脸检测
- mini6410成功移植OPENCV-2.0.0实现人脸检测
- mini6410成功移植OPENCV-2.0.0实现人脸检测
- mini6410成功移植OPENCV-2.0.0实现人脸检测
- mini6410 kernel 移植
- Mini6410上移植mplayer
- mini6410下移植apache
- MINI6410移植攻略
- Mini6410移植RT3070网卡
- mini6410之UBOOT移植
- U-BOOT for Mini6410 移植
- mini6410防火墙(Netfilter/iptables)移植
- 移植Qt4.7到mini6410
- mini6410下移植apache+php
- mini6410移植--uboot移植(2)
- JS正则表达式验证数字
- php文件上传
- JSONObject和JSONArray的使用 以及JSONObject put,accumulate,element的区别
- linux杂谈(十二):CDN加速
- Java中HashMap和TreeMap的区别深入理解
- mini6410实现 看门狗移植
- Struts2的struts.xml配置中的namespace的使用
- Android registerContentObserver 接口监视数据库变化
- Java JDBC Thin Driver 连接 Oracle 三种方法说明
- 回调函数的作用
- PHP从零单排(十二)使用PHP连接MySQL数据库
- hadoop streamig 运行c/c++程序 少读一个字符
- Aspose.Words for .NET示例大全免费免积分下载
- 深入了解Struts2返回JSON数据的原理及具体应用范例