at32f413_bpr.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /**
  2. **************************************************************************
  3. * @file at32f413_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 "at32f413_conf.h"
  25. /** @addtogroup AT32F413_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 clear bpr tamper flag
  67. * @param flag: specifies the flag to clear.
  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 none
  72. */
  73. void bpr_flag_clear(uint32_t flag)
  74. {
  75. if(flag == BPR_TAMPER_INTERRUPT_FLAG)
  76. {
  77. BPR->ctrlsts_bit.tpifclr = TRUE;
  78. }
  79. else
  80. {
  81. BPR->ctrlsts_bit.tpefclr = TRUE;
  82. }
  83. }
  84. /**
  85. * @brief enable or disable bpr tamper interrupt
  86. * @param new_state (TRUE or FALSE)
  87. * @retval none
  88. */
  89. void bpr_interrupt_enable(confirm_state new_state)
  90. {
  91. BPR->ctrlsts_bit.tpien = new_state;
  92. }
  93. /**
  94. * @brief read bpr bpr data
  95. * @param bpr_data
  96. * this parameter can be one of the following values:
  97. * - BPR_DATA1
  98. * - BPR_DATA2
  99. * ...
  100. * - BPR_DATA41
  101. * - BPR_DATA42
  102. * @retval none
  103. */
  104. uint16_t bpr_data_read(bpr_data_type bpr_data)
  105. {
  106. return (*(__IO uint16_t *)(BPR_BASE + bpr_data));
  107. }
  108. /**
  109. * @brief write bpr data
  110. * @param bpr_data
  111. * this parameter can be one of the following values:
  112. * - BPR_DATA1
  113. * - BPR_DATA2
  114. * ...
  115. * - BPR_DATA41
  116. * - BPR_DATA42
  117. * @param data_value (0x0000~0xFFFF)
  118. * @retval none
  119. */
  120. void bpr_data_write(bpr_data_type bpr_data, uint16_t data_value)
  121. {
  122. (*(__IO uint32_t *)(BPR_BASE + bpr_data)) = data_value;
  123. }
  124. /**
  125. * @brief select bpr rtc output
  126. * @param output_source
  127. * this parameter can be one of the following values:
  128. * - BPR_RTC_OUTPUT_NONE: output disable.
  129. * - BPR_RTC_OUTPUT_CLOCK_CAL_BEFORE: output clock before calibration.
  130. * - BPR_RTC_OUTPUT_ALARM: output alarm event with pluse mode.
  131. * - BPR_RTC_OUTPUT_SECOND: output second event with pluse mode.
  132. * - BPR_RTC_OUTPUT_CLOCK_CAL_AFTER: output clock after calibration.
  133. * - BPR_RTC_OUTPUT_ALARM_TOGGLE: output alarm event with toggle mode.
  134. * - BPR_RTC_OUTPUT_SECOND_TOGGLE: output second event with toggle mode.
  135. * @retval none
  136. */
  137. void bpr_rtc_output_select(bpr_rtc_output_type output_source)
  138. {
  139. /* clear cco,asoe,asos,ccos,togen bits */
  140. BPR->rtccal &= (uint32_t)~0x0F80;
  141. /* set output_source value */
  142. BPR->rtccal |= output_source;
  143. }
  144. /**
  145. * @brief set rtc clock calibration value
  146. * @param calibration_value (0x00~0x7f)
  147. * @retval none
  148. */
  149. void bpr_rtc_clock_calibration_value_set(uint8_t calibration_value)
  150. {
  151. /* set rtc clock calibration value */
  152. BPR->rtccal_bit.calval= calibration_value;
  153. }
  154. /**
  155. * @brief enable or disable bpr tamper pin
  156. * @param new_state (TRUE or FALSE)
  157. * @retval none
  158. */
  159. void bpr_tamper_pin_enable(confirm_state new_state)
  160. {
  161. BPR->ctrl_bit.tpen = new_state;
  162. }
  163. /**
  164. * @brief set bpr tamper pin active level
  165. * @param active_level
  166. * this parameter can be one of the following values:
  167. * - BPR_TAMPER_PIN_ACTIVE_HIGH: tamper pin input active level is high.
  168. * - BPR_TAMPER_PIN_ACTIVE_LOW: tamper pin input active level is low.
  169. * @retval none
  170. */
  171. void bpr_tamper_pin_active_level_set(bpr_tamper_pin_active_level_type active_level)
  172. {
  173. BPR->ctrl_bit.tpp = active_level;
  174. }
  175. /**
  176. * @}
  177. */
  178. #endif
  179. /**
  180. * @}
  181. */
  182. /**
  183. * @}
  184. */