1 /*!
2  * @file        apm32f10x_wwdt.c
3  *
4  * @brief       This file contains all the functions for the WWDT peripheral
5  *
6  * @version     V1.0.4
7  *
8  * @date        2022-12-01
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 "apm32f10x_wwdt.h"
27 #include "apm32f10x_rcm.h"
28 
29 /** @addtogroup APM32F10x_StdPeriphDriver
30   @{
31 */
32 
33 /** @defgroup WWDT_Driver WWDT Driver
34   * @brief WWDT driver modules
35   @{
36 */
37 
38 /** @defgroup  WWDT_Functions Functions
39   @{
40 */
41 
42 /*!
43  * @brief     Reset the WWDT peripheral registers
44  *
45  * @param     None
46  *
47  * @retval    None
48  */
WWDT_Reset(void)49 void WWDT_Reset(void)
50 {
51     RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_WWDT);
52     RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_WWDT);
53 }
54 
55 /*!
56  * @brief     Configures the WWDT Timebase
57  *
58  * @param     timebase: WWDT Prescaler
59  *            The parameter can be one of following values:
60  *            @arg WWDT_TIME_BASE_1:  WWDT counter clock = (PCLK1/4096)/1
61  *            @arg WWDT_TIME_BASE_2:  WWDT counter clock = (PCLK1/4096)/2
62  *            @arg WWDT_TIME_BASE_4:  WWDT counter clock = (PCLK1/4096)/4
63  *            @arg WWDT_TIME_BASE_8:  WWDT counter clock = (PCLK1/4096)/8
64  *
65  * @retval    None
66  */
WWDT_ConfigTimebase(WWDT_TIME_BASE_T timeBase)67 void WWDT_ConfigTimebase(WWDT_TIME_BASE_T timeBase)
68 {
69     __IO uint32_t reg;
70 
71     reg = WWDT->CFG & 0xFFFFFE7F;
72     reg |= timeBase;
73     WWDT->CFG = reg;
74 }
75 
76 /*!
77  * @brief     Configures the WWDT Window data
78  *
79  * @param     windowdata: window data which compare with the downcounter
80  *
81  * @retval    None
82  *
83  * @note      The windowdata must be lower than 0x80
84  */
WWDT_ConfigWindowData(uint8_t windowData)85 void WWDT_ConfigWindowData(uint8_t windowData)
86 {
87     __IO uint32_t reg;
88 
89     reg = WWDT->CFG & 0xFFFFFF80;
90     reg |= windowData & 0x7F;
91     WWDT->CFG = reg;
92 }
93 
94 /*!
95  * @brief       Configures the WWDT counter value
96  *
97  * @param       counter: Specifies the watchdog counter value
98  *
99  * @retval      None
100  *
101  * @note        The counter between 0x40 and 0x7F
102  */
WWDT_ConfigCounter(uint8_t counter)103 void WWDT_ConfigCounter(uint8_t counter)
104 {
105     WWDT->CTRL = counter & 0x7F;
106 }
107 
108 /*!
109  * @brief     Enable the WWDT Early Wakeup interrupt
110  *
111  * @param     None
112  *
113  * @retval    None
114  */
WWDT_EnableEWI(void)115 void WWDT_EnableEWI(void)
116 {
117     WWDT->CFG_B.EWIEN = SET;
118 }
119 
120 /*!
121  * @brief     Enable WWDT and set the counter value
122  *
123  * @param     counter: the window watchdog counter value
124  *
125  * @retval    None
126  *
127  * @note      The counter between 0x40 and 0x7F
128  */
WWDT_Enable(uint8_t counter)129 void WWDT_Enable(uint8_t counter)
130 {
131     WWDT->CTRL =  counter | 0x00000080;
132 }
133 
134 /*!
135  * @brief     Read the Early Wakeup interrupt flag
136  *
137  * @param     None
138  *
139  * @retval    the state of the Early Wakeup interrupt flagte
140  */
WWDT_ReadFlag(void)141 uint8_t WWDT_ReadFlag(void)
142 {
143     return (uint8_t)(WWDT->STS);
144 }
145 
146 /*!
147  * @brief     Clear the Early Wakeup interrupt flag
148  *
149  * @param     None
150  *
151  * @retval    None
152  */
WWDT_ClearFlag(void)153 void WWDT_ClearFlag(void)
154 {
155     WWDT->STS_B.EWIFLG = RESET;
156 }
157 
158 /**@} end of group WWDT_Functions */
159 /**@} end of group WWDT_Driver */
160 /**@} end of group APM32F10x_StdPeriphDriver */
161