1 /*! 2 * @file apm32f0xx_wwdt.c 3 * 4 * @brief This file contains all the functions for the WWDG peripheral 5 * 6 * @version V1.0.3 7 * 8 * @date 2022-09-20 9 * 10 * @attention 11 * 12 * Copyright (C) 2020-2022 Geehy Semiconductor 13 * 14 * You may not use this file except in compliance with the 15 * GEEHY COPYRIGHT NOTICE (GEEHY SOFTWARE PACKAGE LICENSE). 16 * 17 * The program is only for reference, which is distributed in the hope 18 * that it will be useful and instructional for customers to develop 19 * their software. Unless required by applicable law or agreed to in 20 * writing, the program is distributed on an "AS IS" BASIS, WITHOUT 21 * ANY WARRANTY OR CONDITIONS OF ANY KIND, either express or implied. 22 * See the GEEHY SOFTWARE PACKAGE LICENSE for the governing permissions 23 * and limitations under the License. 24 */ 25 26 #include "apm32f0xx_wwdt.h" 27 #include "apm32f0xx_rcm.h" 28 29 /** @addtogroup APM32F0xx_StdPeriphDriver 30 @{ 31 */ 32 33 /** @addtogroup WWDT_Driver WWDT Driver 34 @{ 35 */ 36 37 /** @defgroup WWDT_Macros Macros 38 @{ 39 */ 40 41 /**@} end of group WWDT_Macros */ 42 43 /** @defgroup WWDT_Enumerations Enumerations 44 @{ 45 */ 46 47 /**@} end of group WWDT_Enumerations */ 48 49 /** @defgroup WWDT_Structures Structures 50 @{ 51 */ 52 53 /**@} end of group WWDT_Structures */ 54 55 /** @defgroup WWDT_Variables Variables 56 @{ 57 */ 58 59 /**@} end of group WWDT_Variables */ 60 61 /** @defgroup WWDT_Functions Functions 62 @{ 63 */ 64 65 /*! 66 * @brief Set the WWDT peripheral registers to their default reset values 67 * 68 * @param None 69 70 * @retval None 71 */ WWDT_Reset(void)72void WWDT_Reset(void) 73 { 74 RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_WWDT); 75 RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_WWDT); 76 } 77 78 /*! 79 * @brief Set the WWDT Timebase 80 * 81 * @param timebase: WWDT Prescaler 82 * The parameter can be one of following values: 83 * @arg WWDT_DIV_1: WWDT counter clock = (PCLK1/4096)/1 84 * @arg WWDT_DIV_2: WWDT counter clock = (PCLK1/4096)/2 85 * @arg WWDT_DIV_4: WWDT counter clock = (PCLK1/4096)/4 86 * @arg WWDT_DIV_8: WWDT counter clock = (PCLK1/4096)/8 87 * 88 * @retval None 89 */ WWDT_SetTimebase(uint32_t div)90void WWDT_SetTimebase(uint32_t div) 91 { 92 WWDT->CFG_B.TBPSC = 0; 93 WWDT->CFG_B.TBPSC = div; 94 } 95 96 /*! 97 * @brief Set the Window data 98 * 99 * @param data: Specifies the window data to be set 100 * 101 * @retval None 102 */ WWDT_ConfigWindowValue(uint16_t windowValue)103void WWDT_ConfigWindowValue(uint16_t windowValue) 104 { 105 uint32_t reg; 106 107 reg = (windowValue | BIT6) & 0x7f; 108 109 WWDT->CFG_B.WIN = reg; 110 } 111 112 /*! 113 * @brief Enable the WWDT Early Wakeup interrupt 114 * 115 * @param None 116 * 117 * @retval None 118 */ WWDT_EnableEWI(void)119void WWDT_EnableEWI(void) 120 { 121 WWDT->CFG_B.EWIEN = SET; 122 } 123 124 /*! 125 * @brief Set counter 126 * 127 * @param couter: Specifies the counter to be set 128 * 129 * @retval None 130 */ WWDT_ConfigCounter(uint8_t couter)131void WWDT_ConfigCounter(uint8_t couter) 132 { 133 WWDT->CTRL = (uint32_t)(couter & 0x7f); 134 } 135 136 /*! 137 * @brief Enable WWDT and set the counter value 138 * 139 * @param count: the window watchdog counter value 140 * 141 * @retval None 142 */ WWDT_Enable(uint8_t count)143void WWDT_Enable(uint8_t count) 144 { 145 WWDT->CTRL_B.CNT = count; 146 WWDT->CTRL_B.WWDTEN = SET; 147 } 148 149 /*! 150 * @brief Read the Early Wakeup interrupt flag 151 * 152 * @param None 153 * 154 * @retval the state of the Early Wakeup interrupt flag 155 */ WWDT_ReadStatusFlag(void)156uint8_t WWDT_ReadStatusFlag(void) 157 { 158 return (uint8_t)(WWDT->STS); 159 } 160 161 /*! 162 * @brief Clear the Early Wakeup interrupt flag 163 * 164 * @param None 165 * 166 * @retval None 167 */ WWDT_ClearStatusFlag(void)168void WWDT_ClearStatusFlag(void) 169 { 170 WWDT->STS_B.EWIFLG = RESET; 171 } 172 173 /**@} end of group WWDT_Functions*/ 174 /**@} end of group WWDT_Driver */ 175 /**@} end of group APM32F0xx_StdPeriphDriver*/ 176