hal_wwdg.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. ////////////////////////////////////////////////////////////////////////////////
  2. /// @file hal_wwdg.c
  3. /// @author AE TEAM
  4. /// @brief THIS FILE PROVIDES ALL THE WWDG FIRMWARE FUNCTIONS.
  5. ////////////////////////////////////////////////////////////////////////////////
  6. /// @attention
  7. ///
  8. /// THE EXISTING FIRMWARE IS ONLY FOR REFERENCE, WHICH IS DESIGNED TO PROVIDE
  9. /// CUSTOMERS WITH CODING INFORMATION ABOUT THEIR PRODUCTS SO THEY CAN SAVE
  10. /// TIME. THEREFORE, MINDMOTION SHALL NOT BE LIABLE FOR ANY DIRECT, INDIRECT OR
  11. /// CONSEQUENTIAL DAMAGES ABOUT ANY CLAIMS ARISING OUT OF THE CONTENT OF SUCH
  12. /// HARDWARE AND/OR THE USE OF THE CODING INFORMATION CONTAINED HEREIN IN
  13. /// CONNECTION WITH PRODUCTS MADE BY CUSTOMERS.
  14. ///
  15. /// <H2><CENTER>&COPY; COPYRIGHT MINDMOTION </CENTER></H2>
  16. ////////////////////////////////////////////////////////////////////////////////
  17. // Define to prevent recursive inclusion
  18. #define _HAL_WWDG_C_
  19. // Files includes
  20. #include "hal_wwdg.h"
  21. #include "hal_rcc.h"
  22. ////////////////////////////////////////////////////////////////////////////////
  23. /// @addtogroup MM32_Hardware_Abstract_Layer
  24. /// @{
  25. ////////////////////////////////////////////////////////////////////////////////
  26. /// @addtogroup WWDG_HAL
  27. /// @{
  28. ////////////////////////////////////////////////////////////////////////////////
  29. /// @addtogroup WWDG_Exported_Functions
  30. /// @{
  31. ////////////////////////////////////////////////////////////////////////////////
  32. /// @brief Deinitializes the WWDG peripheral registers to their default reset
  33. /// values.
  34. /// @param None.
  35. /// @retval None.
  36. ////////////////////////////////////////////////////////////////////////////////
  37. void WWDG_DeInit()
  38. {
  39. exRCC_APB1PeriphReset(RCC_APB1RSTR_WWDG);
  40. }
  41. ////////////////////////////////////////////////////////////////////////////////
  42. /// @brief Sets the WWDG Prescaler.
  43. /// @param WWDG_Prescaler: specifies the WWDG Prescaler.
  44. /// This parameter can be one of the following values:
  45. /// @arg WWDG_Prescaler_1: WWDG counter clock = APB1CLK / 4096 / 1
  46. /// @arg WWDG_Prescaler_2: WWDG counter clock = APB1CLK / 4096 / 2
  47. /// @arg WWDG_Prescaler_4: WWDG counter clock = APB1CLK / 4096 / 4
  48. /// @arg WWDG_Prescaler_8: WWDG counter clock = APB1CLK / 4096 / 8
  49. /// @retval None.
  50. ////////////////////////////////////////////////////////////////////////////////
  51. void WWDG_SetPrescaler(u32 prescaler)
  52. {
  53. WWDG->CFGR = (WWDG->CFGR & ~WWDG_CFGR_WDGTB) | prescaler;
  54. }
  55. ////////////////////////////////////////////////////////////////////////////////
  56. /// @brief Sets the WWDG window value.
  57. /// @param WindowValue: specifies the window value to be compared to the
  58. /// downcounter.
  59. /// This parameter value must be lower than 0x80.
  60. /// @retval None.
  61. ////////////////////////////////////////////////////////////////////////////////
  62. void WWDG_SetWindowValue(u8 window_value)
  63. {
  64. WWDG->CFGR = (WWDG->CFGR & ~WWDG_CFGR_WINDOW) | (window_value & WWDG_CFGR_WINDOW);
  65. }
  66. ////////////////////////////////////////////////////////////////////////////////
  67. /// @brief Enables the WWDG Early Wakeup interrupt(EWI).
  68. /// @note Once enabled this interrupt cannot be disabled except by a system
  69. /// reset.
  70. /// @param None.
  71. /// @retval None.
  72. ////////////////////////////////////////////////////////////////////////////////
  73. void WWDG_EnableIT()
  74. {
  75. WWDG->CFGR |= WWDG_CFGR_EWI;
  76. }
  77. ////////////////////////////////////////////////////////////////////////////////
  78. /// @brief Sets the WWDG counter value.
  79. /// @param Counter: specifies the watchdog counter value.
  80. /// This parameter must be a number between 0x40 and 0x7F (to prevent
  81. /// generating an immediate reset).
  82. /// @retval None.
  83. ////////////////////////////////////////////////////////////////////////////////
  84. void WWDG_SetCounter(u8 count)
  85. {
  86. WWDG->CR = count & WWDG_CFGR_WINDOW;
  87. }
  88. ////////////////////////////////////////////////////////////////////////////////
  89. /// @brief Enables WWDG and load the counter value.
  90. /// @param Counter: specifies the watchdog counter value.
  91. /// This parameter must be a number between 0x40 and 0x7F (to prevent
  92. /// generating an immediate reset).
  93. /// @retval None.
  94. ////////////////////////////////////////////////////////////////////////////////
  95. u32 WWDG_GetCounter()
  96. {
  97. return WWDG->CR & WWDG_CR_CNT;
  98. }
  99. ////////////////////////////////////////////////////////////////////////////////
  100. /// @brief Enables WWDG and load the counter value.
  101. /// @param Counter: specifies the watchdog counter value.
  102. /// This parameter must be a number between 0x40 and 0x7F (to prevent
  103. /// generating an immediate reset).
  104. /// @retval None.
  105. ////////////////////////////////////////////////////////////////////////////////
  106. void WWDG_Enable(u8 count)
  107. {
  108. WWDG->CR = WWDG_CR_WDGA | count;
  109. }
  110. ////////////////////////////////////////////////////////////////////////////////
  111. /// @brief Checks whether the Early Wakeup interrupt flag is set or not.
  112. /// @param None.
  113. /// @retval The new state of the Early Wakeup interrupt flag (SET or RESET).
  114. ////////////////////////////////////////////////////////////////////////////////
  115. FlagStatus WWDG_GetFlagStatus()
  116. {
  117. return WWDG->SR ? SET : RESET;
  118. }
  119. ////////////////////////////////////////////////////////////////////////////////
  120. /// @brief Clears Early Wakeup interrupt flag.
  121. /// @param None.
  122. /// @retval None.
  123. ////////////////////////////////////////////////////////////////////////////////
  124. void WWDG_ClearFlag()
  125. {
  126. WWDG->SR &= ~WWDG_SR_EWIF;
  127. }
  128. /// @}
  129. /// @}
  130. /// @}