stm32f10x_iwdg.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_iwdg.c
  4. * @author MCD Application Team
  5. * @version V3.3.0
  6. * @date 04/16/2010
  7. * @brief This file provides all the IWDG firmware functions.
  8. ******************************************************************************
  9. * @copy
  10. *
  11. * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
  12. * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
  13. * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
  14. * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
  15. * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
  16. * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
  17. *
  18. * <h2><center>&copy; COPYRIGHT 2010 STMicroelectronics</center></h2>
  19. */
  20. /* Includes ------------------------------------------------------------------*/
  21. #include "stm32f10x_iwdg.h"
  22. /** @addtogroup STM32F10x_StdPeriph_Driver
  23. * @{
  24. */
  25. /** @defgroup IWDG
  26. * @brief IWDG driver modules
  27. * @{
  28. */
  29. /** @defgroup IWDG_Private_TypesDefinitions
  30. * @{
  31. */
  32. /**
  33. * @}
  34. */
  35. /** @defgroup IWDG_Private_Defines
  36. * @{
  37. */
  38. /* ---------------------- IWDG registers bit mask ----------------------------*/
  39. /* KR register bit mask */
  40. #define KR_KEY_Reload ((uint16_t)0xAAAA)
  41. #define KR_KEY_Enable ((uint16_t)0xCCCC)
  42. /**
  43. * @}
  44. */
  45. /** @defgroup IWDG_Private_Macros
  46. * @{
  47. */
  48. /**
  49. * @}
  50. */
  51. /** @defgroup IWDG_Private_Variables
  52. * @{
  53. */
  54. /**
  55. * @}
  56. */
  57. /** @defgroup IWDG_Private_FunctionPrototypes
  58. * @{
  59. */
  60. /**
  61. * @}
  62. */
  63. /** @defgroup IWDG_Private_Functions
  64. * @{
  65. */
  66. /**
  67. * @brief Enables or disables write access to IWDG_PR and IWDG_RLR registers.
  68. * @param IWDG_WriteAccess: new state of write access to IWDG_PR and IWDG_RLR registers.
  69. * This parameter can be one of the following values:
  70. * @arg IWDG_WriteAccess_Enable: Enable write access to IWDG_PR and IWDG_RLR registers
  71. * @arg IWDG_WriteAccess_Disable: Disable write access to IWDG_PR and IWDG_RLR registers
  72. * @retval None
  73. */
  74. void IWDG_WriteAccessCmd(uint16_t IWDG_WriteAccess)
  75. {
  76. /* Check the parameters */
  77. assert_param(IS_IWDG_WRITE_ACCESS(IWDG_WriteAccess));
  78. IWDG->KR = IWDG_WriteAccess;
  79. }
  80. /**
  81. * @brief Sets IWDG Prescaler value.
  82. * @param IWDG_Prescaler: specifies the IWDG Prescaler value.
  83. * This parameter can be one of the following values:
  84. * @arg IWDG_Prescaler_4: IWDG prescaler set to 4
  85. * @arg IWDG_Prescaler_8: IWDG prescaler set to 8
  86. * @arg IWDG_Prescaler_16: IWDG prescaler set to 16
  87. * @arg IWDG_Prescaler_32: IWDG prescaler set to 32
  88. * @arg IWDG_Prescaler_64: IWDG prescaler set to 64
  89. * @arg IWDG_Prescaler_128: IWDG prescaler set to 128
  90. * @arg IWDG_Prescaler_256: IWDG prescaler set to 256
  91. * @retval None
  92. */
  93. void IWDG_SetPrescaler(uint8_t IWDG_Prescaler)
  94. {
  95. /* Check the parameters */
  96. assert_param(IS_IWDG_PRESCALER(IWDG_Prescaler));
  97. IWDG->PR = IWDG_Prescaler;
  98. }
  99. /**
  100. * @brief Sets IWDG Reload value.
  101. * @param Reload: specifies the IWDG Reload value.
  102. * This parameter must be a number between 0 and 0x0FFF.
  103. * @retval None
  104. */
  105. void IWDG_SetReload(uint16_t Reload)
  106. {
  107. /* Check the parameters */
  108. assert_param(IS_IWDG_RELOAD(Reload));
  109. IWDG->RLR = Reload;
  110. }
  111. /**
  112. * @brief Reloads IWDG counter with value defined in the reload register
  113. * (write access to IWDG_PR and IWDG_RLR registers disabled).
  114. * @param None
  115. * @retval None
  116. */
  117. void IWDG_ReloadCounter(void)
  118. {
  119. IWDG->KR = KR_KEY_Reload;
  120. }
  121. /**
  122. * @brief Enables IWDG (write access to IWDG_PR and IWDG_RLR registers disabled).
  123. * @param None
  124. * @retval None
  125. */
  126. void IWDG_Enable(void)
  127. {
  128. IWDG->KR = KR_KEY_Enable;
  129. }
  130. /**
  131. * @brief Checks whether the specified IWDG flag is set or not.
  132. * @param IWDG_FLAG: specifies the flag to check.
  133. * This parameter can be one of the following values:
  134. * @arg IWDG_FLAG_PVU: Prescaler Value Update on going
  135. * @arg IWDG_FLAG_RVU: Reload Value Update on going
  136. * @retval The new state of IWDG_FLAG (SET or RESET).
  137. */
  138. FlagStatus IWDG_GetFlagStatus(uint16_t IWDG_FLAG)
  139. {
  140. FlagStatus bitstatus = RESET;
  141. /* Check the parameters */
  142. assert_param(IS_IWDG_FLAG(IWDG_FLAG));
  143. if ((IWDG->SR & IWDG_FLAG) != (uint32_t)RESET)
  144. {
  145. bitstatus = SET;
  146. }
  147. else
  148. {
  149. bitstatus = RESET;
  150. }
  151. /* Return the flag status */
  152. return bitstatus;
  153. }
  154. /**
  155. * @}
  156. */
  157. /**
  158. * @}
  159. */
  160. /**
  161. * @}
  162. */
  163. /******************* (C) COPYRIGHT 2010 STMicroelectronics *****END OF FILE****/