ils
Fork of GA-Test_copy by
Watchdog/Watchdog.cpp@0:a3b83d366423, 2017-12-06 (annotated)
- Committer:
- aungriah
- Date:
- Wed Dec 06 21:35:45 2017 +0000
- Revision:
- 0:a3b83d366423
test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
aungriah | 0:a3b83d366423 | 1 | #include "Watchdog.h" |
aungriah | 0:a3b83d366423 | 2 | |
aungriah | 0:a3b83d366423 | 3 | |
aungriah | 0:a3b83d366423 | 4 | Watchdog::Watchdog() { |
aungriah | 0:a3b83d366423 | 5 | } |
aungriah | 0:a3b83d366423 | 6 | |
aungriah | 0:a3b83d366423 | 7 | // Load timeout value in watchdog timer and enable |
aungriah | 0:a3b83d366423 | 8 | void Watchdog::kick(float s) { |
aungriah | 0:a3b83d366423 | 9 | |
aungriah | 0:a3b83d366423 | 10 | uint32_t clk = SystemCoreClock / 3; // found by trying. TODO: exakt values |
aungriah | 0:a3b83d366423 | 11 | hiwdg.Instance = IWDG; |
aungriah | 0:a3b83d366423 | 12 | hiwdg.Init.Prescaler = IWDG_PRESCALER_16; |
aungriah | 0:a3b83d366423 | 13 | hiwdg.Init.Reload = s * (float)clk; |
aungriah | 0:a3b83d366423 | 14 | if (HAL_IWDG_Init(&hiwdg) != HAL_OK) |
aungriah | 0:a3b83d366423 | 15 | { |
aungriah | 0:a3b83d366423 | 16 | // Error Handler |
aungriah | 0:a3b83d366423 | 17 | } |
aungriah | 0:a3b83d366423 | 18 | } |
aungriah | 0:a3b83d366423 | 19 | |
aungriah | 0:a3b83d366423 | 20 | // "kick" or "feed" the dog - reset the watchdog timer |
aungriah | 0:a3b83d366423 | 21 | // by writing this required bit pattern |
aungriah | 0:a3b83d366423 | 22 | void Watchdog::kick() { |
aungriah | 0:a3b83d366423 | 23 | HAL_IWDG_Refresh(&hiwdg); |
aungriah | 0:a3b83d366423 | 24 | } |
aungriah | 0:a3b83d366423 | 25 |