software_watchdog.h 959 B

123456789101112131415161718192021222324252627282930313233343536
  1. #ifndef SOFTWAREWATCHDOG_H
  2. #define SOFTWAREWATCHDOG_H
  3. #include <time.h>
  4. #include <stdbool.h>
  5. #ifdef _WIN32
  6. #include <windows.h>
  7. #include <winpthreads.h>
  8. #define sleep(...) (Sleep(1000.0*__VA_ARGS__))
  9. #else
  10. #include <pthread.h>
  11. #include <unistd.h>
  12. #endif
  13. // Software WatchDog (swd)
  14. void printHelloWorld();
  15. typedef void (*timeout_cb_t)(void *watchdog);
  16. typedef struct {
  17. char *name;
  18. timeout_cb_t timeout_cb;
  19. struct timespec timeout;
  20. struct timespec latestKick;
  21. void *userData;
  22. bool isEnabled;
  23. pthread_t thread_id;
  24. pthread_mutex_t mutex;
  25. } SoftwareWatchdog;
  26. // return -1 on error
  27. int swd_setup(SoftwareWatchdog *watchdog, const char *name, timeout_cb_t timeout_cb, struct timespec timeout, void *userData);
  28. int swd_enable(SoftwareWatchdog *watchdog);
  29. void swd_disable(SoftwareWatchdog *watchdog);
  30. void swd_kick(SoftwareWatchdog *watchdog);
  31. #endif /* SOFTWAREWATCHDOG_H */