1 /*! 2 * @file apm32f10x_bakpr.c 3 * 4 * @brief This file provides all the BAKPR firmware functions. 5 * 6 * @version V1.0.4 7 * 8 * @date 2022-12-01 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 "apm32f10x_bakpr.h" 27 #include "apm32f10x_rcm.h" 28 29 /** @addtogroup APM32F10x_StdPeriphDriver 30 @{ 31 */ 32 33 /** @addtogroup BAKPR_Driver BAKPR Driver 34 * @brief BAKPR driver modules 35 @{ 36 */ 37 38 /** @defgroup BAKPR_Functions Functions 39 @{ 40 */ 41 42 /*! 43 * @brief Reset the BAKPR peripheral registers to their default reset values. 44 * 45 * @param None 46 * 47 * @retval None 48 */ BAKPR_Reset(void)49void BAKPR_Reset(void) 50 { 51 RCM_EnableBackupReset(); 52 RCM_DisableBackupReset(); 53 } 54 55 /*! 56 * @brief Deinitializes the BAKPR peripheral registers to their default reset values. 57 * 58 * @param value: specifies the RTC output source. 59 * This parameter can be one of the following values: 60 * @arg BAKPR_TAMPER_PIN_LEVEL_HIGH: Tamper pin active on high level 61 * @arg BAKPR_TAMPER_PIN_LEVEL_LOW: Tamper pin active on low level 62 * 63 * @retval None 64 */ BAKPR_ConfigTamperPinLevel(BAKPR_TAMPER_PIN_LEVEL_T value)65void BAKPR_ConfigTamperPinLevel(BAKPR_TAMPER_PIN_LEVEL_T value) 66 { 67 BAKPR->CTRL_B.TPALCFG = value; 68 } 69 70 /*! 71 * @brief Enables the Tamper Pin activation. 72 * 73 * @param None 74 * 75 * @retval None 76 */ BAKPR_EnableTamperPin(void)77void BAKPR_EnableTamperPin(void) 78 { 79 BAKPR->CTRL_B.TPFCFG = ENABLE ; 80 } 81 82 /*! 83 * @brief Disables the Tamper Pin activation. 84 * 85 * @param None 86 * 87 * @retval None 88 */ BAKPR_DisableTamperPin(void)89void BAKPR_DisableTamperPin(void) 90 { 91 BAKPR->CTRL_B.TPFCFG = DISABLE ; 92 } 93 94 /*! 95 * @brief Enables the Tamper Pin Interrupt. 96 * 97 * @param None 98 * 99 * @retval None 100 */ BAKPR_EnableInterrupt(void)101void BAKPR_EnableInterrupt(void) 102 { 103 BAKPR->CSTS_B.TPIEN = ENABLE ; 104 } 105 106 /*! 107 * @brief Disables the Tamper Pin Interrupt. 108 * 109 * @param None 110 * 111 * @retval None 112 */ BAKPR_DisableInterrupt(void)113void BAKPR_DisableInterrupt(void) 114 { 115 BAKPR->CSTS_B.TPIEN = DISABLE ; 116 } 117 118 /*! 119 * @brief Select the RTC output source to output on the Tamper pin. 120 * 121 * @param soure: specifies the RTC output source. 122 * This parameter can be one of the following values: 123 * @arg BAKPR_RTC_OUTPUT_SOURCE_NONE : no RTC output on the Tamper pin. 124 * @arg BAKPR_RTC_OUTPUT_SOURCE_CALIBRATION_CLOCK: output the RTC clock with frequency divided by 64 on the Tamper pin. 125 * @arg BAKPR_RTC_OUTPUT_SOURCE_ALARM : output the RTC Alarm pulse signal on the Tamper pin. 126 * @arg BAKPR_RTC_OUTPUT_SOURCE_SECOND : output the RTC Second pulse signal on the Tamper pin. 127 * 128 * @retval None 129 */ BAKPR_ConfigRTCOutput(BAKPR_RTC_OUTPUT_SOURCE_T soure)130void BAKPR_ConfigRTCOutput(BAKPR_RTC_OUTPUT_SOURCE_T soure) 131 { 132 if (soure == BAKPR_RTC_OUTPUT_SOURCE_NONE) 133 { 134 BAKPR->CLKCAL = RESET; 135 } 136 else if (soure == BAKPR_RTC_OUTPUT_SOURCE_CALIBRATION_CLOCK) 137 { 138 BAKPR->CLKCAL_B.CALCOEN = BIT_SET; 139 } 140 else if (soure == BAKPR_RTC_OUTPUT_SOURCE_ALARM) 141 { 142 BAKPR->CLKCAL_B.ASPOEN = BIT_SET; 143 } 144 else if (soure == BAKPR_RTC_OUTPUT_SOURCE_SECOND) 145 { 146 BAKPR->CLKCAL_B.ASPOSEL = BIT_SET; 147 } 148 } 149 150 /*! 151 * @brief Sets RTC Clock Calibration value. 152 * 153 * @param calibrationValue: Specifies the calibration value. 154 * This parameter must be a number between 0 and 0x7F. 155 * 156 * @retval None 157 */ BAKPR_ConfigRTCCalibrationValue(uint8_t calibrationValue)158void BAKPR_ConfigRTCCalibrationValue(uint8_t calibrationValue) 159 { 160 BAKPR->CLKCAL_B.CALVALUE = calibrationValue; 161 } 162 163 /*! 164 * @brief Set user data to the specified Data Backup Register. 165 * 166 * @param bakrData : specifies the Data Backup Register. 167 * This parameter can be BAKPR_DATAx where x is between 1 and 42. 168 * 169 * @param data : data to set 170 * This parameter can be a 16bit value. 171 * 172 * @retval None 173 */ BAKPR_ConfigBackupRegister(BAKPR_DATA_T bakrData,uint16_t data)174void BAKPR_ConfigBackupRegister(BAKPR_DATA_T bakrData, uint16_t data) 175 { 176 __IOM uint32_t tmp = 0; 177 178 tmp = (uint32_t)BAKPR_BASE; 179 tmp += bakrData; 180 181 *(__IOM uint32_t*) tmp = data; 182 } 183 184 /*! 185 * @brief Reads user data from the specified Data Backup Register. 186 * 187 * @param bakrData : specifies the Data Backup Register. 188 * This parameter can be BAKPR_DATAx where x is between 1 and 42. 189 * 190 * @retval The content of the specified Data Backup Register 191 */ BAKPR_ReadBackupRegister(BAKPR_DATA_T bakrData)192uint16_t BAKPR_ReadBackupRegister(BAKPR_DATA_T bakrData) 193 { 194 __IOM uint32_t tmp = 0; 195 196 tmp = (uint32_t)BAKPR_BASE; 197 tmp += bakrData; 198 199 return (*(__IOM uint32_t*) tmp); 200 } 201 202 /*! 203 * @brief Read whether the Tamper Pin Event flag is set or not. 204 * 205 * @param None 206 * 207 * @retval Tamper Pin Event flag state 208 */ BAKPR_ReadStatusFlag(void)209uint8_t BAKPR_ReadStatusFlag(void) 210 { 211 return BAKPR->CSTS_B.TEFLG; 212 } 213 214 /*! 215 * @brief Clears Tamper Pin Event pending flag. 216 * 217 * @param None 218 * 219 * @retval None 220 */ BAKPR_ClearStatusFlag(void)221void BAKPR_ClearStatusFlag(void) 222 { 223 BAKPR->CSTS_B.TECLR = BIT_SET; 224 } 225 226 /*! 227 * @brief Get whether the Tamper Pin Interrupt has occurred or not. 228 * 229 * @param None 230 * 231 * @retval Tamper Pin Interrupt State 232 */ BAKPR_ReadIntFlag(void)233uint8_t BAKPR_ReadIntFlag(void) 234 { 235 return BAKPR->CSTS_B.TIFLG; 236 } 237 238 /*! 239 * @brief Clears Tamper Pin Interrupt pending bit. 240 * 241 * @param None 242 * 243 * @retval None 244 */ BAKPR_ClearIntFlag(void)245void BAKPR_ClearIntFlag(void) 246 { 247 BAKPR->CSTS_B.TICLR = BIT_SET; 248 } 249 250 /**@} end of group BAKPR_Functions*/ 251 /**@} end of group BAKPR_Driver*/ 252 /**@} end of group APM32F10x_StdPeriphDriver */ 253