pcwd-watchdog.txt 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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/types.h>
  32. #include <linux/watchdog.h>
  33. int fd;
  34. /*
  35. * This function simply sends an IOCTL to the driver, which in turn ticks
  36. * the PC Watchdog card to reset its internal timer so it doesn't trigger
  37. * a computer reset.
  38. */
  39. void keep_alive(void)
  40. {
  41. int dummy;
  42. ioctl(fd, WDIOC_KEEPALIVE, &dummy);
  43. }
  44. /*
  45. * The main program. Run the program with "-d" to disable the card,
  46. * or "-e" to enable the card.
  47. */
  48. int main(int argc, char *argv[])
  49. {
  50. fd = open("/dev/watchdog", O_WRONLY);
  51. if (fd == -1) {
  52. fprintf(stderr, "Watchdog device not enabled.\n");
  53. fflush(stderr);
  54. exit(-1);
  55. }
  56. if (argc > 1) {
  57. if (!strncasecmp(argv[1], "-d", 2)) {
  58. ioctl(fd, WDIOC_SETOPTIONS, WDIOS_DISABLECARD);
  59. fprintf(stderr, "Watchdog card disabled.\n");
  60. fflush(stderr);
  61. exit(0);
  62. } else if (!strncasecmp(argv[1], "-e", 2)) {
  63. ioctl(fd, WDIOC_SETOPTIONS, WDIOS_ENABLECARD);
  64. fprintf(stderr, "Watchdog card enabled.\n");
  65. fflush(stderr);
  66. exit(0);
  67. } else {
  68. fprintf(stderr, "-d to disable, -e to enable.\n");
  69. fprintf(stderr, "run by itself to tick the card.\n");
  70. fflush(stderr);
  71. exit(0);
  72. }
  73. } else {
  74. fprintf(stderr, "Watchdog Ticking Away!\n");
  75. fflush(stderr);
  76. }
  77. while(1) {
  78. keep_alive();
  79. sleep(1);
  80. }
  81. }
  82. -- End snippet --
  83. Other IOCTL functions include:
  84. WDIOC_GETSUPPORT
  85. This returns the support of the card itself. This
  86. returns in structure "PCWDS" which returns:
  87. options = WDIOS_TEMPPANIC
  88. (This card supports temperature)
  89. firmware_version = xxxx
  90. (Firmware version of the card)
  91. WDIOC_GETSTATUS
  92. This returns the status of the card, with the bits of
  93. WDIOF_* bitwise-anded into the value. (The comments
  94. are in linux/pcwd.h)
  95. WDIOC_GETBOOTSTATUS
  96. This returns the status of the card that was reported
  97. at bootup.
  98. WDIOC_GETTEMP
  99. This returns the temperature of the card. (You can also
  100. read /dev/watchdog, which gives a temperature update
  101. every second.)
  102. WDIOC_SETOPTIONS
  103. This lets you set the options of the card. You can either
  104. enable or disable the card this way.
  105. WDIOC_KEEPALIVE
  106. This pings the card to tell it not to reset your computer.
  107. And that's all she wrote!
  108. -- Ken Hollis
  109. (kenji@bitgate.com)
  110. (This documentation may be out of date. Check
  111. http://ftp.bitgate.com/pcwd/ for the absolute latest additions.)