1 /*! 2 * @file apm32s10x_iwdt.c 3 * 4 * @brief This file provides all the IWDT firmware functions 5 * 6 * @version V1.0.1 7 * 8 * @date 2022-12-31 9 * 10 * @attention 11 * 12 * Copyright (C) 2022-2023 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 /* Includes */ 27 #include "apm32s10x_iwdt.h" 28 29 /** @addtogroup APM32S10x_StdPeriphDriver 30 @{ 31 */ 32 33 /** @addtogroup IWDT_Driver IWDT Driver 34 @{ 35 */ 36 37 /** @defgroup IWDT_Functions Functions 38 @{ 39 */ 40 41 /*! 42 * @brief Enable IWDT 43 * 44 * @param None 45 * 46 * @retval None 47 */ IWDT_Enable(void)48void IWDT_Enable(void) 49 { 50 IWDT->KEY = IWDT_KEYWORD_ENABLE; 51 } 52 53 /*! 54 * @brief Reload the IWDT counter with value 55 * 56 * @param None 57 * 58 * @retval None 59 */ IWDT_Refresh(void)60void IWDT_Refresh(void) 61 { 62 IWDT->KEY = IWDT_KEYWORD_RELOAD; 63 } 64 65 /*! 66 * @brief Set IWDT count reload values 67 * 68 * @param reload: IWDT count reload values 69 * 70 * @retval None 71 */ IWDT_ConfigReload(uint16_t reload)72void IWDT_ConfigReload(uint16_t reload) 73 { 74 IWDT->CNTRLD = reload; 75 } 76 77 /*! 78 * @brief Enable the IWDT write access 79 * 80 * @param None 81 * 82 * @retval None 83 */ IWDT_EnableWriteAccess(void)84void IWDT_EnableWriteAccess(void) 85 { 86 IWDT->KEY_B.KEY = IWDT_WRITEACCESS_ENABLE; 87 } 88 89 /*! 90 * @brief Disable the IWDT write access 91 * 92 * @param None 93 * 94 * @retval None 95 */ IWDT_DisableWriteAccess(void)96void IWDT_DisableWriteAccess(void) 97 { 98 IWDT->KEY_B.KEY = IWDT_WRITEACCESS_DISABLE; 99 } 100 101 /*! 102 * @brief Set IWDT frequency divider values 103 * 104 * @param div: IWDT frequency divider values 105 * This parameter can be one of the following values: 106 * @arg IWDT_DIVIDER_4 : prescaler divider equal to 4 107 * @arg IWDT_DIVIDER_8 : prescaler divider equal to 8 108 * @arg IWDT_DIVIDER_16 : prescaler divider equal to 16 109 * @arg IWDT_DIVIDER_32 : prescaler divider equal to 32 110 * @arg IWDT_DIVIDER_64 : prescaler divider equal to 64 111 * @arg IWDT_DIVIDER_128: prescaler divider equal to 128 112 * @arg IWDT_DIVIDER_256: prescaler divider equal to 256 113 * 114 * @retval None 115 */ IWDT_ConfigDivider(uint8_t div)116void IWDT_ConfigDivider(uint8_t div) 117 { 118 IWDT->PSC = div; 119 } 120 121 /*! 122 * @brief Read the specified IWDT flag 123 * 124 * @param flag: specifies the flag to read 125 * This parameter can be one of the following values: 126 * @arg IWDT_FLAG_PSCU : Watchdog Prescaler Factor Update flag 127 * @arg IWDT_FLAG_CNTU : Watchdog Counter Reload Value Update flag 128 * 129 * @retval status of IWDT_FLAG (SET or RESET) 130 */ IWDT_ReadStatusFlag(uint16_t flag)131uint8_t IWDT_ReadStatusFlag(uint16_t flag) 132 { 133 uint8_t bitStatus = RESET; 134 135 if ((IWDT->STS & flag) != (uint32_t)RESET) 136 { 137 bitStatus = SET; 138 } 139 else 140 { 141 bitStatus = RESET; 142 } 143 return bitStatus; 144 } 145 146 /**@} end of group IWDT_Functions */ 147 /**@} end of group IWDT_Driver */ 148 /**@} end of group APM32S10x_StdPeriphDriver */ 149