stm8s_wwdg.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /**
  2. ********************************************************************************
  3. * @file stm8s_wwdg.c
  4. * @author MCD Application Team
  5. * @version V2.3.0
  6. * @date 16-June-2017
  7. * @brief This file contains all the functions for the WWDG peripheral.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2>
  12. *
  13. * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  14. * You may not use this file except in compliance with the License.
  15. * You may obtain a copy of the License at:
  16. *
  17. * http://www.st.com/software_license_agreement_liberty_v2
  18. *
  19. * Unless required by applicable law or agreed to in writing, software
  20. * distributed under the License is distributed on an "AS IS" BASIS,
  21. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  22. * See the License for the specific language governing permissions and
  23. * limitations under the License.
  24. *
  25. ******************************************************************************
  26. */
  27. /* Includes ------------------------------------------------------------------*/
  28. #include "stm8s_wwdg.h"
  29. /** @addtogroup STM8S_StdPeriph_Driver
  30. * @{
  31. */
  32. /* Private define ------------------------------------------------------------*/
  33. #define BIT_MASK ((uint8_t)0x7F)
  34. /* Private macro -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private function prototypes -----------------------------------------------*/
  37. /* Private functions ---------------------------------------------------------*/
  38. /** @addtogroup WWDG_Public_Functions
  39. * @{
  40. */
  41. /**
  42. * @brief Initializes the WWDG peripheral.
  43. * This function set Window Register = WindowValue, Counter Register
  44. * according to Counter and \b ENABLE \b WWDG
  45. * @param Counter : WWDG counter value
  46. * @param WindowValue : specifies the WWDG Window Register, range is 0x00 to 0x7F.
  47. * @retval None
  48. */
  49. void WWDG_Init(uint8_t Counter, uint8_t WindowValue)
  50. {
  51. /* Check the parameters */
  52. assert_param(IS_WWDG_WINDOWLIMITVALUE_OK(WindowValue));
  53. WWDG->WR = WWDG_WR_RESET_VALUE;
  54. WWDG->CR = (uint8_t)((uint8_t)(WWDG_CR_WDGA | WWDG_CR_T6) | (uint8_t)Counter);
  55. WWDG->WR = (uint8_t)((uint8_t)(~WWDG_CR_WDGA) & (uint8_t)(WWDG_CR_T6 | WindowValue));
  56. }
  57. /**
  58. * @brief Refreshes the WWDG peripheral.
  59. * @param Counter : WWDG Counter Value
  60. * This parameter must be a number between 0x40 and 0x7F.
  61. * @retval None
  62. */
  63. void WWDG_SetCounter(uint8_t Counter)
  64. {
  65. /* Check the parameters */
  66. assert_param(IS_WWDG_COUNTERVALUE_OK(Counter));
  67. /* Write to T[6:0] bits to configure the counter value, no need to do
  68. a read-modify-write; writing a 0 to WDGA bit does nothing */
  69. WWDG->CR = (uint8_t)(Counter & (uint8_t)BIT_MASK);
  70. }
  71. /**
  72. * @brief Gets the WWDG Counter Value.
  73. * This value could be used to check if WWDG is in the window, where
  74. * refresh is allowed.
  75. * @param None
  76. * @retval WWDG Counter Value
  77. */
  78. uint8_t WWDG_GetCounter(void)
  79. {
  80. return(WWDG->CR);
  81. }
  82. /**
  83. * @brief Generates immediate WWDG RESET.
  84. * @param None
  85. * @retval None
  86. */
  87. void WWDG_SWReset(void)
  88. {
  89. WWDG->CR = WWDG_CR_WDGA; /* Activate WWDG, with clearing T6 */
  90. }
  91. /**
  92. * @brief Sets the WWDG window value.
  93. * @param WindowValue: specifies the window value to be compared to the
  94. * downcounter.
  95. * This parameter value must be lower than 0x80.
  96. * @retval None
  97. */
  98. void WWDG_SetWindowValue(uint8_t WindowValue)
  99. {
  100. /* Check the parameters */
  101. assert_param(IS_WWDG_WINDOWLIMITVALUE_OK(WindowValue));
  102. WWDG->WR = (uint8_t)((uint8_t)(~WWDG_CR_WDGA) & (uint8_t)(WWDG_CR_T6 | WindowValue));
  103. }
  104. /**
  105. * @}
  106. */
  107. /**
  108. * @}
  109. */
  110. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/