ft32f0xx_iwdg.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /**
  2. ******************************************************************************
  3. * @file ft32f0xx_iwdg.c
  4. * @author FMD AE
  5. * @brief This file provides firmware functions to manage the following
  6. * functionalities of the Independent watchdog (IWDG) peripheral:
  7. * + Prescaler and Counter configuration
  8. * + IWDG activation
  9. * + Flag management
  10. * @version V1.0.0
  11. * @data 2021-07-01
  12. ******************************************************************************
  13. */
  14. /* Includes ------------------------------------------------------------------*/
  15. #include "ft32f0xx_iwdg.h"
  16. /* ---------------------- IWDG registers bit mask ----------------------------*/
  17. /* KR register bit mask */
  18. #define KR_KEY_RELOAD ((uint16_t)0xAAAA)
  19. #define KR_KEY_ENABLE ((uint16_t)0xCCCC)
  20. /**
  21. * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers.
  22. * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
  23. * This parameter can be one of the following values:
  24. * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
  25. * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
  26. * @retval None
  27. */
  28. void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)
  29. {
  30. /* Check the parameters */
  31. assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
  32. IWDG->KR = IWDG_WriteAccess;
  33. }
  34. /**
  35. * @brief Sets IWDG Prescaler value.
  36. * @param IWDG_Prescaler: specifies the IWDG Prescaler value.
  37. * This parameter can be one of the following values:
  38. * @arg IWDG_Prescaler_4: IWDG prescaler set to 4
  39. * @arg IWDG_Prescaler_8: IWDG prescaler set to 8
  40. * @arg IWDG_Prescaler_16: IWDG prescaler set to 16
  41. * @arg IWDG_Prescaler_32: IWDG prescaler set to 32
  42. * @arg IWDG_Prescaler_64: IWDG prescaler set to 64
  43. * @arg IWDG_Prescaler_128: IWDG prescaler set to 128
  44. * @arg IWDG_Prescaler_256: IWDG prescaler set to 256
  45. * @retval None
  46. */
  47. void IWDG_SetPrescaler(uint8_t IWDG_Prescaler)
  48. {
  49. /* Check the parameters */
  50. assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler));
  51. IWDG->PR = IWDG_Prescaler;
  52. }
  53. /**
  54. * @brief Sets IWDG Reload value.
  55. * @param Reload: specifies the IWDG Reload value.
  56. * This parameter must be a number between 0 and 0x0FFF.
  57. * @retval None
  58. */
  59. void IWDG_SetReload(uint16_t Reload)
  60. {
  61. /* Check the parameters */
  62. assert_param(IS_IWDG_RELOAD(Reload));
  63. IWDG->RLR = Reload;
  64. }
  65. /**
  66. * @brief Reloads IWDG counter with value defined in the reload register
  67. * (write access to IWDG_PR and IWDG_RLR registers disabled).
  68. * @param None
  69. * @retval None
  70. */
  71. void IWDG_ReloadCounter(void)
  72. {
  73. IWDG->KR = KR_KEY_RELOAD;
  74. }
  75. /**
  76. * @brief Sets the IWDG window value.
  77. * @param WindowValue: specifies the window value to be compared to the downcounter.
  78. * @retval None
  79. */
  80. void IWDG_SetWindowValue(uint16_t WindowValue)
  81. {
  82. /* Check the parameters */
  83. assert_param(IS_IWDG_WINDOW_VALUE(WindowValue));
  84. IWDG->WINR = WindowValue;
  85. }
  86. /**
  87. * @}
  88. */
  89. /** @defgroup IWDG_Group2 IWDG activation function
  90. * @brief IWDG activation function
  91. *
  92. @verbatim
  93. ==============================================================================
  94. ##### IWDG activation function #####
  95. ==============================================================================
  96. @endverbatim
  97. * @{
  98. */
  99. /**
  100. * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
  101. * @param None
  102. * @retval None
  103. */
  104. void IWDG_Enable(void)
  105. {
  106. IWDG->KR = KR_KEY_ENABLE;
  107. }
  108. /**
  109. * @}
  110. */
  111. /**
  112. * @brief Checks whether the specified IWDG flag is set or not.
  113. * @param IWDG_FLAG: specifies the flag to check.
  114. * This parameter can be one of the following values:
  115. * @arg IWDG_FLAG_PVU: Prescaler Value Update on going
  116. * @arg IWDG_FLAG_RVU: Reload Value Update on going
  117. * @arg IWDG_FLAG_WVU: Counter Window Value Update on going
  118. * @retval The new state of IWDG_FLAG (SET or RESET).
  119. */
  120. FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG)
  121. {
  122. FlagStatus bitstatus = RESET;
  123. /* Check the parameters */
  124. assert_param(IS_IWDG_FLAG(IWDG_FLAG));
  125. if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET)
  126. {
  127. bitstatus = SET;
  128. }
  129. else
  130. {
  131. bitstatus = RESET;
  132. }
  133. /* Return the flag status */
  134. return bitstatus;
  135. }
  136. /**
  137. * @}
  138. */
  139. /**
  140. * @}
  141. */
  142. /**
  143. * @}
  144. */
  145. /**
  146. * @}
  147. */
  148. /************************ (C) COPYRIGHT FMD *****END OF FILE****/