From d1fd815e0c3473b31df1cdf6690e7963083283ce Mon Sep 17 00:00:00 2001 From: Alex Voinea Date: Mon, 20 Sep 2021 16:36:44 +0200 Subject: [PATCH] Quick and dirty workaround --- src/hal/watchdog.h | 23 ++++++++++++++++------- src/main.cpp | 2 +- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/hal/watchdog.h b/src/hal/watchdog.h index f737cb7..31edb81 100644 --- a/src/hal/watchdog.h +++ b/src/hal/watchdog.h @@ -23,15 +23,24 @@ struct configuration { uint16_t reload; public: - static constexpr configuration compute(float timeout) { + static constexpr configuration compute(uint16_t timeout) { + // uint8_t prescalerBits = 0; + // uint32_t ticks = timeout * F_WDT / (basePrescaler * (1 << prescalerBits)); + // while ((ticks >= (1 << reloadBits)) && (prescalerBits < maxPrescaler)) { + // prescalerBits++; + // ticks >>= 1; + // } + // if ((prescalerBits == 0) && (ticks == 0)) + // ticks = 1; //1 tick is minimum + // configuration config = { prescalerBits, static_cast(ticks - 1) }; + // return config; uint8_t prescalerBits = 0; - uint32_t ticks = timeout * F_WDT / (basePrescaler * (1 << prescalerBits)); - while ((ticks >= (1 << reloadBits)) && (prescalerBits < maxPrescaler)) { - prescalerBits++; - ticks >>= 1; + uint32_t ticks = 1; + switch (timeout) { + case 8000: + prescalerBits = 9; } - if ((prescalerBits == 0) && (ticks == 0)) - ticks = 1; //1 tick is minimum + configuration config = { prescalerBits, static_cast(ticks - 1) }; return config; } diff --git a/src/main.cpp b/src/main.cpp index e06a034..2544f4d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -97,7 +97,7 @@ void setup() { mt::timebase.Init(); - watchdog::Enable(watchdog::configuration::compute(8)); //set 8s timeout + watchdog::Enable(watchdog::configuration::compute(8000)); //set 8s timeout mg::globals.Init();