am335x watchdog

am335x watchdog

内核文档kernel/Documentation/watchdog

Qt@aplex:~/kernel/7109/linux-3.2.0/Documentation/watchdog$ ll
total 88
drwxrwxr-x 3 Qt Qt 4096 Jun 8 15:11 ./
drwxrwxr-x 94 Qt Qt 12288 Apr 28 13:09 ../
-rwxrwxr-x 1 Qt Qt 576 Nov 20 2013 00-INDEX
-rwxrwxr-x 1 Qt Qt 6789 Nov 20 2013 convert_drivers_to_kernel_api.txt

-rwxrwxr-x 1 Qt Qt 3989 Nov 20 2013 hpwdt.txt
-rwxrwxr-x 1 Qt Qt 2266 Nov 20 2013 pcwd-watchdog.txt

drwxrwxr-x 2 Qt Qt 4096 Jun 8 15:11 src/
-rwxrwxr-x 1 Qt Qt 8442 Nov 20 2013 watchdog-api.txt
-rwxrwxr-x 1 Qt Qt 8387 Nov 20 2013 watchdog-kernel-api.txt

-rwxrwxr-x 1 Qt Qt 16450 Nov 20 2013 watchdog-parameters.txt
-rwxrwxr-x 1 Qt Qt 1825 Nov 20 2013 wdt.txt

参考程序
内核文档kernel/Documentation/watchdog/src/watchdog-simple.c
内核文档kernel/Documentation/watchdog/src/watchdog-test.c

#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/watchdog.h>

int fd;

/*
 * This function simply sends an IOCTL to the driver, which in turn ticks
 * the PC Watchdog card to reset its internal timer so it doesn't trigger
 * a computer reset.
 */
static void keep_alive(void)
{
    int dummy;

    ioctl(fd, WDIOC_KEEPALIVE, &dummy);
}

/*
 * The main program.  Run the program with "-d" to disable the card,
 * or "-e" to enable the card.
 */
int main(int argc, char *argv[])
{
    int flags;

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

    if (fd == -1) {
    fprintf(stderr, "Watchdog device not enabled.\n");
    fflush(stderr);
    exit(-1);
    }

    if (argc > 1) {
    if (!strncasecmp(argv[1], "-d", 2)) {
        flags = WDIOS_DISABLECARD;
        ioctl(fd, WDIOC_SETOPTIONS, &flags);
        fprintf(stderr, "Watchdog card disabled.\n");
        fflush(stderr);
        exit(0);
    } else if (!strncasecmp(argv[1], "-e", 2)) {
        flags = WDIOS_ENABLECARD;
        ioctl(fd, WDIOC_SETOPTIONS, &flags);
        fprintf(stderr, "Watchdog card enabled.\n");
        fflush(stderr);
        exit(0);
    } else {
        fprintf(stderr, "-d to disable, -e to enable.\n");
        fprintf(stderr, "run by itself to tick the card.\n");
        fflush(stderr);
        exit(0);
    }
    } else {
    fprintf(stderr, "Watchdog Ticking Away!\n");
    fflush(stderr);
    }

    while(1) {
    keep_alive();
    sleep(1);
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值