Skip to content

Commit 27418c3

Browse files
Create watchdog module (#389)
* Watchdog module * clang fix * clang fix2 * test-watchdog * Edited WatchdogWrapper.h * Fixed pure virtual function errors * fixed namespace error * Fixed error2 * Cmake * Cmake * Cmake fix * Top-level Cmake * Changes made * clang fix * Update libs/utility/src/WatchdogWrapper.cpp Co-authored-by: Cindy Li <cindyli0213@hotmail.com> * Update test-apps/test-watchdog/src/main.cpp Co-authored-by: Cindy Li <cindyli0213@hotmail.com> * cmake * Changed periodic function name * watchdogwrapper fix Co-authored-by: Cindy Li <cindyli0213@hotmail.com>
1 parent 4b5c8d6 commit 27418c3

File tree

13 files changed

+86
-20
lines changed

13 files changed

+86
-20
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ add_app_subdirectory(${ROVER_APPS_DIR}/gamepad_2021)
9494
add_app_subdirectory(${ROVER_APPS_DIR}/gimbal_2021)
9595
add_app_subdirectory(${ROVER_APPS_DIR}/pdb_2021)
9696
add_app_subdirectory(${ROVER_APPS_DIR}/science_2021)
97+
add_app_subdirectory(${ROVER_APPS_DIR}/common)
9798

9899
# Include Test Apps
99100
add_app_subdirectory(${TEST_APPS_DIR}/test-actuator-controller)

libs/utility/include/WatchdogWrapper.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ namespace Utility {
55

66
class WatchdogWrapper {
77
public:
8-
static void startWatchdog(std::chrono::milliseconds countdown_ms = 5000ms, std::chrono::milliseconds pet_ms = 1000ms);
9-
static void logResetReason();
10-
11-
private:
12-
static void petWatchdog(std::chrono::milliseconds *pet_ms);
13-
static Thread pet_thread;
8+
static void startWatchdog(std::chrono::milliseconds countdown_ms);
9+
static void logResetReason(void);
10+
static void petWatchdog(void);
1411
};
1512
} // namespace Utility

libs/utility/src/WatchdogWrapper.cpp

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,13 @@
66

77
namespace Utility {
88

9-
Thread WatchdogWrapper::pet_thread;
10-
11-
void WatchdogWrapper::startWatchdog(std::chrono::milliseconds countdown_ms /*= 5000ms*/,
12-
std::chrono::milliseconds pet_ms /*= 1000ms*/) {
9+
void WatchdogWrapper::startWatchdog(std::chrono::milliseconds countdown_ms) {
1310
uint32_t countdown_uint32 = countdown_ms.count();
1411
Watchdog &watchdog = Watchdog::get_instance();
1512
watchdog.start(countdown_uint32);
16-
pet_thread.start(callback(WatchdogWrapper::petWatchdog, &pet_ms));
1713
}
1814

19-
void WatchdogWrapper::logResetReason() {
15+
void WatchdogWrapper::logResetReason(void) {
2016
const reset_reason_t reason = ResetReason::get();
2117
if (reason == RESET_REASON_WATCHDOG) {
2218
time_t seconds = time(NULL);
@@ -26,10 +22,7 @@ void WatchdogWrapper::logResetReason() {
2622
}
2723
}
2824

29-
void WatchdogWrapper::petWatchdog(std::chrono::milliseconds *pet_ms) {
30-
while (1) {
31-
Watchdog::get_instance().kick();
32-
ThisThread::sleep_for(*pet_ms);
33-
}
25+
void WatchdogWrapper::petWatchdog(void) {
26+
Watchdog::get_instance().kick();
3427
}
35-
} // namespace Utility
28+
} // namespace Utility

rover-apps/arm/include/AppConfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
#include <vector>
44

55
#include "Module.h"
6+
#include "WatchdogModule.h"
7+
8+
WatchdogModule arm_watchdog;
69

710
std::vector<Module*> gModules = {
811
// put modules here
12+
&arm_watchdog,
913
};

rover-apps/arm_2021/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ target_link_libraries(arm
2828
CANMsg
2929
#Sensor
3030
CurrentSensor
31+
#common-modules
32+
WatchdogModule
3133
#Other
3234
uwrt-mars-rover-hw-bridge
3335
Logger

rover-apps/common/CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_library(WatchdogModule STATIC)
2+
target_sources(WatchdogModule PRIVATE src/WatchdogModule.cpp)
3+
target_include_directories(WatchdogModule PUBLIC include)
4+
target_link_libraries(WatchdogModule
5+
PRIVATE
6+
WatchdogWrapper
7+
mbed-os
8+
)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include "Module.h"
4+
#include "mbed.h"
5+
6+
class WatchdogModule final : public Module {
7+
public:
8+
/* Initiates the watchdog with a countdown
9+
* @param countdown - max timeout of the watchdog
10+
* */
11+
WatchdogModule();
12+
13+
/* Periodic function to kick the watchdog and restart its timer every 1s
14+
* */
15+
void periodic_1s(void) override;
16+
17+
void periodic_10s(void) override {}
18+
void periodic_100ms(void) override {}
19+
void periodic_10ms(void) override {}
20+
void periodic_1ms(void) override {}
21+
22+
private:
23+
static const std::chrono::milliseconds WATCHDOG_DEFAULT_COUNTDOWN;
24+
};
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "WatchdogModule.h"
2+
3+
#include "Module.h"
4+
#include "WatchdogWrapper.h"
5+
#include "mbed.h"
6+
7+
const std::chrono::milliseconds WatchdogModule::WATCHDOG_DEFAULT_COUNTDOWN = 5000ms;
8+
9+
WatchdogModule::WatchdogModule() {
10+
Utility::WatchdogWrapper::logResetReason();
11+
Utility::WatchdogWrapper::startWatchdog(WATCHDOG_DEFAULT_COUNTDOWN);
12+
}
13+
14+
void WatchdogModule::periodic_1s(void) {
15+
Utility::WatchdogWrapper::petWatchdog();
16+
}

rover-apps/gimbal/include/AppConfig.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
#include <vector>
44

55
#include "Module.h"
6+
#include "WatchdogModule.h"
7+
8+
WatchdogModule gimbal_watchdog;
69

710
std::vector<Module*> gModules = {
811
// put modules here
12+
&gimbal_watchdog,
913
};

rover-apps/gimbal_2021/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ target_link_libraries(gimbal
2626
CANMsg
2727
#Sensor
2828
CurrentSensor
29+
#common-modules
30+
WatchdogModule
2931
#Other
3032
Logger
3133
uwrt-mars-rover-hw-bridge

0 commit comments

Comments
 (0)