gd32e23x_wwdgt.c 4.0 KB

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