at32f403a_407_bpr.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /**
  2. **************************************************************************
  3. * @file at32f403a_407_bpr.c
  4. * @brief contains all the functions for the bpr firmware library
  5. **************************************************************************
  6. * Copyright notice & Disclaimer
  7. *
  8. * The software Board Support Package (BSP) that is made available to
  9. * download from Artery official website is the copyrighted work of Artery.
  10. * Artery authorizes customers to use, copy, and distribute the BSP
  11. * software and its related documentation for the purpose of design and
  12. * development in conjunction with Artery microcontrollers. Use of the
  13. * software is governed by this copyright notice and the following disclaimer.
  14. *
  15. * THIS SOFTWARE IS PROVIDED ON "AS IS" BASIS WITHOUT WARRANTIES,
  16. * GUARANTEES OR REPRESENTATIONS OF ANY KIND. ARTERY EXPRESSLY DISCLAIMS,
  17. * TO THE FULLEST EXTENT PERMITTED BY LAW, ALL EXPRESS, IMPLIED OR
  18. * STATUTORY OR OTHER WARRANTIES, GUARANTEES OR REPRESENTATIONS,
  19. * INCLUDING BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT.
  21. *
  22. **************************************************************************
  23. */
  24. #include "at32f403a_407_conf.h"
  25. /** @addtogroup AT32F403A_407_periph_driver
  26. * @{
  27. */
  28. /** @defgroup BPR
  29. * @brief BPR driver modules
  30. * @{
  31. */
  32. #ifdef BPR_MODULE_ENABLED
  33. /** @defgroup BPR_private_functions
  34. * @{
  35. */
  36. /**
  37. * @brief bpr reset by crm reset register
  38. * @param none
  39. * @retval none
  40. */
  41. void bpr_reset(void)
  42. {
  43. crm_battery_powered_domain_reset(TRUE);
  44. crm_battery_powered_domain_reset(FALSE);
  45. }
  46. /**
  47. * @brief bpr event flag get, for tamper event flag
  48. * @param flag: specifies the flag to check.
  49. * this parameter can be one of the following values:
  50. * - BPR_TAMPER_INTERRUPT_FLAG: tamper interrupt flag
  51. * - BPR_TAMPER_EVENT_FLAG: tamper event flag
  52. * @retval state of tamper event flag
  53. */
  54. flag_status bpr_flag_get(uint32_t flag)
  55. {
  56. if(flag == BPR_TAMPER_INTERRUPT_FLAG)
  57. {
  58. return (flag_status)(BPR->ctrlsts_bit.tpif);
  59. }
  60. else
  61. {
  62. return (flag_status)(BPR->ctrlsts_bit.tpef);
  63. }
  64. }
  65. /**
  66. * @brief bpr interrupt flag get
  67. * @param flag: specifies the flag to check.
  68. * this parameter can be one of the following values:
  69. * - BPR_TAMPER_INTERRUPT_FLAG: tamper interrupt flag
  70. * - BPR_TAMPER_EVENT_FLAG: tamper event flag
  71. * @retval state of tamper event flag
  72. */
  73. flag_status bpr_interrupt_flag_get(uint32_t flag)
  74. {
  75. if(flag == BPR_TAMPER_INTERRUPT_FLAG)
  76. {
  77. return (flag_status)(BPR->ctrlsts_bit.tpif && BPR->ctrlsts_bit.tpien);
  78. }
  79. else
  80. {
  81. return (flag_status)(BPR->ctrlsts_bit.tpef && BPR->ctrlsts_bit.tpien);
  82. }
  83. }
  84. /**
  85. * @brief clear bpr tamper flag
  86. * @param flag: specifies the flag to clear.
  87. * this parameter can be one of the following values:
  88. * - BPR_TAMPER_INTERRUPT_FLAG: tamper interrupt flag
  89. * - BPR_TAMPER_EVENT_FLAG: tamper event flag
  90. * @retval none
  91. */
  92. void bpr_flag_clear(uint32_t flag)
  93. {
  94. if(flag == BPR_TAMPER_INTERRUPT_FLAG)
  95. {
  96. BPR->ctrlsts_bit.tpifclr = TRUE;
  97. }
  98. else
  99. {
  100. BPR->ctrlsts_bit.tpefclr = TRUE;
  101. }
  102. }
  103. /**
  104. * @brief enable or disable bpr tamper interrupt
  105. * @param new_state (TRUE or FALSE)
  106. * @retval none
  107. */
  108. void bpr_interrupt_enable(confirm_state new_state)
  109. {
  110. BPR->ctrlsts_bit.tpien = new_state;
  111. }
  112. /**
  113. * @brief read bpr bpr data
  114. * @param bpr_data
  115. * this parameter can be one of the following values:
  116. * - BPR_DATA1
  117. * - BPR_DATA2
  118. * ...
  119. * - BPR_DATA41
  120. * - BPR_DATA42
  121. * @retval none
  122. */
  123. uint16_t bpr_data_read(bpr_data_type bpr_data)
  124. {
  125. return (*(__IO uint16_t *)(BPR_BASE + bpr_data));
  126. }
  127. /**
  128. * @brief write bpr data
  129. * @param bpr_data
  130. * this parameter can be one of the following values:
  131. * - BPR_DATA1
  132. * - BPR_DATA2
  133. * ...
  134. * - BPR_DATA41
  135. * - BPR_DATA42
  136. * @param data_value (0x0000~0xFFFF)
  137. * @retval none
  138. */
  139. void bpr_data_write(bpr_data_type bpr_data, uint16_t data_value)
  140. {
  141. (*(__IO uint32_t *)(BPR_BASE + bpr_data)) = data_value;
  142. }
  143. /**
  144. * @brief select bpr rtc output
  145. * @param output_source
  146. * this parameter can be one of the following values:
  147. * - BPR_RTC_OUTPUT_NONE: output disable.
  148. * - BPR_RTC_OUTPUT_CLOCK_CAL_BEFORE: output clock before calibration.
  149. * - BPR_RTC_OUTPUT_ALARM: output alarm event with pluse mode.
  150. * - BPR_RTC_OUTPUT_SECOND: output second event with pluse mode.
  151. * - BPR_RTC_OUTPUT_CLOCK_CAL_AFTER: output clock after calibration.
  152. * - BPR_RTC_OUTPUT_ALARM_TOGGLE: output alarm event with toggle mode.
  153. * - BPR_RTC_OUTPUT_SECOND_TOGGLE: output second event with toggle mode.
  154. * @retval none
  155. */
  156. void bpr_rtc_output_select(bpr_rtc_output_type output_source)
  157. {
  158. /* clear cco,asoe,asos,ccos,togen bits */
  159. BPR->rtccal &= (uint32_t)~0x0F80;
  160. /* set output_source value */
  161. BPR->rtccal |= output_source;
  162. }
  163. /**
  164. * @brief set rtc clock calibration value
  165. * @param calibration_value (0x00~0x7f)
  166. * @retval none
  167. */
  168. void bpr_rtc_clock_calibration_value_set(uint8_t calibration_value)
  169. {
  170. /* set rtc clock calibration value */
  171. BPR->rtccal_bit.calval= calibration_value;
  172. }
  173. /**
  174. * @brief enable or disable bpr tamper pin
  175. * @param new_state (TRUE or FALSE)
  176. * @retval none
  177. */
  178. void bpr_tamper_pin_enable(confirm_state new_state)
  179. {
  180. BPR->ctrl_bit.tpen = new_state;
  181. }
  182. /**
  183. * @brief set bpr tamper pin active level
  184. * @param active_level
  185. * this parameter can be one of the following values:
  186. * - BPR_TAMPER_PIN_ACTIVE_HIGH: tamper pin input active level is high.
  187. * - BPR_TAMPER_PIN_ACTIVE_LOW: tamper pin input active level is low.
  188. * @retval none
  189. */
  190. void bpr_tamper_pin_active_level_set(bpr_tamper_pin_active_level_type active_level)
  191. {
  192. BPR->ctrl_bit.tpp = active_level;
  193. }
  194. /**
  195. * @}
  196. */
  197. #endif
  198. /**
  199. * @}
  200. */
  201. /**
  202. * @}
  203. */