1 /*!
2  * @file        apm32f0xx_iwdt.c
3  *
4  * @brief       This file contains all the functions for the IWDT peripheral
5  *
6  * @version     V1.0.3
7  *
8  * @date        2022-09-20
9  *
10  * @attention
11  *
12  *  Copyright (C) 2020-2022 Geehy Semiconductor
13  *
14  *  You may not use this file except in compliance with the
15  *  GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE).
16  *
17  *  The program is only for reference, which is distributed in the hope
18  *  that it will be useful and instructional for customers to develop
19  *  their software. Unless required by applicable law or agreed to in
20  *  writing, the program is distributed on an "AS IS" BASIS, WITHOUT
21  *  ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied.
22  *  See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions
23  *  and limitations under the License.
24  */
25 
26 #include "apm32f0xx_iwdt.h"
27 
28 /** @addtogroup APM32F0xx_StdPeriphDriver
29   @{
30 */
31 
32 /** @addtogroup IWDT_Driver
33   @{
34 */
35 
36 /** @defgroup IWDT_Macros Macros
37   @{
38 */
39 
40 /**@} end of group IWDT_Macros*/
41 
42 /** @defgroup IWDT_Enumerations Enumerations
43   @{
44 */
45 
46 /**@} end of group IWDT_Enumerations*/
47 
48 /** @defgroup IWDT_Structures Structures
49   @{
50 */
51 
52 /**@} end of group IWDT_Structures*/
53 
54 /** @defgroup IWDT_Variables Variables
55   @{
56 */
57 
58 /**@} end of group IWDT_Variables*/
59 
60 /** @defgroup IWDT_Functions Functions
61   @{
62 */
63 
64 /*!
65  * @brief       Enable IWDT
66  *
67  * @param       None
68  *
69  * @retval      None
70  */
IWDT_Enable(void)71 void IWDT_Enable(void)
72 {
73     IWDT->KEY = IWDT_KEY_ENABLE;
74 }
75 
76 /*!
77  * @brief       Enable write access to Divider and Counter Reload registers
78  *
79  * @param       None
80  *
81  * @retval      None
82  */
IWDT_EnableWriteAccess(void)83 void IWDT_EnableWriteAccess(void)
84 {
85     IWDT->KEY = IWDT_KEY_ACCESS;
86 }
87 
88 /*!
89  * @brief       Disable write access to Divider and Counter Reload registers
90  *
91  * @param       None
92  *
93  * @retval      None
94  */
IWDT_DisableWriteAccess(void)95 void IWDT_DisableWriteAccess(void)
96 {
97     IWDT->KEY = 0;
98 }
99 
100 /*!
101  * @brief       Refresh IWDT
102  *
103  * @param       None
104  *
105  * @retval      None
106  */
IWDT_Refresh(void)107 void IWDT_Refresh(void)
108 {
109     IWDT->KEY = IWDT_KEY_REFRESH;
110 }
111 
112 /*!
113  * @brief       Divider configuration
114  *
115  * @param       div: Specifies the divider
116  *                   The parameter can be one of following values:
117  *                      @arg IWDT_DIV_4:    Prescaler divider 4
118  *                      @arg IWDT_DIV_8:    Prescaler divider 8
119  *                      @arg IWDT_DIV_16:   Prescaler divider 16
120  *                      @arg IWDT_DIV_32:   Prescaler divider 32
121  *                      @arg IWDT_DIV_64:   Prescaler divider 64
122  *                      @arg IWDT_DIV_128:  Prescaler divider 128
123  *                      @arg IWDT_DIV_256:  Prescaler divider 256
124  *
125  * @retval      None
126  */
IWDT_ConfigDivider(IWDT_DIV_T div)127 void IWDT_ConfigDivider(IWDT_DIV_T div)
128 {
129     IWDT->PSC = (uint32_t)div;
130 }
131 
132 /*!
133  * @brief       Set counter reload value
134  *
135  * @param       reload: Specifies the reload value
136  *
137  * @retval      None
138  */
IWDT_ConfigReload(uint16_t reload)139 void IWDT_ConfigReload(uint16_t reload)
140 {
141     IWDT->CNTRLD = (uint32_t)reload;
142 }
143 
144 /*!
145  * @brief       Set counter reload value
146  *
147  * @param       reload: Specifies the reload value
148  *
149  * @retval      None
150  */
IWDT_ConfigWindowValue(uint16_t windowValue)151 void IWDT_ConfigWindowValue(uint16_t windowValue)
152 {
153     IWDT->WIN = (uint32_t)windowValue;
154 }
155 /*!
156  * @brief       Read the specified IWDT flag
157  *
158  * @param       flag: Specifies the flag to read
159  *              The parameter can be one of following values:
160  *                 @arg IWDT_FLAG_DIVU:  Watchdog prescaler value update
161  *                 @arg IWDT_FLAG_CNTU:  Watchdog counter reload value update
162  *                 @arg IWDT_FLAG_WINU:  Watchdog counter window value update
163  *
164  * @retval      status of IWDT_FLAG (SET or RESET)
165  */
IWDT_ReadStatusFlag(uint8_t flag)166 uint8_t IWDT_ReadStatusFlag(uint8_t flag)
167 {
168     uint8_t bitStatus = RESET;
169 
170     if ((IWDT->STS & flag) != (uint32_t)RESET)
171     {
172         bitStatus = SET;
173     }
174     else
175     {
176         bitStatus = RESET;
177     }
178 
179     return bitStatus;
180 }
181 
182 /**@} end of group IWDT_Functions*/
183 /**@} end of group IWDT_Driver */
184 /**@} end of group APM32F0xx_StdPeriphDriver*/
185