| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- #include <stdio.h>
- #include <pthread.h>
- #include "common.h"
- #include "modbus_handle.h"
- #include "sqlite_handle.h"
- #include "list.h"
- #include "switch_ctrl.h"
- #include "app.h"
- #include "shell.h"
- #include <linux/watchdog.h>
- #include "errno.h"
- #include "fcntl.h"
- static int wdog_fd=-1;
- static int wdog_init(void)
- {
- int r =0;
- char *path="/dev/watchdog";
- if(wdog_fd<0) {
- wdog_fd = open(path, O_RDWR); //O_WRONLY
- log_d("wdog_fd = %d\n",wdog_fd);
- if(wdog_fd<0) {
- printf("___ %s open failed\n", path);
- return -1;
- }
- }
- int i,option,timeout;
- struct watchdog_info info;
-
- option = WDIOS_DISABLECARD;
- 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);
- timeout = 40;
- r = ioctl(wdog_fd, WDIOC_SETTIMEOUT, &timeout);
- if(r) {
- printf("______set__________ wdog set timeout: %d failed, errno: %d\n", timeout, errno);
- }
- option = WDIOS_ENABLECARD;
- r = ioctl(wdog_fd, WDIOC_SETOPTIONS, &option);
- // }
- return r;
- }
- static int wdog_feed(void)
- {
- int r=0;
- //if(wdog_is_en()) {
- r = ioctl(wdog_fd, WDIOC_KEEPALIVE, 0);
- //int t1=200,t2=0;
- //r = ioctl(wdog_fd, WDIOC_SETTIMEOUT, &t1);
- //printf("______set__________ wdog timeout: %d, errno: %d\n", r, errno);
-
- //r = ioctl(wdog_fd, WDIOC_GETTIMEOUT, &t2);
- //printf("________________ wdog timeout: %d\n", t2);
- //}
- return r;
- }
- void * _global_feed_dog(void* arg)
- {
- while(1)
- {
- wdog_feed();
- sleep(1);
- }
- pthread_exit(NULL);
- }
- //主函数
- int main(int argc,char* argv[])
- {
- pthread_t pthread_wg = 0;
- initLogger();
- wdog_init();
- pthread_create(&pthread_wg, NULL, _global_feed_dog, NULL);
- //初始化系统
- _global_device_manage_init(&__globalDeviceManage);
- return 0;
- }
|