2 ******************************************************************************
3 * @file stm32f10x_iwdg.c
4 * @author MCD Application Team
7 * @brief This file provides all the IWDG firmware functions.
8 ******************************************************************************
11 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
12 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
13 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
14 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
15 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
16 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
18 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2>
19 ******************************************************************************
22 /* Includes ------------------------------------------------------------------*/
23 #include "stm32f10x_iwdg.h"
25 /** @addtogroup STM32F10x_StdPeriph_Driver
30 * @brief IWDG driver modules
34 /** @defgroup IWDG_Private_TypesDefinitions
42 /** @defgroup IWDG_Private_Defines
46 /* ---------------------- IWDG registers bit mask ----------------------------*/
48 /* KR register bit mask */
49 #define KR_KEY_Reload ((uint16_t)0xAAAA)
50 #define KR_KEY_Enable ((uint16_t)0xCCCC)
56 /** @defgroup IWDG_Private_Macros
64 /** @defgroup IWDG_Private_Variables
72 /** @defgroup IWDG_Private_FunctionPrototypes
80 /** @defgroup IWDG_Private_Functions
85 * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers.
86 * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
87 * This parameter can be one of the following values:
88 * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
89 * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
92 void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess
)
94 /* Check the parameters */
95 assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess
));
96 IWDG
->KR
= IWDG_WriteAccess
;
100 * @brief Sets IWDG Prescaler value.
101 * @param IWDG_Prescaler: specifies the IWDG Prescaler value.
102 * This parameter can be one of the following values:
103 * @arg IWDG_Prescaler_4: IWDG prescaler set to 4
104 * @arg IWDG_Prescaler_8: IWDG prescaler set to 8
105 * @arg IWDG_Prescaler_16: IWDG prescaler set to 16
106 * @arg IWDG_Prescaler_32: IWDG prescaler set to 32
107 * @arg IWDG_Prescaler_64: IWDG prescaler set to 64
108 * @arg IWDG_Prescaler_128: IWDG prescaler set to 128
109 * @arg IWDG_Prescaler_256: IWDG prescaler set to 256
112 void IWDG_SetPrescaler(uint8_t IWDG_Prescaler
)
114 /* Check the parameters */
115 assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler
));
116 IWDG
->PR
= IWDG_Prescaler
;
120 * @brief Sets IWDG Reload value.
121 * @param Reload: specifies the IWDG Reload value.
122 * This parameter must be a number between 0 and 0x0FFF.
125 void IWDG_SetReload(uint16_t Reload
)
127 /* Check the parameters */
128 assert_param(IS_IWDG_RELOAD(Reload
));
133 * @brief Reloads IWDG counter with value defined in the reload register
134 * (write access to IWDG_PR and IWDG_RLR registers disabled).
138 void IWDG_ReloadCounter(void)
140 IWDG
->KR
= KR_KEY_Reload
;
144 * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
148 void IWDG_Enable(void)
150 IWDG
->KR
= KR_KEY_Enable
;
154 * @brief Checks whether the specified IWDG flag is set or not.
155 * @param IWDG_FLAG: specifies the flag to check.
156 * This parameter can be one of the following values:
157 * @arg IWDG_FLAG_PVU: Prescaler Value Update on going
158 * @arg IWDG_FLAG_RVU: Reload Value Update on going
159 * @retval The new state of IWDG_FLAG (SET or RESET).
161 FlagStatus
IWDG_GetFlagStatus(uint16_t IWDG_FLAG
)
163 FlagStatus bitstatus
= RESET
;
164 /* Check the parameters */
165 assert_param(IS_IWDG_FLAG(IWDG_FLAG
));
166 if ((IWDG
->SR
& IWDG_FLAG
) != (uint32_t)RESET
)
174 /* Return the flag status */
190 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/