|
@@ -1255,12 +1255,93 @@ static void send_check(void)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+//https://blog.csdn.net/weixin_47604497/article/details/136913868
|
|
|
|
|
+#include <linux/watchdog.h>
|
|
|
|
|
+static int wdog_fd=-1;
|
|
|
|
|
+static int wdog_init(void)
|
|
|
|
|
+{
|
|
|
|
|
+ int r=0;
|
|
|
|
|
+
|
|
|
|
|
+#ifdef USE_WDOG
|
|
|
|
|
+ char *path="/dev/watchdog";
|
|
|
|
|
+ struct watchdog_info info;
|
|
|
|
|
+ int option = WDIOS_DISABLECARD;
|
|
|
|
|
+
|
|
|
|
|
+ if(wdog_fd<0) {
|
|
|
|
|
+ wdog_fd = open(path, O_RDWR); //O_WRONLY
|
|
|
|
|
+ if(wdog_fd<0) {
|
|
|
|
|
+ printf("___ %s open failed\n", path);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+#if 0
|
|
|
|
|
+ r = ioctl(wdog_fd, WDIOC_SETOPTIONS, &option);
|
|
|
|
|
+
|
|
|
|
|
+ r = ioctl(wdog_fd, WDIOC_GETSUPPORT, &info);
|
|
|
|
|
+ if(r<0) {
|
|
|
|
|
+ printf("___ %s getsupport failed\n", path);
|
|
|
|
|
+ return -1;
|
|
|
|
|
+ }
|
|
|
|
|
+ printf("___ watchdog options: 0x%x\n", info.options&WDIOC_SETTIMEOUT);
|
|
|
|
|
+
|
|
|
|
|
+ r = ioctl(wdog_fd, WDIOC_SETTIMEOUT, &timeout);
|
|
|
|
|
+
|
|
|
|
|
+ option = WDIOS_ENABLECARD;
|
|
|
|
|
+ r = ioctl(wdog_fd, WDIOC_SETOPTIONS, &option);
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+ return r;
|
|
|
|
|
+}
|
|
|
|
|
+static int wdog_enable(int en)
|
|
|
|
|
+{
|
|
|
|
|
+ int r=0;
|
|
|
|
|
+
|
|
|
|
|
+#ifdef USE_WDOG
|
|
|
|
|
+ int option = en?WDIOS_ENABLECARD:WDIOS_DISABLECARD;
|
|
|
|
|
+ r = ioctl(wdog_fd, WDIOC_SETOPTIONS, &option);
|
|
|
|
|
+#endif
|
|
|
|
|
+ return r;
|
|
|
|
|
+}
|
|
|
|
|
+static int wdog_feed(void)
|
|
|
|
|
+{
|
|
|
|
|
+ int r=0,t1=100,t2=0;
|
|
|
|
|
+
|
|
|
|
|
+#ifdef USE_WDOG
|
|
|
|
|
+ r = ioctl(wdog_fd, WDIOC_KEEPALIVE, NULL);
|
|
|
|
|
+
|
|
|
|
|
+ //r = ioctl(wdog_fd, WDIOC_SETTIMEOUT, &t1);
|
|
|
|
|
+ //printf("______set__________ wdog timeout: %d\n", r);
|
|
|
|
|
+ //r = ioctl(wdog_fd, WDIOC_GETTIMEOUT, &t2);
|
|
|
|
|
+ //printf("________________ wdog timeout: %d\n", t2);
|
|
|
|
|
+#endif
|
|
|
|
|
+ return r;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+static void sig_handler(int signo)
|
|
|
|
|
+{
|
|
|
|
|
+ printf("sigint_handler, signo: %d\n", signo);
|
|
|
|
|
+}
|
|
|
|
|
+static void sig_init(void)
|
|
|
|
|
+{
|
|
|
|
|
+ signal(SIGINT, sig_handler);
|
|
|
|
|
+ signal(SIGTERM, sig_handler);
|
|
|
|
|
+ signal(SIGKILL, sig_handler);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
static void* polling_thread(void *arg)
|
|
static void* polling_thread(void *arg)
|
|
|
{
|
|
{
|
|
|
thread_handle_t *h=(thread_handle_t*)arg;
|
|
thread_handle_t *h=(thread_handle_t*)arg;
|
|
|
|
|
|
|
|
|
|
+ wdog_init();
|
|
|
tmp_create();
|
|
tmp_create();
|
|
|
while(h->quit==0) {
|
|
while(h->quit==0) {
|
|
|
|
|
+ wdog_feed();
|
|
|
mem_check();
|
|
mem_check();
|
|
|
send_check();
|
|
send_check();
|
|
|
sleep(1);
|
|
sleep(1);
|