annotate vd_watchdog/vd_watchdog.c @ 0:71475f5afa92

Watchdog for Vortex86 6071 on FreeBSD
author Thinker K.F. Li <thinker@branda.to>
date Tue, 08 Jul 2008 09:57:54 +0800
parents
children 0b9854adb86c
rev   line source
0
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
1 #include <stdio.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
2 #include <stdlib.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
3 #include <unistd.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
4 #include <fcntl.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
5 #include <sys/ioctl.h>
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
6 #include "vordog.h"
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
7
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
8 #define DEVNAME "/dev/vordog0"
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
9 #define PROG "vd_watchdog"
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
10
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
11 static void
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
12 watchdog(int min) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
13 struct vordog_cfg cfg;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
14 int intval;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
15 int r;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
16 int fd;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
17
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
18 fd = open(DEVNAME, O_RDWR);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
19 if(fd == -1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
20 perror(PROG);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
21 exit(1);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
22 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
23 cfg.init_val = min;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
24 cfg.unit = VDT_1M;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
25 r = ioctl(fd, VDCTL_ENABLE, &cfg);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
26 if(r == -1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
27 perror(PROG);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
28 exit(1);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
29 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
30
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
31 intval = min * 60 * 3 / 4;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
32 while(1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
33 sleep(intval);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
34 r = ioctl(fd, VDCTL_RESET);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
35 if(r == -1) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
36 perror(PROG);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
37 exit(1);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
38 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
39 printf("reset\n");
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
40 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
41 }
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
42
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
43
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
44 int
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
45 main(int argc, const char *argv[]) {
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
46 watchdog(1);
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
47 return 0;
71475f5afa92 Watchdog for Vortex86 6071 on FreeBSD
Thinker K.F. Li <thinker@branda.to>
parents:
diff changeset
48 }