mywatchdog.c 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #include <fcntl.h>
  2. #include <linux/kd.h>
  3. #include <linux/vt.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include "gpioregs.h"
  7. #define DEV_FILE "/dev/watchdog"
  8. int main(int argc, char *argv[])
  9. {
  10. int fd;
  11. int retval=1;
  12. char args;
  13. /* char *voidptr = (char *) NULL; */
  14. char *ptr = argv[0];
  15. if (argc != 2)
  16. {
  17. printf ("Usage: %s [on/off/status] \n", argv[0]);
  18. exit (-1);
  19. }
  20. if (strcmp(argv[1], "on") == 0)
  21. args = ON;
  22. else if (strcmp(argv[1], "off") == 0)
  23. args = OFF;
  24. else if (strcmp(argv[1], "status") == 0)
  25. {
  26. if ((fd = open(DEV_FILE, O_RDONLY)) == -1)
  27. {
  28. printf("%s: can't open /dev/watchdog\n", argv[0]);
  29. return(-1);
  30. }
  31. if(read(fd, &args,1) == 1)
  32. {
  33. printf ("The watchdog is %s\n",args?"on":"off");
  34. printf ("The args value is %d\n", args);
  35. }
  36. else
  37. {
  38. printf ("Could not read status from the %s\n", DEV_FILE);
  39. close(fd);
  40. return(-1);
  41. }
  42. close(fd);
  43. return (0);
  44. }
  45. else
  46. {
  47. printf ("Unrecognized command. \n");
  48. exit (-1);
  49. }
  50. if ((fd = open(DEV_FILE, O_WRONLY)) == -1) {
  51. printf("%s: can't open /dev/writeprotect\n", argv[0]);
  52. return(-1);
  53. }
  54. if(write(fd, &args,1) == 1)
  55. {
  56. printf ("Watchdog turned %s successfully\n", argv[1]);
  57. }
  58. else
  59. {
  60. printf ("Could not write to the %s\n", DEV_FILE);
  61. close(fd);
  62. return(-1);
  63. }
  64. close(fd);
  65. return 0;
  66. }