[RPI]看门狗---[浙江大学嵌入式系统]

 

 

实验要求:配置内核中的硬件看门狗,使得一定时间内不喂狗就重启RPi,写一个程序或脚本保持一定频率的喂狗,当关闭这个程 序或脚本时形成重启。实验报告要记录和表现出重启。

实验步骤:

  1. 首先让硬件的看门狗模块运行起来

                      

在/etc/modules 末尾添加

bcm2708_wdog

 

  1. 喂狗原理
  2. 喂狗就是在程序中打开了/dev/watchdog,写入除了‘V’字符的任意内容。在程序中要避免重启,就要每隔一段时间往设备中写一次数据。

关闭看门狗,则要往设备中写入一个‘V’字符。

参考文档:https://www.kernel.org/doc/Documentation/watchdog/watchdog-api.txt

 

  1. 开始喂狗

喂狗程序feed.c

#include <stdio.h>

#include <stdlib.h>

#include <unistd.h>

#include <fcntl.h>

int main(void)

{

         int   fd = open("/dev/watchdog", O_WRONLY);

         int   res = 0;

 

         if   (fd == -1) {

                  perror("open error");

                  exit(EXIT_FAILURE);

         }

         while   (1) {

                  printf(“feed dog now!\n”);

                  res = write(fd, "a", 1);//写入字符”a”

                  if (ret != 1) {

                           ret   = -1;

                           break;

                  }

                  sleep(5);//喂狗间隔5秒钟

         }

         close(fd);

         return   res;

}

 

编译feed.c

 

 

退出喂狗程序,过5秒左右系统出现error,树莓派需重启!

posted @ 2013-03-19 14:38  浪里个浪荡荡  阅读(482)  评论(0编辑  收藏  举报