pcwd-watchdog.txt
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:4k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1.                      Berkshire Products PC Watchdog Card
  2.                    Support for ISA Cards  Revision A and C
  3.            Documentation and Driver by Ken Hollis <kenji@bitgate.com>
  4.  The PC Watchdog is a card that offers the same type of functionality that
  5.  the WDT card does, only it doesn't require an IRQ to run.  Furthermore,
  6.  the Revision C card allows you to monitor any IO Port to automatically
  7.  trigger the card into being reset.  This way you can make the card
  8.  monitor hard drive status, or anything else you need.
  9.  The Watchdog Driver has one basic role: to talk to the card and send
  10.  signals to it so it doesn't reset your computer ... at least during
  11.  normal operation.
  12.  The Watchdog Driver will automatically find your watchdog card, and will
  13.  attach a running driver for use with that card.  After the watchdog
  14.  drivers have initialized, you can then talk to the card using the PC
  15.  Watchdog program, available from http://ftp.bitgate.com/pcwd/.
  16.  I suggest putting a "watchdog -d" before the beginning of an fsck, and
  17.  a "watchdog -e -t 1" immediately after the end of an fsck.  (Remember
  18.  to run the program with an "&" to run it in the background!)
  19.  If you want to write a program to be compatible with the PC Watchdog
  20.  driver, simply do the following:
  21. -- Snippet of code --
  22. /*
  23.  * Watchdog Driver Test Program
  24.  */
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <string.h>
  28. #include <unistd.h>
  29. #include <fcntl.h>
  30. #include <sys/ioctl.h>
  31. #include <linux/pcwd.h>
  32. int fd;
  33. /*
  34.  * This function simply sends an IOCTL to the driver, which in turn ticks
  35.  * the PC Watchdog card to reset its internal timer so it doesn't trigger
  36.  * a computer reset.
  37.  */
  38. void keep_alive(void)
  39. {
  40.     int dummy;
  41.     ioctl(fd, WDIOC_KEEPALIVE, &dummy);
  42. }
  43. /*
  44.  * The main program.  Run the program with "-d" to disable the card,
  45.  * or "-e" to enable the card.
  46.  */
  47. int main(int argc, char *argv[])
  48. {
  49.     fd = open("/dev/watchdog", O_WRONLY);
  50.     if (fd == -1) {
  51. fprintf(stderr, "Watchdog device not enabled.n");
  52. fflush(stderr);
  53. exit(-1);
  54.     }
  55.     if (argc > 1) {
  56. if (!strncasecmp(argv[1], "-d", 2)) {
  57.     ioctl(fd, WDIOC_SETOPTIONS, WDIOS_DISABLECARD);
  58.     fprintf(stderr, "Watchdog card disabled.n");
  59.     fflush(stderr);
  60.     exit(0);
  61. } else if (!strncasecmp(argv[1], "-e", 2)) {
  62.     ioctl(fd, WDIOC_SETOPTIONS, WDIOS_ENABLECARD);
  63.     fprintf(stderr, "Watchdog card enabled.n");
  64.     fflush(stderr);
  65.     exit(0);
  66. } else {
  67.     fprintf(stderr, "-d to disable, -e to enable.n");
  68.     fprintf(stderr, "run by itself to tick the card.n");
  69.     fflush(stderr);
  70.     exit(0);
  71. }
  72.     } else {
  73. fprintf(stderr, "Watchdog Ticking Away!n");
  74. fflush(stderr);
  75.     }
  76.     while(1) {
  77. keep_alive();
  78. sleep(1);
  79.     }
  80. }
  81. -- End snippet --
  82.  Other IOCTL functions include:
  83. WDIOC_GETSUPPORT
  84. This returns the support of the card itself.  This
  85. returns in structure "PCWDS" which returns:
  86. options = WDIOS_TEMPPANIC
  87.   (This card supports temperature)
  88. firmware_version = xxxx
  89.   (Firmware version of the card)
  90. WDIOC_GETSTATUS
  91. This returns the status of the card, with the bits of
  92. WDIOF_* bitwise-anded into the value.  (The comments
  93. are in linux/pcwd.h)
  94. WDIOC_GETBOOTSTATUS
  95. This returns the status of the card that was reported
  96. at bootup.
  97. WDIOC_GETTEMP
  98. This returns the temperature of the card.  (You can also
  99. read /dev/watchdog, which gives a temperature update
  100. every second.)
  101. WDIOC_SETOPTIONS
  102. This lets you set the options of the card.  You can either
  103. enable or disable the card this way.
  104. WDIOC_KEEPALIVE
  105. This pings the card to tell it not to reset your computer.
  106.  And that's all she wrote!
  107.  -- Ken Hollis
  108.     (kenji@bitgate.com)
  109. (This documentation may be out of date.  Check
  110.  http://ftp.bitgate.com/pcwd/ for the absolute latest additions.)