Firmware SDK
twr_watchdog.c
1 #include <twr_watchdog.h>
2 
3 #include <stm32l0xx_hal.h>
4 #include <stm32l083xx.h>
5 
6 #ifdef TWR_WATCHDOG_ENABLED
7 static IWDG_HandleTypeDef _twr_watchdog_hiwdg;
8 
9 static const uint32_t _twr_watchdog_prescaler[] =
10 {
11  IWDG_PRESCALER_256,
12  IWDG_PRESCALER_128,
13  IWDG_PRESCALER_64,
14  IWDG_PRESCALER_32,
15  IWDG_PRESCALER_16,
16  IWDG_PRESCALER_8,
17  IWDG_PRESCALER_4
18 };
19 #endif
20 
21 void twr_watchdog_init(twr_watchdog_time_t twr_watchdog_time)
22 {
23  (void) twr_watchdog_time;
24 #ifdef TWR_WATCHDOG_ENABLED
25  // T = (IWDG_PRESCALER * 4096) / (38*10^3)
26  _twr_watchdog_hiwdg.Instance = IWDG;
27  _twr_watchdog_hiwdg.Init.Reload = 0x0FFF;
28  _twr_watchdog_hiwdg.Init.Window = 0x0FFF;
29  _twr_watchdog_hiwdg.Init.Prescaler = _twr_watchdog_prescaler[twr_watchdog_time];
30  HAL_IWDG_Init(&_twr_watchdog_hiwdg);
31 #endif
32 }
33 
34 void twr_watchdog_refresh()
35 {
36 #ifdef TWR_WATCHDOG_ENABLED
37  HAL_IWDG_Refresh(&_twr_watchdog_hiwdg);
38 #endif
39 }
40