diff --git a/src/hal/avr/cpu.cpp b/src/hal/avr/cpu.cpp index 96d539d..110e8be 100644 --- a/src/hal/avr/cpu.cpp +++ b/src/hal/avr/cpu.cpp @@ -1,4 +1,6 @@ #include "../cpu.h" +#include +#include "../watchdog.h" namespace hal { namespace cpu { @@ -6,5 +8,12 @@ namespace cpu { void Init() { } +void Reset() { + cli(); + watchdog::Enable(0); //minimum amount of watchdog + for (;;) + ; //endless loop while waiting for the watchdog to reset +} + } // namespace CPU } // namespace hal diff --git a/src/hal/avr/watchdog.cpp b/src/hal/avr/watchdog.cpp index a707047..86f1b52 100644 --- a/src/hal/avr/watchdog.cpp +++ b/src/hal/avr/watchdog.cpp @@ -3,11 +3,11 @@ namespace hal { namespace watchdog { -void ConfigureWatchDog(uint16_t period) { +void Enable(uint16_t period) { // @@TODO } -void ResetWatchDog() { +void Reset() { asm("wdr"); } diff --git a/src/hal/cpu.h b/src/hal/cpu.h index 604c7b9..ace6a9e 100644 --- a/src/hal/cpu.h +++ b/src/hal/cpu.h @@ -12,6 +12,7 @@ namespace cpu { /// CPU init routines (not really necessary for the AVR) void Init(); +void Reset(); } // namespace cpu } // namespace hal diff --git a/src/hal/watchdog.h b/src/hal/watchdog.h index 90c3f10..c585281 100644 --- a/src/hal/watchdog.h +++ b/src/hal/watchdog.h @@ -7,8 +7,8 @@ namespace hal { namespace watchdog { /// watchdog interface -void ConfigureWatchDog(uint16_t period); -void ResetWatchDog(); +void Enable(uint16_t period); +void Reset(); } // namespace watchdog } // namespace hal diff --git a/src/main.cpp b/src/main.cpp index 08713da..c24082c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -97,7 +97,7 @@ void setup() { mt::timebase.Init(); - hal::watchdog::ConfigureWatchDog(8); + watchdog::Enable(8000); //8s timeout mg::globals.Init(); @@ -294,9 +294,7 @@ void ProcessRequestMsg(const mp::RequestMsg &rq) { break; case mp::RequestMsgCodes::Reset: // immediately reset the board - there is no response in this case - hal::watchdog::ConfigureWatchDog(1); // set the watchdog to the lowest possible timeout - for (;;) - ; // cycle indefinitely (i.e. let the watchdog reset the CPU) + hal::cpu::Reset(); break; case mp::RequestMsgCodes::Version: ReportVersion(rq); @@ -370,7 +368,7 @@ void loop() { mui::userInput.Step(); currentCommand->Step(); - hal::watchdog::ResetWatchDog(); + hal::watchdog::Reset(); } int main() {