gd32f30x_wwdgt.c 3.9 KB

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