1 /**
2   ******************************************************************************
3   * @file    stm32wbaxx_ll_iwdg.h
4   * @author  MCD Application Team
5   * @brief   Header file of IWDG LL module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2022 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 STM32WBAxx_LL_IWDG_H
21 #define STM32WBAxx_LL_IWDG_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 /* Includes ------------------------------------------------------------------*/
28 #include "stm32wbaxx.h"
29 
30 /** @addtogroup STM32WBAxx_LL_Driver
31   * @{
32   */
33 
34 #if defined(IWDG)
35 
36 /** @defgroup IWDG_LL IWDG
37   * @{
38   */
39 
40 /* Private types -------------------------------------------------------------*/
41 /* Private variables ---------------------------------------------------------*/
42 
43 /* Private constants ---------------------------------------------------------*/
44 /** @defgroup IWDG_LL_Private_Constants IWDG Private Constants
45   * @{
46   */
47 #define LL_IWDG_KEY_RELOAD                 0x0000AAAAU               /*!< IWDG Reload Counter Enable   */
48 #define LL_IWDG_KEY_ENABLE                 0x0000CCCCU               /*!< IWDG Peripheral Enable       */
49 #define LL_IWDG_KEY_WR_ACCESS_ENABLE       0x00005555U               /*!< IWDG KR Write Access Enable  */
50 #define LL_IWDG_KEY_WR_ACCESS_DISABLE      0x00000000U               /*!< IWDG KR Write Access Disable */
51 /**
52   * @}
53   */
54 
55 /* Private macros ------------------------------------------------------------*/
56 
57 /* Exported types ------------------------------------------------------------*/
58 /* Exported constants --------------------------------------------------------*/
59 /** @defgroup IWDG_LL_Exported_Constants IWDG Exported Constants
60   * @{
61   */
62 
63 /** @defgroup IWDG_LL_EC_GET_FLAG Get Flags Defines
64   * @brief    Flags defines which can be used with LL_IWDG_ReadReg function
65   * @{
66   */
67 #define LL_IWDG_SR_PVU                     IWDG_SR_PVU                           /*!< Watchdog prescaler value update */
68 #define LL_IWDG_SR_RVU                     IWDG_SR_RVU                           /*!< Watchdog counter reload value update */
69 #define LL_IWDG_SR_WVU                     IWDG_SR_WVU                           /*!< Watchdog counter window value update */
70 /**
71   * @}
72   */
73 
74 /** @defgroup IWDG_LL_EC_PRESCALER  Prescaler Divider
75   * @{
76   */
77 #define LL_IWDG_PRESCALER_4                0x00000000U                                   /*!< Divider by 4    */
78 #define LL_IWDG_PRESCALER_8                (IWDG_PR_PR_0)                                /*!< Divider by 8    */
79 #define LL_IWDG_PRESCALER_16               (IWDG_PR_PR_1)                                /*!< Divider by 16   */
80 #define LL_IWDG_PRESCALER_32               (IWDG_PR_PR_1 | IWDG_PR_PR_0)                 /*!< Divider by 32   */
81 #define LL_IWDG_PRESCALER_64               (IWDG_PR_PR_2)                                /*!< Divider by 64   */
82 #define LL_IWDG_PRESCALER_128              (IWDG_PR_PR_2 | IWDG_PR_PR_0)                 /*!< Divider by 128  */
83 #define LL_IWDG_PRESCALER_256              (IWDG_PR_PR_2 | IWDG_PR_PR_1)                 /*!< Divider by 256  */
84 #define LL_IWDG_PRESCALER_512              (IWDG_PR_PR_2 | IWDG_PR_PR_1 | IWDG_PR_PR_0)  /*!< Divider by 512  */
85 #define LL_IWDG_PRESCALER_1024             IWDG_PR_PR_3                                  /*!< Divider by 1024 */
86 /**
87   * @}
88   */
89 
90 /**
91   * @}
92   */
93 
94 /* Exported macro ------------------------------------------------------------*/
95 /** @defgroup IWDG_LL_Exported_Macros IWDG Exported Macros
96   * @{
97   */
98 
99 /** @defgroup IWDG_LL_EM_WRITE_READ Common Write and read registers Macros
100   * @{
101   */
102 
103 /**
104   * @brief  Write a value in IWDG register
105   * @param  __INSTANCE__ IWDG Instance
106   * @param  __REG__ Register to be written
107   * @param  __VALUE__ Value to be written in the register
108   * @retval None
109   */
110 #define LL_IWDG_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__))
111 
112 /**
113   * @brief  Read a value in IWDG register
114   * @param  __INSTANCE__ IWDG Instance
115   * @param  __REG__ Register to be read
116   * @retval Register value
117   */
118 #define LL_IWDG_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__)
119 /**
120   * @}
121   */
122 
123 /**
124   * @}
125   */
126 
127 
128 /* Exported functions --------------------------------------------------------*/
129 /** @defgroup IWDG_LL_Exported_Functions IWDG Exported Functions
130   * @{
131   */
132 /** @defgroup IWDG_LL_EF_Configuration Configuration
133   * @{
134   */
135 
136 /**
137   * @brief  Start the Independent Watchdog
138   * @note   Except if the hardware watchdog option is selected
139   * @rmtoll KR           KEY           LL_IWDG_Enable
140   * @param  IWDGx IWDG Instance
141   * @retval None
142   */
LL_IWDG_Enable(IWDG_TypeDef * IWDGx)143 __STATIC_INLINE void LL_IWDG_Enable(IWDG_TypeDef *IWDGx)
144 {
145   WRITE_REG(IWDGx->KR, LL_IWDG_KEY_ENABLE);
146 }
147 
148 /**
149   * @brief  Reloads IWDG counter with value defined in the reload register
150   * @rmtoll KR           KEY           LL_IWDG_ReloadCounter
151   * @param  IWDGx IWDG Instance
152   * @retval None
153   */
LL_IWDG_ReloadCounter(IWDG_TypeDef * IWDGx)154 __STATIC_INLINE void LL_IWDG_ReloadCounter(IWDG_TypeDef *IWDGx)
155 {
156   WRITE_REG(IWDGx->KR, LL_IWDG_KEY_RELOAD);
157 }
158 
159 /**
160   * @brief  Enable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers
161   * @rmtoll KR           KEY           LL_IWDG_EnableWriteAccess
162   * @param  IWDGx IWDG Instance
163   * @retval None
164   */
LL_IWDG_EnableWriteAccess(IWDG_TypeDef * IWDGx)165 __STATIC_INLINE void LL_IWDG_EnableWriteAccess(IWDG_TypeDef *IWDGx)
166 {
167   WRITE_REG(IWDGx->KR, LL_IWDG_KEY_WR_ACCESS_ENABLE);
168 }
169 
170 /**
171   * @brief  Disable write access to IWDG_PR, IWDG_RLR and IWDG_WINR registers
172   * @rmtoll KR           KEY           LL_IWDG_DisableWriteAccess
173   * @param  IWDGx IWDG Instance
174   * @retval None
175   */
LL_IWDG_DisableWriteAccess(IWDG_TypeDef * IWDGx)176 __STATIC_INLINE void LL_IWDG_DisableWriteAccess(IWDG_TypeDef *IWDGx)
177 {
178   WRITE_REG(IWDGx->KR, LL_IWDG_KEY_WR_ACCESS_DISABLE);
179 }
180 
181 /**
182   * @brief  Select the prescaler of the IWDG
183   * @rmtoll PR           PR            LL_IWDG_SetPrescaler
184   * @param  IWDGx IWDG Instance
185   * @param  Prescaler This parameter can be one of the following values:
186   *         @arg @ref LL_IWDG_PRESCALER_4
187   *         @arg @ref LL_IWDG_PRESCALER_8
188   *         @arg @ref LL_IWDG_PRESCALER_16
189   *         @arg @ref LL_IWDG_PRESCALER_32
190   *         @arg @ref LL_IWDG_PRESCALER_64
191   *         @arg @ref LL_IWDG_PRESCALER_128
192   *         @arg @ref LL_IWDG_PRESCALER_256
193   *         @arg @ref LL_IWDG_PRESCALER_512
194   *         @arg @ref LL_IWDG_PRESCALER_1024
195   * @retval None
196   */
LL_IWDG_SetPrescaler(IWDG_TypeDef * IWDGx,uint32_t Prescaler)197 __STATIC_INLINE void LL_IWDG_SetPrescaler(IWDG_TypeDef *IWDGx, uint32_t Prescaler)
198 {
199   WRITE_REG(IWDGx->PR, IWDG_PR_PR & Prescaler);
200 }
201 
202 /**
203   * @brief  Get the selected prescaler of the IWDG
204   * @rmtoll PR           PR            LL_IWDG_GetPrescaler
205   * @param  IWDGx IWDG Instance
206   * @retval Returned value can be one of the following values:
207   *         @arg @ref LL_IWDG_PRESCALER_4
208   *         @arg @ref LL_IWDG_PRESCALER_8
209   *         @arg @ref LL_IWDG_PRESCALER_16
210   *         @arg @ref LL_IWDG_PRESCALER_32
211   *         @arg @ref LL_IWDG_PRESCALER_64
212   *         @arg @ref LL_IWDG_PRESCALER_128
213   *         @arg @ref LL_IWDG_PRESCALER_256
214   *         @arg @ref LL_IWDG_PRESCALER_512
215   *         @arg @ref LL_IWDG_PRESCALER_1024
216   */
LL_IWDG_GetPrescaler(const IWDG_TypeDef * IWDGx)217 __STATIC_INLINE uint32_t LL_IWDG_GetPrescaler(const IWDG_TypeDef *IWDGx)
218 {
219   return (READ_REG(IWDGx->PR));
220 }
221 
222 /**
223   * @brief  Specify the IWDG down-counter reload value
224   * @rmtoll RLR          RL            LL_IWDG_SetReloadCounter
225   * @param  IWDGx IWDG Instance
226   * @param  Counter Value between Min_Data=0 and Max_Data=0x0FFF
227   * @retval None
228   */
LL_IWDG_SetReloadCounter(IWDG_TypeDef * IWDGx,uint32_t Counter)229 __STATIC_INLINE void LL_IWDG_SetReloadCounter(IWDG_TypeDef *IWDGx, uint32_t Counter)
230 {
231   WRITE_REG(IWDGx->RLR, IWDG_RLR_RL & Counter);
232 }
233 
234 /**
235   * @brief  Get the specified IWDG down-counter reload value
236   * @rmtoll RLR          RL            LL_IWDG_GetReloadCounter
237   * @param  IWDGx IWDG Instance
238   * @retval Value between Min_Data=0 and Max_Data=0x0FFF
239   */
LL_IWDG_GetReloadCounter(const IWDG_TypeDef * IWDGx)240 __STATIC_INLINE uint32_t LL_IWDG_GetReloadCounter(const IWDG_TypeDef *IWDGx)
241 {
242   return (READ_REG(IWDGx->RLR));
243 }
244 
245 /**
246   * @brief  Specify high limit of the window value to be compared to the down-counter.
247   * @rmtoll WINR         WIN           LL_IWDG_SetWindow
248   * @param  IWDGx IWDG Instance
249   * @param  Window Value between Min_Data=0 and Max_Data=0x0FFF
250   * @retval None
251   */
LL_IWDG_SetWindow(IWDG_TypeDef * IWDGx,uint32_t Window)252 __STATIC_INLINE void LL_IWDG_SetWindow(IWDG_TypeDef *IWDGx, uint32_t Window)
253 {
254   WRITE_REG(IWDGx->WINR, IWDG_WINR_WIN & Window);
255 }
256 
257 /**
258   * @brief  Get the high limit of the window value specified.
259   * @rmtoll WINR         WIN           LL_IWDG_GetWindow
260   * @param  IWDGx IWDG Instance
261   * @retval Value between Min_Data=0 and Max_Data=0x0FFF
262   */
LL_IWDG_GetWindow(const IWDG_TypeDef * IWDGx)263 __STATIC_INLINE uint32_t LL_IWDG_GetWindow(const IWDG_TypeDef *IWDGx)
264 {
265   return (READ_REG(IWDGx->WINR));
266 }
267 
268 /**
269   * @}
270   */
271 
272 /** @defgroup IWDG_LL_EF_IT_Management IT_Management
273   * @{
274   */
275 
276 /**
277   * @brief  Specify comparator value that will be used to trig Early Wakeup interrupt
278   * @rmtoll EWCR         EWIT          LL_IWDG_SetEwiTime
279   * @param  IWDGx IWDG Instance
280   * @param  Time Value between Min_Data=0 and Max_Data=0x0FFF
281   * @retval None
282   */
LL_IWDG_SetEwiTime(IWDG_TypeDef * IWDGx,uint32_t Time)283 __STATIC_INLINE void LL_IWDG_SetEwiTime(IWDG_TypeDef *IWDGx, uint32_t Time)
284 {
285   MODIFY_REG(IWDGx->EWCR, IWDG_EWCR_EWIT, Time);
286 }
287 
288 /**
289   * @brief  Get the Early Wakeup interrupt comparator value
290   * @rmtoll EWCR         EWIT          LL_IWDG_GetEwiTime
291   * @param  IWDGx IWDG Instance
292   * @retval Value between Min_Data=0 and Max_Data=0x0FFF
293   */
LL_IWDG_GetEwiTime(const IWDG_TypeDef * IWDGx)294 __STATIC_INLINE uint32_t LL_IWDG_GetEwiTime(const IWDG_TypeDef *IWDGx)
295 {
296   return (READ_BIT(IWDGx->EWCR, IWDG_EWCR_EWIT));
297 }
298 
299 /**
300   * @brief  Enable Early wakeup interrupt
301   * @rmtoll EWCR         EWIE          LL_IWDG_EnableIT_EWI
302   * @param  IWDGx IWDG Instance
303   * @retval None
304   */
LL_IWDG_EnableIT_EWI(IWDG_TypeDef * IWDGx)305 __STATIC_INLINE void LL_IWDG_EnableIT_EWI(IWDG_TypeDef *IWDGx)
306 {
307   SET_BIT(IWDGx->EWCR, IWDG_EWCR_EWIE);
308 }
309 
310 /**
311   * @brief  Disable Early wakeup interrupt
312   * @rmtoll EWCR         EWIE          LL_IWDG_DisableIT_EWI
313   * @param  IWDGx IWDG Instance
314   * @retval None
315   */
LL_IWDG_DisableIT_EWI(IWDG_TypeDef * IWDGx)316 __STATIC_INLINE void LL_IWDG_DisableIT_EWI(IWDG_TypeDef *IWDGx)
317 {
318   CLEAR_BIT(IWDGx->EWCR, IWDG_EWCR_EWIE);
319 }
320 
321 /**
322   * @brief  Indicates whether Early wakeup interrupt is enable
323   * @rmtoll EWCR         EWIE          LL_IWDG_IsEnabledIT_EWI
324   * @param  IWDGx IWDG Instance
325   * @retval None
326   */
LL_IWDG_IsEnabledIT_EWI(const IWDG_TypeDef * IWDGx)327 __STATIC_INLINE uint32_t LL_IWDG_IsEnabledIT_EWI(const IWDG_TypeDef *IWDGx)
328 {
329   return ((READ_BIT(IWDGx->EWCR, IWDG_EWCR_EWIE) == (IWDG_EWCR_EWIE)) ? 1UL : 0UL);
330 }
331 
332 /**
333   * @}
334   */
335 
336 /** @defgroup IWDG_LL_EF_FLAG_Management FLAG_Management
337   * @{
338   */
339 
340 /**
341   * @brief  Check if flag Prescaler Value Update is set or not
342   * @rmtoll SR           PVU           LL_IWDG_IsActiveFlag_PVU
343   * @param  IWDGx IWDG Instance
344   * @retval State of bit (1 or 0).
345   */
LL_IWDG_IsActiveFlag_PVU(const IWDG_TypeDef * IWDGx)346 __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_PVU(const IWDG_TypeDef *IWDGx)
347 {
348   return ((READ_BIT(IWDGx->SR, IWDG_SR_PVU) == (IWDG_SR_PVU)) ? 1UL : 0UL);
349 }
350 
351 /**
352   * @brief  Check if flag Reload Value Update is set or not
353   * @rmtoll SR           RVU           LL_IWDG_IsActiveFlag_RVU
354   * @param  IWDGx IWDG Instance
355   * @retval State of bit (1 or 0).
356   */
LL_IWDG_IsActiveFlag_RVU(const IWDG_TypeDef * IWDGx)357 __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_RVU(const IWDG_TypeDef *IWDGx)
358 {
359   return ((READ_BIT(IWDGx->SR, IWDG_SR_RVU) == (IWDG_SR_RVU)) ? 1UL : 0UL);
360 }
361 
362 /**
363   * @brief  Check if flag Window Value Update is set or not
364   * @rmtoll SR           WVU           LL_IWDG_IsActiveFlag_WVU
365   * @param  IWDGx IWDG Instance
366   * @retval State of bit (1 or 0).
367   */
LL_IWDG_IsActiveFlag_WVU(const IWDG_TypeDef * IWDGx)368 __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_WVU(const IWDG_TypeDef *IWDGx)
369 {
370   return ((READ_BIT(IWDGx->SR, IWDG_SR_WVU) == (IWDG_SR_WVU)) ? 1UL : 0UL);
371 }
372 
373 /**
374   * @brief  Check if flag EWI Value Update is set or not
375   * @rmtoll SR           EVU           LL_IWDG_IsActiveFlag_EWU
376   * @param  IWDGx IWDG Instance
377   * @retval State of bit (1 or 0).
378   */
LL_IWDG_IsActiveFlag_EWU(const IWDG_TypeDef * IWDGx)379 __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_EWU(const IWDG_TypeDef *IWDGx)
380 {
381   return ((READ_BIT(IWDGx->SR, IWDG_SR_EWU) == (IWDG_SR_EWU)) ? 1UL : 0UL);
382 }
383 
384 /**
385   * @brief  Check if all flags Prescaler, Reload, Window & Early Interrupt Value Update are reset or not
386   * @rmtoll SR           PVU           LL_IWDG_IsReady\n
387   *         SR           RVU           LL_IWDG_IsReady\n
388   *         SR           WVU           LL_IWDG_IsReady\n
389   *         SR           EWU           LL_IWDG_IsReady
390   * @param  IWDGx IWDG Instance
391   * @retval State of bits (1 or 0).
392   */
LL_IWDG_IsReady(const IWDG_TypeDef * IWDGx)393 __STATIC_INLINE uint32_t LL_IWDG_IsReady(const IWDG_TypeDef *IWDGx)
394 {
395   return ((READ_BIT(IWDGx->SR, IWDG_SR_PVU | IWDG_SR_RVU | IWDG_SR_WVU | IWDG_SR_EWU) == 0U) ? 1UL : 0UL);
396 }
397 
398 /**
399   * @brief  Check if IWDG has been started or not
400   * @rmtoll SR           ONF           LL_IWDG_IsActiveFlag_ONF
401   * @param  IWDGx IWDG Instance
402   * @retval State of bit (1 or 0).
403   */
LL_IWDG_IsActiveFlag_ONF(const IWDG_TypeDef * IWDGx)404 __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_ONF(const IWDG_TypeDef *IWDGx)
405 {
406   return ((READ_BIT(IWDGx->SR, IWDG_SR_ONF) == (IWDG_SR_ONF)) ? 1UL : 0UL);
407 }
408 
409 /**
410   * @brief  Check if Early Wakeup interrupt flag is set or not
411   * @rmtoll SR           EWIF          LL_IWDG_IsActiveFlag_EWIF
412   * @param  IWDGx IWDG Instance
413   * @retval State of bit (1 or 0).
414   */
LL_IWDG_IsActiveFlag_EWIF(const IWDG_TypeDef * IWDGx)415 __STATIC_INLINE uint32_t LL_IWDG_IsActiveFlag_EWIF(const IWDG_TypeDef *IWDGx)
416 {
417   return ((READ_BIT(IWDGx->SR, IWDG_SR_EWIF) == (IWDG_SR_EWIF)) ? 1UL : 0UL);
418 }
419 
420 /**
421   * @brief  Clear the Early Wakeup interrupt flag
422   * @rmtoll EWCR         EWIC          LL_IWDG_ClearFlag_EWIF
423   * @param  IWDGx IWDG Instance
424   * @retval None
425   */
LL_IWDG_ClearFlag_EWIF(IWDG_TypeDef * IWDGx)426 __STATIC_INLINE void LL_IWDG_ClearFlag_EWIF(IWDG_TypeDef *IWDGx)
427 {
428   SET_BIT(IWDGx->EWCR, IWDG_EWCR_EWIC);
429 }
430 
431 /**
432   * @}
433   */
434 
435 /**
436   * @}
437   */
438 
439 /**
440   * @}
441   */
442 
443 #endif /* IWDG */
444 
445 /**
446   * @}
447   */
448 
449 #ifdef __cplusplus
450 }
451 #endif
452 
453 #endif /* STM32WBAxx_LL_IWDG_H */
454