at32f413_wdt.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /**
  2. **************************************************************************
  3. * @file at32f413_wdt.c
  4. * @brief contains all the functions for the wdt 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 "at32f413_conf.h"
  25. /** @addtogroup AT32F413_periph_driver
  26. * @{
  27. */
  28. /** @defgroup WDT
  29. * @brief WDT driver modules
  30. * @{
  31. */
  32. #ifdef WDT_MODULE_ENABLED
  33. /** @defgroup WDT_private_functions
  34. * @{
  35. */
  36. /**
  37. * @brief wdt enable ,the reload value will be sent to the counter
  38. * @param none
  39. * @retval none
  40. */
  41. void wdt_enable(void)
  42. {
  43. WDT->cmd = WDT_CMD_ENABLE;
  44. }
  45. /**
  46. * @brief reload wdt counter
  47. * @param none
  48. * @retval none
  49. */
  50. void wdt_counter_reload(void)
  51. {
  52. WDT->cmd = WDT_CMD_RELOAD;
  53. }
  54. /**
  55. * @brief set wdt counter reload value
  56. * @param reload_value (0x0000~0x0FFF)
  57. * @retval none
  58. */
  59. void wdt_reload_value_set(uint16_t reload_value)
  60. {
  61. WDT->rld = reload_value;
  62. }
  63. /**
  64. * @brief set wdt division divider
  65. * @param division
  66. * this parameter can be one of the following values:
  67. * - WDT_CLK_DIV_4
  68. * - WDT_CLK_DIV_8
  69. * - WDT_CLK_DIV_16
  70. * - WDT_CLK_DIV_32
  71. * - WDT_CLK_DIV_64
  72. * - WDT_CLK_DIV_128
  73. * - WDT_CLK_DIV_256
  74. * @retval none
  75. */
  76. void wdt_divider_set(wdt_division_type division)
  77. {
  78. WDT->div_bit.div = division;
  79. }
  80. /**
  81. * @brief enable or disable wdt cmd register write
  82. * @param new_state (TRUE or FALSE)
  83. * @retval none
  84. */
  85. void wdt_register_write_enable( confirm_state new_state)
  86. {
  87. if(new_state == FALSE)
  88. {
  89. WDT->cmd = WDT_CMD_LOCK;
  90. }
  91. else
  92. {
  93. WDT->cmd = WDT_CMD_UNLOCK;
  94. }
  95. }
  96. /**
  97. * @brief get wdt flag
  98. * @param wdt_flag
  99. * this parameter can be one of the following values:
  100. * - WDT_DIVF_UPDATE_FLAG: division value update complete flag.
  101. * - WDT_RLDF_UPDATE_FLAG: reload value update complete flag.
  102. * @retval state of wdt flag
  103. */
  104. flag_status wdt_flag_get(uint16_t wdt_flag)
  105. {
  106. flag_status status = RESET;
  107. if ((WDT->sts & wdt_flag) != (uint16_t)RESET)
  108. {
  109. status = SET;
  110. }
  111. else
  112. {
  113. status = RESET;
  114. }
  115. return status;
  116. }
  117. /**
  118. * @}
  119. */
  120. #endif
  121. /**
  122. * @}
  123. */
  124. /**
  125. * @}
  126. */