1 /*!
2 \file gd32e10x_wwdgt.c
3 \brief WWDGT driver
4
5 \version 2017-12-26, V1.0.0, firmware for GD32E10x
6 \version 2020-09-30, V1.1.0, firmware for GD32E10x
7 \version 2020-12-31, V1.2.0, firmware for GD32E10x
8 \version 2022-06-30, V1.3.0, firmware for GD32E10x
9 */
10
11 /*
12 Copyright (c) 2022, GigaDevice Semiconductor Inc.
13
14 Redistribution and use in source and binary forms, with or without modification,
15 are permitted provided that the following conditions are met:
16
17 1. Redistributions of source code must retain the above copyright notice, this
18 list of conditions and the following disclaimer.
19 2. Redistributions in binary form must reproduce the above copyright notice,
20 this list of conditions and the following disclaimer in the documentation
21 and/or other materials provided with the distribution.
22 3. Neither the name of the copyright holder nor the names of its contributors
23 may be used to endorse or promote products derived from this software without
24 specific prior written permission.
25
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
28 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
29 IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
31 NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
33 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35 OF SUCH DAMAGE.
36 */
37
38 #include "gd32e10x_wwdgt.h"
39
40 /*!
41 \brief reset the window watchdog timer configuration
42 \param[in] none
43 \param[out] none
44 \retval none
45 */
wwdgt_deinit(void)46 void wwdgt_deinit(void)
47 {
48 rcu_periph_reset_enable(RCU_WWDGTRST);
49 rcu_periph_reset_disable(RCU_WWDGTRST);
50 }
51
52 /*!
53 \brief start the window watchdog timer counter
54 \param[in] none
55 \param[out] none
56 \retval none
57 */
wwdgt_enable(void)58 void wwdgt_enable(void)
59 {
60 WWDGT_CTL |= WWDGT_CTL_WDGTEN;
61 }
62
63 /*!
64 \brief configure the window watchdog timer counter value
65 \param[in] counter_value: 0x00 - 0x7F
66 \param[out] none
67 \retval none
68 */
wwdgt_counter_update(uint16_t counter_value)69 void wwdgt_counter_update(uint16_t counter_value)
70 {
71 WWDGT_CTL = (uint32_t)(CTL_CNT(counter_value));
72 }
73
74 /*!
75 \brief configure counter value, window value, and prescaler divider value
76 \param[in] counter: 0x00 - 0x7F
77 \param[in] window: 0x00 - 0x7F
78 \param[in] prescaler: wwdgt prescaler value
79 only one parameter can be selected which is shown as below:
80 \arg WWDGT_CFG_PSC_DIV1: the time base of window watchdog counter = (PCLK1/4096)/1
81 \arg WWDGT_CFG_PSC_DIV2: the time base of window watchdog counter = (PCLK1/4096)/2
82 \arg WWDGT_CFG_PSC_DIV4: the time base of window watchdog counter = (PCLK1/4096)/4
83 \arg WWDGT_CFG_PSC_DIV8: the time base of window watchdog counter = (PCLK1/4096)/8
84 \param[out] none
85 \retval none
86 */
wwdgt_config(uint16_t counter,uint16_t window,uint32_t prescaler)87 void wwdgt_config(uint16_t counter, uint16_t window, uint32_t prescaler)
88 {
89 WWDGT_CTL = (uint32_t)(CTL_CNT(counter));
90 WWDGT_CFG = (uint32_t)(CFG_WIN(window) | prescaler);
91 }
92
93 /*!
94 \brief check early wakeup interrupt state of WWDGT
95 \param[in] none
96 \param[out] none
97 \retval FlagStatus: SET or RESET
98 */
wwdgt_flag_get(void)99 FlagStatus wwdgt_flag_get(void)
100 {
101 if(WWDGT_STAT & WWDGT_STAT_EWIF) {
102 return SET;
103 }
104
105 return RESET;
106 }
107
108 /*!
109 \brief clear early wakeup interrupt state of WWDGT
110 \param[in] none
111 \param[out] none
112 \retval none
113 */
wwdgt_flag_clear(void)114 void wwdgt_flag_clear(void)
115 {
116 WWDGT_STAT = (uint32_t)(RESET);
117 }
118
119 /*!
120 \brief enable early wakeup interrupt of WWDGT
121 \param[in] none
122 \param[out] none
123 \retval none
124 */
wwdgt_interrupt_enable(void)125 void wwdgt_interrupt_enable(void)
126 {
127 WWDGT_CFG |= WWDGT_CFG_EWIE;
128 }
129