at32f403a_407_wwdt.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /**
  2. **************************************************************************
  3. * @file at32f403a_407_wwdt.c
  4. * @brief contains all the functions for the wwdt firmware library
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. #include "at32f403a_407_conf.h"
  25. /** @addtogroup AT32F403A_407_periph_driver
  26. * @{
  27. */
  28. /** @defgroup WWDT
  29. * @brief WWDT driver modules
  30. * @{
  31. */
  32. #ifdef WWDT_MODULE_ENABLED
  33. /** @defgroup WWDT_private_functions
  34. * @{
  35. */
  36. /**
  37. * @brief wwdt reset by crm reset register
  38. * @retval none
  39. */
  40. void wwdt_reset(void)
  41. {
  42. crm_periph_reset(CRM_WWDT_PERIPH_RESET, TRUE);
  43. crm_periph_reset(CRM_WWDT_PERIPH_RESET, FALSE);
  44. }
  45. /**
  46. * @brief wwdt division set
  47. * @param division
  48. * this parameter can be one of the following values:
  49. * - WWDT_PCLK1_DIV_4096 (wwdt counter clock = (pclk1/4096)/1)
  50. * - WWDT_PCLK1_DIV_8192 (wwdt counter clock = (pclk1/4096)/2)
  51. * - WWDT_PCLK1_DIV_16384 (wwdt counter clock = (pclk1/4096)/4)
  52. * - WWDT_PCLK1_DIV_32768 (wwdt counter clock = (pclk1/4096)/8)
  53. * @retval none
  54. */
  55. void wwdt_divider_set(wwdt_division_type division)
  56. {
  57. WWDT->cfg_bit.div = division;
  58. }
  59. /**
  60. * @brief wwdt reload counter interrupt flag clear
  61. * @param none
  62. * @retval none
  63. */
  64. void wwdt_flag_clear(void)
  65. {
  66. WWDT->sts = 0;
  67. }
  68. /**
  69. * @brief wwdt enable and the counter value load
  70. * @param wwdt_cnt (0x40~0x7f)
  71. * @retval none
  72. */
  73. void wwdt_enable(uint8_t wwdt_cnt)
  74. {
  75. WWDT->ctrl = wwdt_cnt | WWDT_EN_BIT;
  76. }
  77. /**
  78. * @brief wwdt reload counter interrupt enable
  79. * @param none
  80. * @retval none
  81. */
  82. void wwdt_interrupt_enable(void)
  83. {
  84. WWDT->cfg_bit.rldien = TRUE;
  85. }
  86. /**
  87. * @brief wwdt reload counter interrupt flag get
  88. * @param none
  89. * @retval state of reload counter interrupt flag
  90. */
  91. flag_status wwdt_flag_get(void)
  92. {
  93. return (flag_status)WWDT->sts_bit.rldf;
  94. }
  95. /**
  96. * @brief wwdt reload counter interrupt flag get
  97. * @param none
  98. * @retval state of reload counter interrupt flag
  99. */
  100. flag_status wwdt_interrupt_flag_get(void)
  101. {
  102. return (flag_status)(WWDT->sts_bit.rldf && WWDT->cfg_bit.rldien);
  103. }
  104. /**
  105. * @brief wwdt counter value set
  106. * @param wwdt_cnt (0x40~0x7f)
  107. * @retval none
  108. */
  109. void wwdt_counter_set(uint8_t wwdt_cnt)
  110. {
  111. WWDT->ctrl_bit.cnt = wwdt_cnt;
  112. }
  113. /**
  114. * @brief wwdt window counter value set
  115. * @param window_cnt (0x40~0x7f)
  116. * @retval none
  117. */
  118. void wwdt_window_counter_set(uint8_t window_cnt)
  119. {
  120. WWDT->cfg_bit.win = window_cnt;
  121. }
  122. /**
  123. * @}
  124. */
  125. #endif
  126. /**
  127. * @}
  128. */
  129. /**
  130. * @}
  131. */