-
Notifications
You must be signed in to change notification settings - Fork 0
/
watchdog.h
42 lines (33 loc) · 1.08 KB
/
watchdog.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "ASR_Arduino.h"
static TimerEvent_t watchDogTimer;
unsigned int maxFeedTime, watchDogCheckInterval;
static volatile unsigned long lastFeedTime = millis();
static void feedWatchDog() {
lastFeedTime = millis();
}
static void checkWatchDog() {
unsigned long currentTime = millis();
if ((currentTime - lastFeedTime) >= maxFeedTime) {
Serial.println(F("Watch Dog is Hungry! Reset Hardware"));
delay(10);
HW_Reset(0);
return;
}
TimerStart(&watchDogTimer);
}
static void stopWatchDog() {
Serial.println(F("Watch Dog stopped"));
TimerStop(&watchDogTimer);
}
static void startWatchDog() {
Serial.println(F("Watch Dog started"));
TimerStart(&watchDogTimer);
feedWatchDog();
}
static void initWatchDog(unsigned int interval, unsigned int maxTime = 0) {
maxFeedTime = maxTime;
watchDogCheckInterval = interval;
TimerInit(&watchDogTimer, checkWatchDog);
TimerSetValue(&watchDogTimer, watchDogCheckInterval);
Serial.printf("Setup Watchdog: Interval %d sec | Max feeding time: %d sec \r\n", int(watchDogCheckInterval / 1000), int(maxFeedTime / 1000));
}