apm32f10x_bakpr.c 5.9 KB

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