1 /*! 2 * @file apm32f4xx_wwdt.c 3 * 4 * @brief This file contains all the functions for the WWDT peripheral 5 * 6 * @version V1.0.2 7 * 8 * @date 2022-06-23 9 * 10 * @attention 11 * 12 * Copyright (C) 2021-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 usefull 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 "apm32f4xx_wwdt.h" 27 #include "apm32f4xx_rcm.h" 28 29 /** @addtogroup APM32F4xx_StdPeriphDriver 30 @{ 31 */ 32 33 /** @defgroup WWDT_Driver 34 * @brief WWDT driver modules 35 @{ 36 */ 37 38 /** @defgroup WWDT_Functions 39 @{ 40 */ 41 42 /*! 43 * @brief Reset the WWDT peripheral registers to the default value. 44 * 45 * @param None 46 * 47 * @retval None 48 */ WWDT_Reset(void)49void WWDT_Reset(void) 50 { 51 RCM_EnableAPB1PeriphReset(RCM_APB1_PERIPH_WWDT); 52 RCM_DisableAPB1PeriphReset(RCM_APB1_PERIPH_WWDT); 53 } 54 55 /*! 56 * @brief Config the WWDT Timer Base Prescaler Factor. 57 * 58 * @param timebase: Specifies WWDT Prescaler 59 * The parameter can be one of following values: 60 * @arg WWDT_TIME_BASE_1 : WWDT counter clock = (PCLK1/4096)/1 61 * @arg WWDT_TIME_BASE_2 : WWDT counter clock = (PCLK1/4096)/2 62 * @arg WWDT_TIME_BASE_4 : WWDT counter clock = (PCLK1/4096)/4 63 * @arg WWDT_TIME_BASE_8 : WWDT counter clock = (PCLK1/4096)/8 64 * 65 * @retval None 66 */ WWDT_ConfigTimebase(WWDT_TIME_BASE_T timeBase)67void WWDT_ConfigTimebase(WWDT_TIME_BASE_T timeBase) 68 { 69 WWDT->CFG_B.TBPSC = timeBase; 70 } 71 72 /*! 73 * @brief Config the WWDT Window data 74 * 75 * @param windowdata: window data which compare with the downcounter 76 * 77 * @retval None 78 * 79 * @note The windowdata must be lower than 0x80 80 */ WWDT_ConfigWindowData(uint8_t windowData)81void WWDT_ConfigWindowData(uint8_t windowData) 82 { 83 WWDT->CFG_B.WIN = windowData; 84 } 85 86 /*! 87 * @brief Config the WWDT counter value 88 * 89 * @param counter: Specifies the watchdog counter value. 90 * 91 * @retval None 92 * 93 * @note The counter must be from 0x40 to 0x7F. 94 */ WWDT_ConfigCounter(uint8_t counter)95void WWDT_ConfigCounter(uint8_t counter) 96 { 97 WWDT->CTRL_B.CNT = counter; 98 } 99 100 /*! 101 * @brief Enable the WWDT Early Wakeup interrupt 102 * 103 * @param None 104 * 105 * @retval None 106 */ WWDT_EnableEWI(void)107void WWDT_EnableEWI(void) 108 { 109 WWDT->CFG_B.EWIEN = SET; 110 } 111 112 /*! 113 * @brief Enable WWDT and set the counter value 114 * 115 * @param counter: the window watchdog counter value 116 * 117 * @retval None 118 * 119 * @note The counter between 0x40 and 0x7F 120 */ WWDT_Enable(uint8_t counter)121void WWDT_Enable(uint8_t counter) 122 { 123 WWDT->CTRL = counter | 0x00000080; 124 } 125 126 /*! 127 * @brief Checks whether the Early Wakeup interrupt flag is set or not. 128 * 129 * @param None 130 * 131 * @retval SET or RESET 132 */ WWDT_ReadFlag(void)133uint8_t WWDT_ReadFlag(void) 134 { 135 return (WWDT->STS_B.EWIFLG); 136 } 137 138 /*! 139 * @brief Clear the Early Wakeup interrupt flag 140 * 141 * @param None 142 * 143 * @retval None 144 */ WWDT_ClearFlag(void)145void WWDT_ClearFlag(void) 146 { 147 WWDT->STS_B.EWIFLG = RESET; 148 149 } 150 151 /**@} end of group WWDT_Functions */ 152 /**@} end of group WWDT_Driver */ 153 /**@} end of group APM32F4xx_StdPeriphDriver */ 154