| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- #include <fcntl.h>
- #include <linux/kd.h>
- #include <linux/vt.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include "gpioregs.h"
- #define DEV_FILE "/dev/watchdog"
- int main(int argc, char *argv[])
- {
- int fd;
- int retval=1;
- char args;
- /* char *voidptr = (char *) NULL; */
- char *ptr = argv[0];
- if (argc != 2)
- {
- printf ("Usage: %s [on/off/status] \n", argv[0]);
- exit (-1);
- }
- if (strcmp(argv[1], "on") == 0)
- args = ON;
- else if (strcmp(argv[1], "off") == 0)
- args = OFF;
- else if (strcmp(argv[1], "status") == 0)
- {
- if ((fd = open(DEV_FILE, O_RDONLY)) == -1)
- {
- printf("%s: can't open /dev/watchdog\n", argv[0]);
- return(-1);
- }
- if(read(fd, &args,1) == 1)
- {
- printf ("The watchdog is %s\n",args?"on":"off");
- printf ("The args value is %d\n", args);
- }
- else
- {
- printf ("Could not read status from the %s\n", DEV_FILE);
- close(fd);
- return(-1);
- }
- close(fd);
- return (0);
- }
- else
- {
- printf ("Unrecognized command. \n");
- exit (-1);
- }
- if ((fd = open(DEV_FILE, O_WRONLY)) == -1) {
- printf("%s: can't open /dev/writeprotect\n", argv[0]);
- return(-1);
- }
-
- if(write(fd, &args,1) == 1)
- {
- printf ("Watchdog turned %s successfully\n", argv[1]);
- }
- else
- {
- printf ("Could not write to the %s\n", DEV_FILE);
- close(fd);
- return(-1);
- }
- close(fd);
- return 0;
- }
|