1 /**
2   ******************************************************************************
3   * @file    stm32l5xx_hal_iwdg.h
4   * @author  MCD Application Team
5   * @brief   Header file of IWDG HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2019 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32L5xx_HAL_IWDG_H
21 #define STM32L5xx_HAL_IWDG_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32l5xx_hal_def.h"
29 
30 /** @addtogroup STM32L5xx_HAL_Driver
31   * @{
32   */
33 
34 /** @defgroup IWDG IWDG
35   * @{
36   */
37 
38 /* Exported types ------------------------------------------------------------*/
39 /** @defgroup IWDG_Exported_Types IWDG Exported Types
40   * @{
41   */
42 
43 /**
44   * @brief  IWDG Init structure definition
45   */
46 typedef struct
47 {
48   uint32_t Prescaler;  /*!< Select the prescaler of the IWDG.
49                             This parameter can be a value of @ref IWDG_Prescaler */
50 
51   uint32_t Reload;     /*!< Specifies the IWDG down-counter reload value.
52                             This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
53 
54   uint32_t Window;     /*!< Specifies the window value to be compared to the down-counter.
55                             This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
56 
57 } IWDG_InitTypeDef;
58 
59 /**
60   * @brief  IWDG Handle Structure definition
61   */
62 typedef struct
63 {
64   IWDG_TypeDef                 *Instance;  /*!< Register base address    */
65 
66   IWDG_InitTypeDef             Init;       /*!< IWDG required parameters */
67 } IWDG_HandleTypeDef;
68 
69 
70 /**
71   * @}
72   */
73 
74 /* Exported constants --------------------------------------------------------*/
75 /** @defgroup IWDG_Exported_Constants IWDG Exported Constants
76   * @{
77   */
78 
79 /** @defgroup IWDG_Prescaler IWDG Prescaler
80   * @{
81   */
82 #define IWDG_PRESCALER_4                0x00000000u                                     /*!< IWDG prescaler set to 4   */
83 #define IWDG_PRESCALER_8                IWDG_PR_PR_0                                    /*!< IWDG prescaler set to 8   */
84 #define IWDG_PRESCALER_16               IWDG_PR_PR_1                                    /*!< IWDG prescaler set to 16  */
85 #define IWDG_PRESCALER_32               (IWDG_PR_PR_1 | IWDG_PR_PR_0)                   /*!< IWDG prescaler set to 32  */
86 #define IWDG_PRESCALER_64               IWDG_PR_PR_2                                    /*!< IWDG prescaler set to 64  */
87 #define IWDG_PRESCALER_128              (IWDG_PR_PR_2 | IWDG_PR_PR_0)                   /*!< IWDG prescaler set to 128 */
88 #define IWDG_PRESCALER_256              (IWDG_PR_PR_2 | IWDG_PR_PR_1)                   /*!< IWDG prescaler set to 256 */
89 /**
90   * @}
91   */
92 
93 /** @defgroup IWDG_Window_option IWDG Window option
94   * @{
95   */
96 #define IWDG_WINDOW_DISABLE             IWDG_WINR_WIN
97 /**
98   * @}
99   */
100 
101 /**
102   * @}
103   */
104 
105 /* Exported macros -----------------------------------------------------------*/
106 /** @defgroup IWDG_Exported_Macros IWDG Exported Macros
107   * @{
108   */
109 
110 /**
111   * @brief  Enable the IWDG peripheral.
112   * @param  __HANDLE__  IWDG handle
113   * @retval None
114   */
115 #define __HAL_IWDG_START(__HANDLE__)                WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_ENABLE)
116 
117 /**
118   * @brief  Reload IWDG counter with value defined in the reload register
119   *         (write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers disabled).
120   * @param  __HANDLE__  IWDG handle
121   * @retval None
122   */
123 #define __HAL_IWDG_RELOAD_COUNTER(__HANDLE__)       WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_RELOAD)
124 
125 /**
126   * @}
127   */
128 
129 /* Exported functions --------------------------------------------------------*/
130 /** @defgroup IWDG_Exported_Functions  IWDG Exported Functions
131   * @{
132   */
133 
134 /** @defgroup IWDG_Exported_Functions_Group1 Initialization and Start functions
135   * @{
136   */
137 /* Initialization/Start functions  ********************************************/
138 HAL_StatusTypeDef     HAL_IWDG_Init(IWDG_HandleTypeDef *hiwdg);
139 /**
140   * @}
141   */
142 
143 /** @defgroup IWDG_Exported_Functions_Group2 IO operation functions
144   * @{
145   */
146 /* I/O operation functions ****************************************************/
147 HAL_StatusTypeDef     HAL_IWDG_Refresh(IWDG_HandleTypeDef *hiwdg);
148 /**
149   * @}
150   */
151 
152 /**
153   * @}
154   */
155 
156 /* Private constants ---------------------------------------------------------*/
157 /** @defgroup IWDG_Private_Constants IWDG Private Constants
158   * @{
159   */
160 
161 /**
162   * @brief  IWDG Key Register BitMask
163   */
164 #define IWDG_KEY_RELOAD                 0x0000AAAAu  /*!< IWDG Reload Counter Enable   */
165 #define IWDG_KEY_ENABLE                 0x0000CCCCu  /*!< IWDG Peripheral Enable       */
166 #define IWDG_KEY_WRITE_ACCESS_ENABLE    0x00005555u  /*!< IWDG KR Write Access Enable  */
167 #define IWDG_KEY_WRITE_ACCESS_DISABLE   0x00000000u  /*!< IWDG KR Write Access Disable */
168 
169 /**
170   * @}
171   */
172 
173 /* Private macros ------------------------------------------------------------*/
174 /** @defgroup IWDG_Private_Macros IWDG Private Macros
175   * @{
176   */
177 
178 /**
179   * @brief  Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers.
180   * @param  __HANDLE__  IWDG handle
181   * @retval None
182   */
183 #define IWDG_ENABLE_WRITE_ACCESS(__HANDLE__)  WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_ENABLE)
184 
185 /**
186   * @brief  Disable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers.
187   * @param  __HANDLE__  IWDG handle
188   * @retval None
189   */
190 #define IWDG_DISABLE_WRITE_ACCESS(__HANDLE__) WRITE_REG((__HANDLE__)->Instance->KR, IWDG_KEY_WRITE_ACCESS_DISABLE)
191 
192 /**
193   * @brief  Check IWDG prescaler value.
194   * @param  __PRESCALER__  IWDG prescaler value
195   * @retval None
196   */
197 #define IS_IWDG_PRESCALER(__PRESCALER__)      (((__PRESCALER__) == IWDG_PRESCALER_4)  || \
198                                                ((__PRESCALER__) == IWDG_PRESCALER_8)  || \
199                                                ((__PRESCALER__) == IWDG_PRESCALER_16) || \
200                                                ((__PRESCALER__) == IWDG_PRESCALER_32) || \
201                                                ((__PRESCALER__) == IWDG_PRESCALER_64) || \
202                                                ((__PRESCALER__) == IWDG_PRESCALER_128)|| \
203                                                ((__PRESCALER__) == IWDG_PRESCALER_256))
204 
205 /**
206   * @brief  Check IWDG reload value.
207   * @param  __RELOAD__  IWDG reload value
208   * @retval None
209   */
210 #define IS_IWDG_RELOAD(__RELOAD__)            ((__RELOAD__) <= IWDG_RLR_RL)
211 
212 /**
213   * @brief  Check IWDG window value.
214   * @param  __WINDOW__  IWDG window value
215   * @retval None
216   */
217 #define IS_IWDG_WINDOW(__WINDOW__)            ((__WINDOW__) <= IWDG_WINR_WIN)
218 
219 
220 /**
221   * @}
222   */
223 
224 /**
225   * @}
226   */
227 
228 /**
229   * @}
230   */
231 
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 
237 #endif /* STM32L5xx_HAL_IWDG_H */
238