stm32f10x_iwdg.c 4.8 KB

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