1 /* Includes ------------------------------------------------------------------*/
2 #include "air32f10x_iwdg.h"
3 
4 
5 /** @defgroup IWDG
6   * @brief IWDG driver modules
7   * @{
8   */
9 
10 /** @defgroup IWDG_Private_TypesDefinitions
11   * @{
12   */
13 
14 /**
15   * @}
16   */
17 
18 /** @defgroup IWDG_Private_Defines
19   * @{
20   */
21 
22 /* ---------------------- IWDG registers bit mask ----------------------------*/
23 
24 /* KR register bit mask */
25 #define KR_KEY_Reload    ((uint16_t)0xAAAA)
26 #define KR_KEY_Enable    ((uint16_t)0xCCCC)
27 
28 /**
29   * @}
30   */
31 
32 /** @defgroup IWDG_Private_Macros
33   * @{
34   */
35 
36 /**
37   * @}
38   */
39 
40 /** @defgroup IWDG_Private_Variables
41   * @{
42   */
43 
44 /**
45   * @}
46   */
47 
48 /** @defgroup IWDG_Private_FunctionPrototypes
49   * @{
50   */
51 
52 /**
53   * @}
54   */
55 
56 /** @defgroup IWDG_Private_Functions
57   * @{
58   */
59 
60 /**
61   * @brief  Enables or disables write access to IWDG_PR and IWDG_RLR registers.
62   * @param  IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
63   *   This parameter can be one of the following values:
64   *     @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
65   *     @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
66   * @retval None
67   */
IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)68 void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)
69 {
70   /* Check the parameters */
71   assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
72   IWDG->KR = IWDG_WriteAccess;
73 }
74 
75 /**
76   * @brief  Sets IWDG Prescaler value.
77   * @param  IWDG_Prescaler: specifies the IWDG Prescaler value.
78   *   This parameter can be one of the following values:
79   *     @arg IWDG_Prescaler_4: IWDG prescaler set to 4
80   *     @arg IWDG_Prescaler_8: IWDG prescaler set to 8
81   *     @arg IWDG_Prescaler_16: IWDG prescaler set to 16
82   *     @arg IWDG_Prescaler_32: IWDG prescaler set to 32
83   *     @arg IWDG_Prescaler_64: IWDG prescaler set to 64
84   *     @arg IWDG_Prescaler_128: IWDG prescaler set to 128
85   *     @arg IWDG_Prescaler_256: IWDG prescaler set to 256
86   * @retval None
87   */
IWDG_SetPrescaler(uint8_t IWDG_Prescaler)88 void IWDG_SetPrescaler(uint8_t IWDG_Prescaler)
89 {
90   /* Check the parameters */
91   assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler));
92   IWDG->PR = IWDG_Prescaler;
93 }
94 
95 /**
96   * @brief  Sets IWDG Reload value.
97   * @param  Reload: specifies the IWDG Reload value.
98   *   This parameter must be a number between 0 and 0x0FFF.
99   * @retval None
100   */
IWDG_SetReload(uint16_t Reload)101 void IWDG_SetReload(uint16_t Reload)
102 {
103   /* Check the parameters */
104   assert_param(IS_IWDG_RELOAD(Reload));
105   IWDG->RLR = Reload;
106 }
107 
108 /**
109   * @brief  Reloads IWDG counter with value defined in the reload register
110   *   (write access to IWDG_PR and IWDG_RLR registers disabled).
111   * @param  None
112   * @retval None
113   */
IWDG_ReloadCounter(void)114 void IWDG_ReloadCounter(void)
115 {
116   IWDG->KR = KR_KEY_Reload;
117 }
118 
119 /**
120   * @brief  Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
121   * @param  None
122   * @retval None
123   */
IWDG_Enable(void)124 void IWDG_Enable(void)
125 {
126   IWDG->KR = KR_KEY_Enable;
127 }
128 
129 /**
130   * @brief  Checks whether the specified IWDG flag is set or not.
131   * @param  IWDG_FLAG: specifies the flag to check.
132   *   This parameter can be one of the following values:
133   *     @arg IWDG_FLAG_PVU: Prescaler Value Update on going
134   *     @arg IWDG_FLAG_RVU: Reload Value Update on going
135   * @retval The new state of IWDG_FLAG (SET or RESET).
136   */
IWDG_GetFlagStatus(uint16_t IWDG_FLAG)137 FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG)
138 {
139   FlagStatus bitstatus = RESET;
140   /* Check the parameters */
141   assert_param(IS_IWDG_FLAG(IWDG_FLAG));
142   if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET)
143   {
144     bitstatus = SET;
145   }
146   else
147   {
148     bitstatus = RESET;
149   }
150   /* Return the flag status */
151   return bitstatus;
152 }
153 
154 /**
155   * @}
156   */
157 
158 /**
159   * @}
160   */
161 
162 /**
163   * @}
164   */
165 
166