Blame view

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