WatchDog.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_error("System watch dog initial fail.\r\n");
  26. }
  27. ioctl(fd, _IOWR('W', 6, int), &timeout);
  28. return fd;
  29. }
  30. void CreateWatchdog(void)
  31. {
  32. wtdFd = InitWatchDog();
  33. ShmStatusCodeData = (struct StatusCodeData*)GetShmStatusCodeData();
  34. if(wtdFd < 0)
  35. {
  36. log_info("Watchdog Initial Fail");
  37. ShmStatusCodeData->AlarmCode.AlarmEvents.bits.CsuInitFailed = 1;
  38. }
  39. else
  40. {
  41. log_info("Watchdog Initial Success");
  42. }
  43. }
  44. void TryCloseWatchdog(void)
  45. {
  46. if(wtdFd > 0)
  47. {
  48. write(wtdFd, "V", 1);
  49. close(wtdFd);
  50. }
  51. }
  52. void TryFeedWatchdog(void)
  53. {
  54. if(wtdFd > 0)
  55. {
  56. write(wtdFd, "a", 1);
  57. }
  58. }