software_watchdog.h 788 B

123456789101112131415161718192021222324252627282930
  1. #ifndef SOFTWAREWATCHDOG_H
  2. #define SOFTWAREWATCHDOG_H
  3. #include <time.h>
  4. #include <stdbool.h>
  5. #include <pthread.h>
  6. // Software WatchDog (swd)
  7. void printHelloWorld();
  8. typedef void (*timeout_cb_t)(void *watchdog);
  9. typedef struct {
  10. char *name;
  11. timeout_cb_t timeout_cb;
  12. struct timespec timeout;
  13. struct timespec latestKick;
  14. void *userData;
  15. bool isEnabled;
  16. pthread_t thread_id;
  17. pthread_mutex_t mutex;
  18. } SoftwareWatchdog;
  19. // return -1 on error
  20. int swd_setup(SoftwareWatchdog *watchdog, char *name, timeout_cb_t timeout_cb, struct timespec timeout, void *userData);
  21. int swd_enable(SoftwareWatchdog *watchdog);
  22. void swd_disable(SoftwareWatchdog *watchdog);
  23. void swd_kick(SoftwareWatchdog *watchdog);
  24. #endif /* SOFTWAREWATCHDOG_H */