Reset the board using the cpu hal instead of the watchdog hal

Also some naming changes
pull/67/head^2
Alex Voinea 2021-07-20 13:47:36 +03:00
parent 3b46c35595
commit 56eee8dcfb
5 changed files with 17 additions and 9 deletions

View File

@ -1,4 +1,6 @@
#include "../cpu.h" #include "../cpu.h"
#include <avr/interrupt.h>
#include "../watchdog.h"
namespace hal { namespace hal {
namespace cpu { namespace cpu {
@ -6,5 +8,12 @@ namespace cpu {
void Init() { 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 CPU
} // namespace hal } // namespace hal

View File

@ -3,11 +3,11 @@
namespace hal { namespace hal {
namespace watchdog { namespace watchdog {
void ConfigureWatchDog(uint16_t period) { void Enable(uint16_t period) {
// @@TODO // @@TODO
} }
void ResetWatchDog() { void Reset() {
asm("wdr"); asm("wdr");
} }

View File

@ -12,6 +12,7 @@ namespace cpu {
/// CPU init routines (not really necessary for the AVR) /// CPU init routines (not really necessary for the AVR)
void Init(); void Init();
void Reset();
} // namespace cpu } // namespace cpu
} // namespace hal } // namespace hal

View File

@ -7,8 +7,8 @@ namespace hal {
namespace watchdog { namespace watchdog {
/// watchdog interface /// watchdog interface
void ConfigureWatchDog(uint16_t period); void Enable(uint16_t period);
void ResetWatchDog(); void Reset();
} // namespace watchdog } // namespace watchdog
} // namespace hal } // namespace hal

View File

@ -97,7 +97,7 @@ void setup() {
mt::timebase.Init(); mt::timebase.Init();
hal::watchdog::ConfigureWatchDog(8); watchdog::Enable(8000); //8s timeout
mg::globals.Init(); mg::globals.Init();
@ -294,9 +294,7 @@ void ProcessRequestMsg(const mp::RequestMsg &rq) {
break; break;
case mp::RequestMsgCodes::Reset: case mp::RequestMsgCodes::Reset:
// immediately reset the board - there is no response in this case // immediately reset the board - there is no response in this case
hal::watchdog::ConfigureWatchDog(1); // set the watchdog to the lowest possible timeout hal::cpu::Reset();
for (;;)
; // cycle indefinitely (i.e. let the watchdog reset the CPU)
break; break;
case mp::RequestMsgCodes::Version: case mp::RequestMsgCodes::Version:
ReportVersion(rq); ReportVersion(rq);
@ -370,7 +368,7 @@ void loop() {
mui::userInput.Step(); mui::userInput.Step();
currentCommand->Step(); currentCommand->Step();
hal::watchdog::ResetWatchDog(); hal::watchdog::Reset();
} }
int main() { int main() {