File tree Expand file tree Collapse file tree 13 files changed +86
-20
lines changed
test-apps/test-watchdog/src Expand file tree Collapse file tree 13 files changed +86
-20
lines changed Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ add_app_subdirectory(${ROVER_APPS_DIR}/gamepad_2021)
9494add_app_subdirectory(${ROVER_APPS_DIR} /gimbal_2021)
9595add_app_subdirectory(${ROVER_APPS_DIR} /pdb_2021)
9696add_app_subdirectory(${ROVER_APPS_DIR} /science_2021)
97+ add_app_subdirectory(${ROVER_APPS_DIR} /common)
9798
9899# Include Test Apps
99100add_app_subdirectory(${TEST_APPS_DIR} /test -actuator-controller)
Original file line number Diff line number Diff line change @@ -5,11 +5,8 @@ namespace Utility {
55
66class 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
Original file line number Diff line number Diff line change 66
77namespace 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
Original file line number Diff line number Diff line change 33#include < vector>
44
55#include " Module.h"
6+ #include " WatchdogModule.h"
7+
8+ WatchdogModule arm_watchdog;
69
710std::vector<Module*> gModules = {
811 // put modules here
12+ &arm_watchdog,
913};
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+ )
Original file line number Diff line number Diff line change 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+ };
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 33#include < vector>
44
55#include " Module.h"
6+ #include " WatchdogModule.h"
7+
8+ WatchdogModule gimbal_watchdog;
69
710std::vector<Module*> gModules = {
811 // put modules here
12+ &gimbal_watchdog,
913};
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments