stm32f10x_wwdg.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /**
  2. ******************************************************************************
  3. * @file stm32f10x_wwdg.c
  4. * @author MCD Application Team
  5. * @version V3.5.0
  6. * @date 11-March-2011
  7. * @brief This file provides all the WWDG 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_wwdg.h"
  23. #include "stm32f10x_rcc.h"
  24. /** @addtogroup STM32F10x_StdPeriph_Driver
  25. * @{
  26. */
  27. /** @defgroup WWDG
  28. * @brief WWDG driver modules
  29. * @{
  30. */
  31. /** @defgroup WWDG_Private_TypesDefinitions
  32. * @{
  33. */
  34. /**
  35. * @}
  36. */
  37. /** @defgroup WWDG_Private_Defines
  38. * @{
  39. */
  40. /* ----------- WWDG registers bit address in the alias region ----------- */
  41. #define WWDG_OFFSET (WWDG_BASE - PERIPH_BASE)
  42. /* Alias word address of EWI bit */
  43. #define CFR_OFFSET (WWDG_OFFSET + 0x04)
  44. #define EWI_BitNumber 0x09
  45. #define CFR_EWI_BB (PERIPH_BB_BASE + (CFR_OFFSET * 32) + (EWI_BitNumber * 4))
  46. /* --------------------- WWDG registers bit mask ------------------------ */
  47. /* CR register bit mask */
  48. #define CR_WDGA_Set ((uint32_t)0x00000080)
  49. /* CFR register bit mask */
  50. #define CFR_WDGTB_Mask ((uint32_t)0xFFFFFE7F)
  51. #define CFR_W_Mask ((uint32_t)0xFFFFFF80)
  52. #define BIT_Mask ((uint8_t)0x7F)
  53. /**
  54. * @}
  55. */
  56. /** @defgroup WWDG_Private_Macros
  57. * @{
  58. */
  59. /**
  60. * @}
  61. */
  62. /** @defgroup WWDG_Private_Variables
  63. * @{
  64. */
  65. /**
  66. * @}
  67. */
  68. /** @defgroup WWDG_Private_FunctionPrototypes
  69. * @{
  70. */
  71. /**
  72. * @}
  73. */
  74. /** @defgroup WWDG_Private_Functions
  75. * @{
  76. */
  77. /**
  78. * @brief Deinitializes the WWDG peripheral registers to their default reset values.
  79. * @param None
  80. * @retval None
  81. */
  82. void WWDG_DeInit(void)
  83. {
  84. RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, ENABLE);
  85. RCC_APB1PeriphResetCmd(RCC_APB1Periph_WWDG, DISABLE);
  86. }
  87. /**
  88. * @brief Sets the WWDG Prescaler.
  89. * @param WWDG_Prescaler: specifies the WWDG Prescaler.
  90. * This parameter can be one of the following values:
  91. * @arg WWDG_Prescaler_1: WWDG counter clock = (PCLK1/4096)/1
  92. * @arg WWDG_Prescaler_2: WWDG counter clock = (PCLK1/4096)/2
  93. * @arg WWDG_Prescaler_4: WWDG counter clock = (PCLK1/4096)/4
  94. * @arg WWDG_Prescaler_8: WWDG counter clock = (PCLK1/4096)/8
  95. * @retval None
  96. */
  97. void WWDG_SetPrescaler(uint32_t WWDG_Prescaler)
  98. {
  99. uint32_t tmpreg = 0;
  100. /* Check the parameters */
  101. assert_param(IS_WWDG_PRESCALER(WWDG_Prescaler));
  102. /* Clear WDGTB[1:0] bits */
  103. tmpreg = WWDG->CFR & CFR_WDGTB_Mask;
  104. /* Set WDGTB[1:0] bits according to WWDG_Prescaler value */
  105. tmpreg |= WWDG_Prescaler;
  106. /* Store the new value */
  107. WWDG->CFR = tmpreg;
  108. }
  109. /**
  110. * @brief Sets the WWDG window value.
  111. * @param WindowValue: specifies the window value to be compared to the downcounter.
  112. * This parameter value must be lower than 0x80.
  113. * @retval None
  114. */
  115. void WWDG_SetWindowValue(uint8_t WindowValue)
  116. {
  117. __IO uint32_t tmpreg = 0;
  118. /* Check the parameters */
  119. assert_param(IS_WWDG_WINDOW_VALUE(WindowValue));
  120. /* Clear W[6:0] bits */
  121. tmpreg = WWDG->CFR & CFR_W_Mask;
  122. /* Set W[6:0] bits according to WindowValue value */
  123. tmpreg |= WindowValue & (uint32_t) BIT_Mask;
  124. /* Store the new value */
  125. WWDG->CFR = tmpreg;
  126. }
  127. /**
  128. * @brief Enables the WWDG Early Wakeup interrupt(EWI).
  129. * @param None
  130. * @retval None
  131. */
  132. void WWDG_EnableIT(void)
  133. {
  134. *(__IO uint32_t *) CFR_EWI_BB = (uint32_t)ENABLE;
  135. }
  136. /**
  137. * @brief Sets the WWDG counter value.
  138. * @param Counter: specifies the watchdog counter value.
  139. * This parameter must be a number between 0x40 and 0x7F.
  140. * @retval None
  141. */
  142. void WWDG_SetCounter(uint8_t Counter)
  143. {
  144. /* Check the parameters */
  145. assert_param(IS_WWDG_COUNTER(Counter));
  146. /* Write to T[6:0] bits to configure the counter value, no need to do
  147. a read-modify-write; writing a 0 to WDGA bit does nothing */
  148. WWDG->CR = Counter & BIT_Mask;
  149. }
  150. /**
  151. * @brief Enables WWDG and load the counter value.
  152. * @param Counter: specifies the watchdog counter value.
  153. * This parameter must be a number between 0x40 and 0x7F.
  154. * @retval None
  155. */
  156. void WWDG_Enable(uint8_t Counter)
  157. {
  158. /* Check the parameters */
  159. assert_param(IS_WWDG_COUNTER(Counter));
  160. WWDG->CR = CR_WDGA_Set | Counter;
  161. }
  162. /**
  163. * @brief Checks whether the Early Wakeup interrupt flag is set or not.
  164. * @param None
  165. * @retval The new state of the Early Wakeup interrupt flag (SET or RESET)
  166. */
  167. FlagStatus WWDG_GetFlagStatus(void)
  168. {
  169. return (FlagStatus)(WWDG->SR);
  170. }
  171. /**
  172. * @brief Clears Early Wakeup interrupt flag.
  173. * @param None
  174. * @retval None
  175. */
  176. void WWDG_ClearFlag(void)
  177. {
  178. WWDG->SR = (uint32_t)RESET;
  179. }
  180. /**
  181. * @}
  182. */
  183. /**
  184. * @}
  185. */
  186. /**
  187. * @}
  188. */
  189. /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/