Firmware SDK
 All Data Structures Functions Variables Typedefs Enumerations Enumerator Groups Pages
bc_watchdog.c
1 #include <bc_watchdog.h>
2 
3 #include <stm32l0xx_hal.h>
4 #include <stm32l083xx.h>
5 
6 #ifdef BC_WATCHDOG_ENABLED
7 static IWDG_HandleTypeDef _bc_watchdog_hiwdg;
8 
9 static const uint32_t _bc_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 bc_watchdog_init(bc_watchdog_time_t bc_watchdog_time)
22 {
23  (void) bc_watchdog_time;
24 #ifdef BC_WATCHDOG_ENABLED
25  // T = (IWDG_PRESCALER * 4096) / (38*10^3)
26  _bc_watchdog_hiwdg.Instance = IWDG;
27  _bc_watchdog_hiwdg.Init.Reload = 0x0FFF;
28  _bc_watchdog_hiwdg.Init.Window = 0x0FFF;
29  _bc_watchdog_hiwdg.Init.Prescaler = _bc_watchdog_prescaler[bc_watchdog_time];
30  HAL_IWDG_Init(&_bc_watchdog_hiwdg);
31 #endif
32 }
33 
34 void bc_watchdog_refresh()
35 {
36 #ifdef BC_WATCHDOG_ENABLED
37  HAL_IWDG_Refresh(&_bc_watchdog_hiwdg);
38 #endif
39 }
40