main.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <stdio.h>
  2. #include <pthread.h>
  3. #include "common.h"
  4. #include "modbus_handle.h"
  5. #include "sqlite_handle.h"
  6. #include "list.h"
  7. #include "switch_ctrl.h"
  8. #include "app.h"
  9. #include "shell.h"
  10. #include <linux/watchdog.h>
  11. #include "errno.h"
  12. #include "fcntl.h"
  13. static int wdog_fd=-1;
  14. static int wdog_init(void)
  15. {
  16. int r =0;
  17. char *path="/dev/watchdog";
  18. if(wdog_fd<0) {
  19. wdog_fd = open(path, O_RDWR); //O_WRONLY
  20. log_d("wdog_fd = %d\n",wdog_fd);
  21. if(wdog_fd<0) {
  22. printf("___ %s open failed\n", path);
  23. return -1;
  24. }
  25. }
  26. int i,option,timeout;
  27. struct watchdog_info info;
  28. option = WDIOS_DISABLECARD;
  29. r = ioctl(wdog_fd, WDIOC_SETOPTIONS, &option);
  30. r = ioctl(wdog_fd, WDIOC_GETSUPPORT, &info);
  31. if(r<0) {
  32. printf("___ %s getsupport failed\n", path);
  33. return -1;
  34. }
  35. printf("___ watchdog options: 0x%x\n", info.options&WDIOC_SETTIMEOUT);
  36. timeout = 40;
  37. r = ioctl(wdog_fd, WDIOC_SETTIMEOUT, &timeout);
  38. if(r) {
  39. printf("______set__________ wdog set timeout: %d failed, errno: %d\n", timeout, errno);
  40. }
  41. option = WDIOS_ENABLECARD;
  42. r = ioctl(wdog_fd, WDIOC_SETOPTIONS, &option);
  43. // }
  44. return r;
  45. }
  46. static int wdog_feed(void)
  47. {
  48. int r=0;
  49. //if(wdog_is_en()) {
  50. r = ioctl(wdog_fd, WDIOC_KEEPALIVE, 0);
  51. //int t1=200,t2=0;
  52. //r = ioctl(wdog_fd, WDIOC_SETTIMEOUT, &t1);
  53. //printf("______set__________ wdog timeout: %d, errno: %d\n", r, errno);
  54. //r = ioctl(wdog_fd, WDIOC_GETTIMEOUT, &t2);
  55. //printf("________________ wdog timeout: %d\n", t2);
  56. //}
  57. return r;
  58. }
  59. void * _global_feed_dog(void* arg)
  60. {
  61. while(1)
  62. {
  63. wdog_feed();
  64. sleep(1);
  65. }
  66. pthread_exit(NULL);
  67. }
  68. //主函数
  69. int main(int argc,char* argv[])
  70. {
  71. pthread_t pthread_wg = 0;
  72. initLogger();
  73. wdog_init();
  74. pthread_create(&pthread_wg, NULL, _global_feed_dog, NULL);
  75. //初始化系统
  76. _global_device_manage_init(&__globalDeviceManage);
  77. return 0;
  78. }