1 /**
2   ******************************************************************************
3   * @file    tae32f53xx_ll_iwdg.h
4   * @author  MCD Application Team
5   * @brief   Header file of IWDG LL module.
6   *
7   ******************************************************************************
8   * @attention
9   *
10   * <h2><center>&copy; Copyright (c) 2020 Tai-Action.
11   * All rights reserved.</center></h2>
12   *
13   * This software is licensed by Tai-Action under BSD 3-Clause license,
14   * the "License"; You may not use this file except in compliance with the
15   * License. You may obtain a copy of the License at:
16   *                        opensource.org/licenses/BSD-3-Clause
17   *
18   ******************************************************************************
19   */
20 
21 /* Define to prevent recursive inclusion -------------------------------------*/
22 #ifndef _TAE32F53XX_LL_IWDG_H_
23 #define _TAE32F53XX_LL_IWDG_H_
24 
25 #ifdef __cplusplus
26 extern "C" {
27 #endif /* __cplusplus */
28 
29 /* Includes ------------------------------------------------------------------*/
30 #include "tae32f53xx_ll_def.h"
31 
32 
33 /** @addtogroup TAE32F53xx_LL_Driver
34   * @{
35   */
36 
37 /** @addtogroup IWDG_LL
38   * @{
39   */
40 
41 
42 /* Exported types ------------------------------------------------------------*/
43 /** @defgroup IWDG_LL_Exported_Types IWDG LL Exported Types
44   * @brief    IWDG LL Exported Types
45   * @{
46   */
47 
48 /**
49   * @brief IWDG Prescaler enumeration
50   */
51 typedef enum {
52     IWDG_PRESCALER_4    = IWDG_PSCR_PSC_0,             /*!< IWDG prescaler set to 4   */
53     IWDG_PRESCALER_8    = IWDG_PSCR_PSC_1,             /*!< IWDG prescaler set to 8   */
54     IWDG_PRESCALER_16   = IWDG_PSCR_PSC_2,             /*!< IWDG prescaler set to 16  */
55     IWDG_PRESCALER_32   = IWDG_PSCR_PSC_3,             /*!< IWDG prescaler set to 32  */
56     IWDG_PRESCALER_64   = IWDG_PSCR_PSC_4,             /*!< IWDG prescaler set to 64  */
57     IWDG_PRESCALER_128  = IWDG_PSCR_PSC_5,             /*!< IWDG prescaler set to 128 */
58     IWDG_PRESCALER_256  = IWDG_PSCR_PSC_6,             /*!< IWDG prescaler set to 256 */
59     IWDG_PRESCALER_512  = IWDG_PSCR_PSC_7,             /*!< IWDG prescaler set to 512 */
60 } IWDG_PreScalerETypeDef;
61 
62 
63 /**
64     @brief IWDG Mode enumeration
65   */
66 typedef enum {
67     IWDG_MODE_RESET     = IWDG_CR_MODE_RESET,          /*!< IWDG Reset after timeout               */
68     IWDG_MODE_INTERRUPT = IWDG_CR_MODE_INTERRUPT,      /*!< IWDG Trigger a interrupt after timeout */
69 } IWDG_ModeETypeDef;
70 
71 
72 /**
73   * @brief IWDG Init structure definition
74   */
75 typedef struct __IWDG_InitTypeDef {
76     IWDG_PreScalerETypeDef Prescaler; /*!< Select the prescaler of the IWDG. */
77     uint32_t Reload_val;              /*!< Specifies the IWDG down-counter reload value.
78                                          This parameter must be a number between Min_Data = 0 and Max_Data = 0x0FFF */
79     IWDG_ModeETypeDef Mode;           /*!< Specifies the IWDG bahavior after timeout.*/
80 } IWDG_InitTypeDef;
81 
82 /**
83   * @}
84   */
85 
86 
87 /* Exported constants --------------------------------------------------------*/
88 /** @defgroup IWDG_LL_Exported_Constants IWDG LL Exported Constants
89   * @brief    IWDG LL Exported Constants
90   * @{
91   */
92 
93 /** @defgroup IWDG_Interrupt_definition IWDG interrupt Definition
94   * @{
95   */
96 #define IWDG_IT_TOIE                    IWDG_CR_TOIE            /*!< IWDG Timeout Interrupte Enable */
97 /**
98   * @}
99   */
100 
101 /** @defgroup IWDG_Flag_definition IWDG Flag Definition
102   * @{
103   */
104 #define IWDG_FLAG_PSCUPD                IWDG_SR_PSCUPD          /*!< IWDG Prescaler Update flag     */
105 #define IWDG_FLAG_RLVUPD                IWDG_SR_RLVUPD          /*!< IWDG Reload Value Update flag  */
106 #define IWDG_FLAG_TOIF                  IWDG_SR_TOIF            /*!< IWDG Timeout Interrupt flag    */
107 /**
108   * @}
109   */
110 
111 /** @defgroup IWDG_Key_definition IWDG Key Definition
112   * @{
113   */
114 #define IWDG_KEY_RELOAD                 0x0000AAAAU             /*!< IWDG Reload Counter Enable     */
115 #define IWDG_KEY_ENABLE                 0x0000CCCCU             /*!< IWDG Peripheral Enable         */
116 #define IWDG_KEY_DISABLE                0x0000DDDDU             /*!< IWDG Peripheral Disable        */
117 #define IWDG_KEY_WRITE_ACCESS_ENABLE    0x00005003U             /*!< IWDG Write Access Enable       */
118 #define IWDG_KEY_WRITE_ACCESS_DISABLE   0x00000000U             /*!< IWDG Write Access Disable      */
119 /**
120   * @}
121   */
122 
123 
124 /**
125   * @}
126   */
127 
128 
129 /* Exported macro ------------------------------------------------------------*/
130 /** @defgroup IWDG_LL_Exported_Macros IWDG LL Exported Macros
131   * @brief    IWDG LL Exported Constants
132   * @{
133   */
134 
135 /**
136   * @brief  Enable write access to IWDG_PSCR, IWDG_RLR and IWDG_CR registers.
137   * @param  __INSTANCE__ IWDG peripheral
138   * @return None
139   */
140 #define __LL_IWDG_ENABLE_WRITE_ACCESS(__INSTANCE__)             WRITE_REG((__INSTANCE__)->KEYR, IWDG_KEY_WRITE_ACCESS_ENABLE)
141 
142 /**
143   * @brief  Disable write access to IWDG_PSCR, IWDG_RLR and IWDG_CR registers.
144   * @param  __INSTANCE__ IWDG peripheral
145   * @return None
146   */
147 #define __LL_IWDG_DISABLE_WRITE_ACCESS(__INSTANCE__)            WRITE_REG((__INSTANCE__)->KEYR, IWDG_KEY_WRITE_ACCESS_DISABLE)
148 
149 
150 /**
151   * @brief  Enable the IWDG peripheral.
152   * @param  __INSTANCE__ IWDG peripheral
153   * @return None
154   */
155 #define __LL_IWDG_START(__INSTANCE__)                           WRITE_REG((__INSTANCE__)->KEYR, IWDG_KEY_ENABLE)
156 
157 /**
158   * @brief  Disable the IWDG peripheral.
159   * @param  __INSTANCE__ IWDG peripheral
160   * @return None
161   */
162 #define __LL_IWDG_STOP(__INSTANCE__)                            WRITE_REG((__INSTANCE__)->KEYR, IWDG_KEY_DISABLE)
163 
164 /** @brief  Enable the specified IWDG interrupt.
165   * @note   __LL_IWDG_ENABLE_WRITE_ACCESS() must be called to enable write access before enable
166   *         the IWDG interrupt.
167   * @param  __INSTANCE__ IWDG peripheral
168   * @param  __INTERRUPT__ specifies the IWDG interrupt source to enable.
169   *         This parameter can be one of the following values:
170   *             @arg IWDG_IT_TOIE: Timeout interrupt flag
171   * @retrun None
172   */
173 #define __LL_IWDG_ENABLE_IT(__INSTANCE__, __INTERRUPT__)        SET_BIT((__INSTANCE__)->CR, (__INTERRUPT__))
174 
175 /** @brief  Disable the specified TIM interrupt.
176   * @note   __LL_IWDG_ENABLE_WRITE_ACCESS() must be called to enable write access before disable
177   *         the IWDG interrupt.
178   * @param  __INSTANCE__ IWDG peripheral
179   * @param  __INTERRUPT__ specifies the IWDG interrupt source to enable.
180   *         This parameter can be one of the following values:
181   *             @arg IWDG_IT_TOIE: Timeout interrupt flag
182   * @retval None
183   */
184 #define __LL_IWDG_DISABLE_IT(__INSTANCE__, __INTERRUPT__)       CLEAR_BIT((__INSTANCE__)->CR, (__INTERRUPT__))
185 
186 
187 /** @brief  Check whether the specified IWDG status or interrupt flag is set or not.
188   * @param  __INSTANCE__ IWDG peripheral
189   * @param  __FLAG__ specifies the IWDG flag to check.
190   *         This parameter can be one of the following values:
191   *             @arg IWDG_FLAG_PSCUPD: Prescaler value update flag
192   *             @arg IWDG_FLAG_RLVUPD: Reload value update flag
193   *             @arg IWDG_FLAG_TOIF: Timeout interrupt flag
194   * @return The new state of __FLAG__ (SET or RESET).
195   */
196 #define __LL_IWDG_GET_FLAG(__INSTANCE__, __FLAG__)              \
197         ((READ_BIT((__INSTANCE__)->SR, (__FLAG__)) == (__FLAG__)) ? SET : RESET)
198 
199 /**
200   * @brief  Clear the specified IWDG status or interrupt flag.
201   * @param  __INSTANCE__ IWDG peripheral
202   * @param  __FLAG__ specifies the IWDG flag to clear.
203   *         This parameter can be one of the following values:
204   *             @arg IWDG_FLAG_TOIF: Timeout interrupt flag
205   * @return None
206   */
207 #define __LL_IWDG_CLEAR_FLAG(__INSTANCE__, __FLAG__)            WRITE_REG((__INSTANCE__)->SR, (__FLAG__))
208 
209 /**
210   * @brief  Check whether the specified IWDG interrupt source is enabled or not.
211   * @param  __INSTANCE__ IWDG peripheral
212   * @param  __INTERRUPT__ specifies the IWDG interrupt source to check.
213   *         This parameter can be one of the following values:
214   *             @arg IWDG_IT_TOIE: Timeout interrupt
215   * @return The state of __INTERRUPT__ (SET or RESET).
216   */
217 #define __LL_IWDG_IT_CHECK_SOURCE(__INSTANCE__, __INTERRUPT__)  \
218         ((READ_BIT((__INSTANCE__)->CR, (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
219 
220 /**
221   * @brief  Reload IWDG counter with value defined in the reload register
222   *         (write access to IWDG_PR & IWDG_RLR registers disabled).
223   * @note   Flag RLVUPD and PSCUPD must be 0 before refreshing IWDG counter.
224   * @param  __INSTANCE__  IWDG peripheral
225   * @return None
226   */
227 #define __LL_IWDG_RELOAD_COUNTER(__INSTANCE__)                  WRITE_REG((__INSTANCE__)->KEYR, IWDG_KEY_RELOAD)
228 
229 /**
230   * @}
231   */
232 
233 
234 /* Exported functions --------------------------------------------------------*/
235 /** @addtogroup IWDG_LL_Exported_Functions
236   * @{
237   */
238 
239 /** @addtogroup IWDG_LL_Exported_Functions_Group1
240   * @{
241   */
242 LL_StatusETypeDef LL_IWDG_Init(IWDG_TypeDef *Instance, IWDG_InitTypeDef *Init);
243 LL_StatusETypeDef LL_IWDG_DeInit(IWDG_TypeDef *Instance);
244 void LL_IWDG_MspInit(IWDG_TypeDef *Instance);
245 void LL_IWDG_MspDeInit(IWDG_TypeDef *Instance);
246 /**
247   * @}
248   */
249 
250 
251 /** @addtogroup IWDG_LL_Exported_Functions_Group2
252   * @{
253   */
254 LL_StatusETypeDef LL_IWDG_Refresh(IWDG_TypeDef *Instance);
255 /**
256   * @}
257   */
258 
259 
260 /** @addtogroup IWDG_LL_Exported_Functions_Interrupt
261   * @{
262   */
263 void LL_IWDG_IRQHandler(IWDG_TypeDef *Instance);
264 void LL_IWDG_TimeOutCallBack(IWDG_TypeDef *Instance);
265 /**
266   * @}
267   */
268 
269 /**
270   * @}
271   */
272 
273 
274 /* Private types -------------------------------------------------------------*/
275 /* Private variables ---------------------------------------------------------*/
276 /* Private constants ---------------------------------------------------------*/
277 /* Private macros ------------------------------------------------------------*/
278 /** @defgroup IWDG_LL_Private_Macros IWDG LL Private Macros
279   * @brief    IWDG LL Private Macros
280   * @{
281   */
282 
283 /**
284   * @brief  Check IWDG prescaler value.
285   * @param  __PRESCALER__  IWDG prescaler value
286   * @return None
287   */
288 
289 /**
290   * @brief  Check IWDG reload value.
291   * @param  __RELOAD__  IWDG reload value
292   * @return None
293   */
294 #define IS_IWDG_RELOAD_Val(__RELOAD__)              ((__RELOAD__) <= IWDG_RLR_RLV)
295 
296 /**
297   * @}
298   */
299 
300 /* Private functions ---------------------------------------------------------*/
301 
302 
303 /**
304   * @}
305   */
306 
307 /**
308   * @}
309   */
310 
311 
312 #ifdef __cplusplus
313 }
314 #endif /* __cplusplus */
315 
316 
317 #endif /* _TAE32F53XX_LL_IWDG_H_ */
318 
319 
320 /************************* (C) COPYRIGHT Tai-Action *****END OF FILE***********/
321 
322