123456789101112131415161718192021222324252627282930313233343536 |
- #ifndef SOFTWAREWATCHDOG_H
- #define SOFTWAREWATCHDOG_H
- #include <time.h>
- #include <stdbool.h>
- #ifdef _WIN32
- #include <windows.h>
- #include <winpthreads.h>
- #define sleep(...) (Sleep(1000.0*__VA_ARGS__))
- #else
- #include <pthread.h>
- #include <unistd.h>
- #endif
- // Software WatchDog (swd)
- void printHelloWorld();
- typedef void (*timeout_cb_t)(void *watchdog);
- typedef struct {
- char *name;
- timeout_cb_t timeout_cb;
- struct timespec timeout;
- struct timespec latestKick;
- void *userData;
- bool isEnabled;
- pthread_t thread_id;
- pthread_mutex_t mutex;
- } SoftwareWatchdog;
- // return -1 on error
- int swd_setup(SoftwareWatchdog *watchdog, const char *name, timeout_cb_t timeout_cb, struct timespec timeout, void *userData);
- int swd_enable(SoftwareWatchdog *watchdog);
- void swd_disable(SoftwareWatchdog *watchdog);
- void swd_kick(SoftwareWatchdog *watchdog);
- #endif /* SOFTWAREWATCHDOG_H */
|