ils
Fork of GA-Test_copy by
Diff: Watchdog/Watchdog.cpp
- Revision:
- 0:a3b83d366423
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Watchdog/Watchdog.cpp Wed Dec 06 21:35:45 2017 +0000 @@ -0,0 +1,25 @@ +#include "Watchdog.h" + + +Watchdog::Watchdog() { +} + +// Load timeout value in watchdog timer and enable +void Watchdog::kick(float s) { + + uint32_t clk = SystemCoreClock / 3; // found by trying. TODO: exakt values + hiwdg.Instance = IWDG; + hiwdg.Init.Prescaler = IWDG_PRESCALER_16; + hiwdg.Init.Reload = s * (float)clk; + if (HAL_IWDG_Init(&hiwdg) != HAL_OK) + { + // Error Handler + } +} + +// "kick" or "feed" the dog - reset the watchdog timer +// by writing this required bit pattern +void Watchdog::kick() { + HAL_IWDG_Refresh(&hiwdg); +} +