gd32e23x_wwdgt.c 4.1 KB

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