ald_bkpc.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /**
  2. *********************************************************************************
  3. *
  4. * @file ald_bkpc.c
  5. * @brief BKPC module driver.
  6. *
  7. * @version V1.0
  8. * @date 15 Dec 2017
  9. * @author AE Team
  10. * @note
  11. *
  12. * Copyright (C) Shanghai Eastsoft Microelectronics Co. Ltd. All rights reserved.
  13. *
  14. *********************************************************************************
  15. */
  16. #include "ald_bkpc.h"
  17. #include "ald_rtc.h"
  18. /** @addtogroup ES32FXXX_ALD
  19. * @{
  20. */
  21. /** @defgroup BKPC BKPC
  22. * @brief BKPC module driver
  23. * @{
  24. */
  25. #ifdef ALD_BKPC
  26. /** @defgroup BKPC_Public_Functions BKPC Public Functions
  27. * @{
  28. */
  29. /** @addtogroup BKPC_Public_Functions_Group1 Peripheral Control functions
  30. * @brief Peripheral Control functions
  31. *
  32. * @verbatim
  33. ==============================================================================
  34. ##### Peripheral Control functions #####
  35. ==============================================================================
  36. [..] This section provides functions allowing to:
  37. (+) bkpc_ldo_config() API can configure LDO in backup field.
  38. (+) bkpc_bor_config() API can configure BOR in backup field.
  39. @endverbatim
  40. * @{
  41. */
  42. /**
  43. * @brief Configure ldo in backup field
  44. * @param output: Output voltage select.
  45. * @param state: DISABLE/ENABLE.
  46. * @retval None
  47. */
  48. void bkpc_ldo_config(bkpc_ldo_output_t output, type_func_t state)
  49. {
  50. assert_param(IS_BKPC_LDO_OUTPUT(output));
  51. assert_param(IS_FUNC_STATE(state));
  52. BKPC_UNLOCK();
  53. MODIFY_REG(BKPC->CR, BKPC_CR_MT_STDB_MSK, state << BKPC_CR_MT_STDB_POS);
  54. if (state)
  55. MODIFY_REG(BKPC->CR, BKPC_CR_LDO_VSEL_MSK, output << BKPC_CR_LDO_VSEL_POSS);
  56. BKPC_LOCK();
  57. return;
  58. }
  59. /**
  60. * @brief Configure bor voltage in backup field
  61. * @param vol: Voltage select.
  62. * @param state: DISABLE/ENABLE.
  63. * @retval None
  64. */
  65. void bkpc_bor_config(bkpc_bor_vol_t vol, type_func_t state)
  66. {
  67. assert_param(IS_BKPC_BOR_VOL(vol));
  68. assert_param(IS_FUNC_STATE(state));
  69. BKPC_UNLOCK();
  70. MODIFY_REG(BKPC->PCR, BKPC_PCR_BOREN_MSK, state << BKPC_PCR_BOREN_POS);
  71. if (state)
  72. MODIFY_REG(BKPC->PCR, BKPC_PCR_BORS_MSK, vol << BKPC_PCR_BORS_POSS);
  73. BKPC_LOCK();
  74. return;
  75. }
  76. /**
  77. * @}
  78. */
  79. /** @addtogroup BKPC_Public_Functions_Group2 IO operation functions
  80. * @brief IO operation functions
  81. *
  82. * @verbatim
  83. ==============================================================================
  84. ##### IO operation functions #####
  85. ==============================================================================
  86. [..] This section provides functions allowing to:
  87. (+) bkpc_write_ram() API can write data in backup ram.
  88. (+) bkpc_read_ram() API can read data from backup ram.
  89. @endverbatim
  90. * @{
  91. */
  92. /**
  93. * @brief Write data into backup ram.
  94. * @param idx: Index of backup word.
  95. * @param value: Value which will be written to backup ram.
  96. * @retval None
  97. */
  98. void bkpc_write_ram(uint8_t idx, uint32_t value)
  99. {
  100. assert_param(IS_BKPC_RAM_IDX(idx));
  101. RTC_UNLOCK();
  102. WRITE_REG(RTC->BKPR[idx], value);
  103. RTC_LOCK();
  104. return;
  105. }
  106. /**
  107. * @brief Read data from backup ram.
  108. * @param idx: Index of backup word.
  109. * @retval The data.
  110. */
  111. uint32_t bkpc_read_ram(uint8_t idx)
  112. {
  113. assert_param(IS_BKPC_RAM_IDX(idx));
  114. return READ_REG(RTC->BKPR[idx]);
  115. }
  116. /**
  117. * @}
  118. */
  119. /**
  120. * @}
  121. */
  122. #endif /* ALD_BKPC */
  123. /**
  124. * @}
  125. */
  126. /**
  127. * @}
  128. */