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