From 324ced6807019fee1b89fad996f8ad696c239694 Mon Sep 17 00:00:00 2001 From: "D.R.racer" Date: Tue, 20 Jul 2021 07:16:59 +0200 Subject: [PATCH] Add watchdog implementation + use it in main() --- src/hal/CMakeLists.txt | 1 + src/hal/avr/watchdog.cpp | 15 +++++++++++++++ src/hal/watchdog.h | 1 + src/main.cpp | 6 +++++- 4 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 src/hal/avr/watchdog.cpp diff --git a/src/hal/CMakeLists.txt b/src/hal/CMakeLists.txt index 77c7d99..fd0029d 100644 --- a/src/hal/CMakeLists.txt +++ b/src/hal/CMakeLists.txt @@ -8,4 +8,5 @@ target_sources( tmc2130.cpp adc.cpp avr/spi.cpp + avr/watchdog.cpp ) diff --git a/src/hal/avr/watchdog.cpp b/src/hal/avr/watchdog.cpp new file mode 100644 index 0000000..a707047 --- /dev/null +++ b/src/hal/avr/watchdog.cpp @@ -0,0 +1,15 @@ +#include "../watchdog.h" + +namespace hal { +namespace watchdog { + +void ConfigureWatchDog(uint16_t period) { + // @@TODO +} + +void ResetWatchDog() { + asm("wdr"); +} + +} // namespace watchdog +} // namespace hal diff --git a/src/hal/watchdog.h b/src/hal/watchdog.h index c57d373..90c3f10 100644 --- a/src/hal/watchdog.h +++ b/src/hal/watchdog.h @@ -1,4 +1,5 @@ #pragma once +#include namespace hal { diff --git a/src/main.cpp b/src/main.cpp index 9fedbe2..8dcbf77 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include "hal/shr16.h" #include "hal/spi.h" #include "hal/usart.h" +#include "hal/watchdog.h" #include "pins.h" #include @@ -96,6 +97,8 @@ void setup() { mt::timebase.Init(); + hal::watchdog::ConfigureWatchDog(8); + mg::globals.Init(); // watchdog init @@ -363,7 +366,8 @@ void loop() { ms::selector.Step(); mui::userInput.Step(); currentCommand->Step(); - // add a watchdog reset + + hal::watchdog::ResetWatchDog(); } int main() {