Skip to content

Commit 5773f25

Browse files
committed
Basic watchdog implementation
1 parent 0676747 commit 5773f25

File tree

4 files changed

+82
-8
lines changed

4 files changed

+82
-8
lines changed

BoxButtonEars.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@ void BoxButtonEars::reloadConfig() {
7777

7878
void BoxButtonEars::waitForRelease() {
7979
while (true) {
80-
delay(250);
80+
delay(100);
81+
Box.watchdog_feed();
8182
_earSmall.read();
8283
_earBig.read();
8384
if (!_earSmall.isPressed() && !_earBig.isPressed())

BoxPower.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void BoxPower::_preparePowerDown() {
3434
Log.info("Prepare power down...");
3535
//TODO
3636
//smartconfig down
37-
//disable watchdog
37+
Box.watchdog_stop();
3838
setSdPower(false);
3939
setOtherPower(false);
4040
Box.boxLEDs.setAllBool(false);

Hackiebox.cpp

+58-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ BoxConfig Config;
44
BoxEvents Events;
55
Hackiebox Box;
66
void Hackiebox::setup() {
7-
//watchdog set 30s?
7+
if (!watchdog_start()) {
8+
watchdog_stop();
9+
//reset box?!
10+
}
811

912
Log.init(LOG_LEVEL_VERBOSE, 115200/*, &logStream*/);
1013
Log.info("Booting Hackiebox, Free MEM=%ib...", freeMemory());
@@ -58,8 +61,59 @@ void Hackiebox::setup() {
5861
}
5962

6063
void Hackiebox::loop() {
64+
watchdog_feed();
6165
_threadController.run();
62-
63-
//watchdog.feed
6466
webServer.handle();
65-
}
67+
}
68+
69+
bool Hackiebox::watchdog_isFed() {
70+
return _watchdog_fed;
71+
}
72+
void Hackiebox::watchdog_feed() {
73+
_watchdog_fed = true;
74+
}
75+
void Hackiebox::watchdog_unfeed() {
76+
_watchdog_fed = false;
77+
}
78+
void watchdog_handler() {
79+
if (Box.watchdog_isFed()) {
80+
MAP_WatchdogIntClear(WDT_BASE);
81+
Box.watchdog_unfeed();
82+
}
83+
}
84+
bool Hackiebox::watchdog_start() {
85+
watchdog_feed();
86+
// Enable the peripherals used by this example.
87+
MAP_PRCMPeripheralClkEnable(PRCM_WDT, PRCM_RUN_MODE_CLK);
88+
89+
// Unlock to be able to configure the registers
90+
MAP_WatchdogUnlock(WDT_BASE);
91+
92+
//if (fpAppWDTCB != NULL) {
93+
MAP_IntPrioritySet(INT_WDT, INT_PRIORITY_LVL_1);
94+
MAP_WatchdogIntRegister(WDT_BASE, watchdog_handler);
95+
//}
96+
97+
98+
// Set the watchdog timer reload value
99+
MAP_WatchdogReloadSet(WDT_BASE, 80000000*15); //15s
100+
101+
// Start the timer. Once the timer is started, it cannot be disable.
102+
MAP_WatchdogEnable(WDT_BASE);
103+
104+
return MAP_WatchdogRunning(WDT_BASE);
105+
}
106+
void Hackiebox::watchdog_stop() {
107+
// Unlock to be able to configure the registers
108+
MAP_WatchdogUnlock(WDT_BASE);
109+
110+
// Disable stalling of the watchdog timer during debug events
111+
MAP_WatchdogStallDisable(WDT_BASE);
112+
113+
// Clear the interrupt
114+
MAP_WatchdogIntClear(WDT_BASE);
115+
116+
// Unregister the interrupt
117+
MAP_WatchdogIntUnregister(WDT_BASE);
118+
}
119+

Hackiebox.h

+21-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@
55

66
#include <ThreadController.h>
77

8+
#include <hw_ints.h>
9+
#include <driverlib/wdt.h>
10+
#include <driverlib/rom_map.h>
11+
#include <driverlib/prcm.h>
12+
813
#include "BoxAccelerometer.h"
914
#include "BoxBattery.h"
1015
#include "BoxButtonEars.h"
@@ -21,9 +26,19 @@
2126

2227
class Hackiebox {
2328
public:
29+
2430
void
2531
setup(),
2632
loop();
33+
34+
bool
35+
watchdog_start(),
36+
watchdog_isFed();
37+
void
38+
watchdog_stop(),
39+
watchdog_feed(),
40+
watchdog_unfeed();
41+
2742

2843
BoxAccelerometer boxAccel;
2944
BoxBattery boxBattery;
@@ -37,10 +52,14 @@ class Hackiebox {
3752

3853
LogStream logStream;
3954

40-
private:
55+
private:/*
56+
typedef void (*fAPPWDTDevCallbk)();
57+
void
58+
watchdog_handler();*/
59+
60+
bool _watchdog_fed;
4161
ThreadController _threadController;
4262
};
43-
4463
extern Hackiebox Box;
4564

4665
#endif

0 commit comments

Comments
 (0)