1 /*!
2  * @file        apm32e10x_iwdt.c
3  *
4  * @brief       This file provides all the IWDT firmware functions
5  *
6  * @version     V1.0.2
7  *
8  * @date        2022-12-31
9  *
10  * @attention
11  *
12  *  Copyright (C) 2021-2023 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 "apm32e10x_iwdt.h"
27 
28 /** @addtogroup APM32E10x_StdPeriphDriver
29   @{
30 */
31 
32 /** @addtogroup IWDT_Driver
33   * @brief IWDT driver modules
34   @{
35 */
36 
37 /** @defgroup IWDT_Functions Functions
38   @{
39 */
40 
41 /*!
42  * @brief        Enable IWDT
43  *
44  * @param        None
45  *
46  * @retval       None
47  */
IWDT_Enable(void)48 void IWDT_Enable(void)
49 {
50     IWDT->KEY = IWDT_KEYWORD_ENABLE;
51 }
52 
53 /*!
54  * @brief        Reload the IWDT counter with value
55  *
56  * @param        None
57  *
58  * @retval       None
59  */
IWDT_Refresh(void)60 void IWDT_Refresh(void)
61 {
62     IWDT->KEY = IWDT_KEYWORD_RELOAD;
63 }
64 
65 /*!
66  * @brief        Set IWDT count reload values
67  *
68  * @param        reload: IWDT count reload values
69  *
70  * @retval       None
71  */
IWDT_ConfigReload(uint16_t reload)72 void IWDT_ConfigReload(uint16_t reload)
73 {
74     IWDT->CNTRLD = reload;
75 }
76 
77 /*!
78  * @brief        Enable the IWDT write access
79  *
80  * @param        None
81  *
82  * @retval       None
83  */
IWDT_EnableWriteAccess(void)84 void IWDT_EnableWriteAccess(void)
85 {
86     IWDT->KEY_B.KEY = IWDT_WRITEACCESS_ENABLE;
87 }
88 
89 /*!
90  * @brief        Disable the IWDT write access
91  *
92  * @param        None
93  *
94  * @retval       None
95  */
IWDT_DisableWriteAccess(void)96 void IWDT_DisableWriteAccess(void)
97 {
98     IWDT->KEY_B.KEY = IWDT_WRITEACCESS_DISABLE;
99 }
100 
101 /*!
102  * @brief        Set IWDT frequency divider values
103  *
104  * @param        div: IWDT frequency divider values
105  *                    This parameter can be one of the following values:
106  *                    @arg IWDT_DIVIDER_4  : prescaler divider equal to 4
107  *                    @arg IWDT_DIVIDER_8  : prescaler divider equal to 8
108  *                    @arg IWDT_DIVIDER_16 : prescaler divider equal to 16
109  *                    @arg IWDT_DIVIDER_32 : prescaler divider equal to 32
110  *                    @arg IWDT_DIVIDER_64 : prescaler divider equal to 64
111  *                    @arg IWDT_DIVIDER_128: prescaler divider equal to 128
112  *                    @arg IWDT_DIVIDER_256: prescaler divider equal to 256
113  *
114  * @retval       None
115  */
IWDT_ConfigDivider(uint8_t div)116 void IWDT_ConfigDivider(uint8_t div)
117 {
118     IWDT->PSC = div;
119 }
120 
121 /*!
122  * @brief        Read the specified IWDT flag
123  *
124  * @param        flag: specifies the flag to read
125  *                     This parameter can be one of the following values:
126  *                     @arg IWDT_FLAG_PSCU : Watchdog Prescaler Factor Update flag
127  *                     @arg IWDT_FLAG_CNTU : Watchdog Counter Reload Value Update flag
128  *
129  * @retval       status of IWDT_FLAG (SET or RESET)
130  *
131  * @note
132  */
IWDT_ReadStatusFlag(uint16_t flag)133 uint8_t IWDT_ReadStatusFlag(uint16_t flag)
134 {
135     uint8_t bitStatus = RESET;
136 
137     if((IWDT->STS & flag) != (uint32_t)RESET)
138     {
139         bitStatus = SET;
140     }
141     else
142     {
143         bitStatus = RESET;
144     }
145     return bitStatus;
146 }
147 
148 /**@} end of group IWDT_Functions */
149 /**@} end of group IWDT_Driver */
150 /**@} end of group APM32E10x_StdPeriphDriver */
151