WatchDog.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include <stdio.h> /*標準輸入輸出定義*/
  2. #include <stdlib.h> /*標準函數庫定義*/
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include "../Config.h"
  6. #include "../Log/log.h"
  7. #include "../Define/define.h"
  8. #include "../ShareMemory/shmMem.h"
  9. int wtdFd = -1;
  10. struct StatusCodeData *ShmStatusCodeData;
  11. void CreateWatchdog(void);
  12. void TryCloseWatchdog(void);
  13. void TryFeedWatchdog(void);
  14. int InitWatchDog()
  15. {
  16. int fd;
  17. int timeout = 180;
  18. system("/usr/bin/fuser -k /dev/watchdog");
  19. sleep(1);
  20. system("echo V > /dev/watchdog");
  21. sleep(1);
  22. fd=open("/dev/watchdog", O_RDWR);
  23. if(fd<=0)
  24. {
  25. log_info("Open watchdog fd:%d",fd);
  26. log_error("System watch dog initial fail.\n");
  27. }
  28. ioctl(fd, _IOWR('W', 6, int), &timeout);
  29. return fd;
  30. }
  31. void CreateWatchdog(void)
  32. {
  33. wtdFd = InitWatchDog();
  34. ShmStatusCodeData = (struct StatusCodeData*)GetShmStatusCodeData();
  35. if(wtdFd < 0)
  36. {
  37. log_info("Watchdog Initial Fail");
  38. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  39. }
  40. else
  41. {
  42. log_info("Watchdog Initial Success (%d)",wtdFd);
  43. }
  44. }
  45. void TryCloseWatchdog(void)
  46. {
  47. if(wtdFd > 0)
  48. {
  49. write(wtdFd, "V", 1);
  50. close(wtdFd);
  51. }
  52. }
  53. void TryFeedWatchdog(void)
  54. {
  55. if(wtdFd > 0)
  56. {
  57. write(wtdFd, "a", 1);
  58. }
  59. }