瀏覽代碼

添加客户提供的mywatchdog源码

liu qidong 3 周之前
父節點
當前提交
89dbd2c038
共有 2 個文件被更改,包括 70 次插入0 次删除
  1. 1 0
      Makefile
  2. 69 0
      test_app/mywatchdog.c

+ 1 - 0
Makefile

@@ -20,6 +20,7 @@ all:
 	~/timesys/SDK64Bit-V6_02_00/toolchain/bin/x86_64-timesys-linux-gnu-gcc test_app/test_beep.c -DPROJECT=$(PROJECT_NAME) -o test_app/beep
 	~/timesys/SDK64Bit-V6_02_00/toolchain/bin/x86_64-timesys-linux-gnu-gcc test_app/setled.c -DPROJECT=$(PROJECT_NAME) -o test_app/setled
 	~/timesys/SDK64Bit-V6_02_00/toolchain/bin/x86_64-timesys-linux-gnu-gcc test_app/system_ctl_app.c -DPROJECT=$(PROJECT_NAME) -o test_app/system_ctl_app
+	~/timesys/SDK64Bit-V6_02_00/toolchain/bin/x86_64-timesys-linux-gnu-gcc test_app/mywatchdog.c -DPROJECT=$(PROJECT_NAME) -o test_app/mywatchdog
 	~/timesys/SDK64Bit-V6_02_00/toolchain/bin/x86_64-timesys-linux-gnu-gcc test_app/cash_app.c -DPROJECT=$(PROJECT_NAME) -o test_app/cash_app -lpthread
 
 clean:

+ 69 - 0
test_app/mywatchdog.c

@@ -0,0 +1,69 @@
+#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;
+}