n32g45x_bkp.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*****************************************************************************
  2. * Copyright (c) 2019, Nations Technologies Inc.
  3. *
  4. * All rights reserved.
  5. * ****************************************************************************
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. *
  10. * - Redistributions of source code must retain the above copyright notice,
  11. * this list of conditions and the disclaimer below.
  12. *
  13. * Nations' name may not be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. *
  16. * DISCLAIMER: THIS SOFTWARE IS PROVIDED BY NATIONS "AS IS" AND ANY EXPRESS OR
  17. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  19. * DISCLAIMED. IN NO EVENT SHALL NATIONS BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  21. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  22. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  23. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  24. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  25. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. * ****************************************************************************/
  27. /**
  28. * @file n32g45x_bkp.c
  29. * @author Nations
  30. * @version v1.0.0
  31. *
  32. * @copyright Copyright (c) 2019, Nations Technologies Inc. All rights reserved.
  33. */
  34. #include "n32g45x_bkp.h"
  35. /** @addtogroup N32G45X_StdPeriph_Driver
  36. * @{
  37. */
  38. /** @addtogroup BKP
  39. * @brief BKP driver modules
  40. * @{
  41. */
  42. /** @addtogroup BKP_Private_TypesDefinitions
  43. * @{
  44. */
  45. /**
  46. * @}
  47. */
  48. /** @addtogroup BKP_Private_Defines
  49. * @{
  50. */
  51. /* ------------ BKP registers bit address in the alias region --------------- */
  52. #define BKP_OFFSET (BKP_BASE - PERIPH_BASE)
  53. /* --- CTRL Register ----*/
  54. /* Alias word address of TP_ALEV bit */
  55. #define CTRL_OFFSET (BKP_OFFSET + 0x30)
  56. #define TP_ALEV_BIT 0x01
  57. #define CTRL_TP_ALEV_BB (PERIPH_BB_BASE + (CTRL_OFFSET * 32) + (TP_ALEV_BIT * 4))
  58. /* Alias word address of TP_EN bit */
  59. #define TP_EN_BIT 0x00
  60. #define CTRL_TP_EN_BB (PERIPH_BB_BASE + (CTRL_OFFSET * 32) + (TP_EN_BIT * 4))
  61. /* --- CTRLSTS Register ---*/
  62. /* Alias word address of TPINT_EN bit */
  63. #define CTRLSTS_OFFSET (BKP_OFFSET + 0x34)
  64. #define TPINT_EN_BIT 0x02
  65. #define CTRLSTS_TPINT_EN_BB (PERIPH_BB_BASE + (CTRLSTS_OFFSET * 32) + (TPINT_EN_BIT * 4))
  66. /* Alias word address of TINTF bit */
  67. #define TINTF_BIT 0x09
  68. #define CTRLSTS_TINTF_BB (PERIPH_BB_BASE + (CTRLSTS_OFFSET * 32) + (TINTF_BIT * 4))
  69. /* Alias word address of TEF bit */
  70. #define TEF_BIT 0x08
  71. #define CTRLSTS_TEF_BB (PERIPH_BB_BASE + (CTRLSTS_OFFSET * 32) + (TEF_BIT * 4))
  72. /**
  73. * @}
  74. */
  75. /** @addtogroup BKP_Private_Macros
  76. * @{
  77. */
  78. /**
  79. * @}
  80. */
  81. /** @addtogroup BKP_Private_Variables
  82. * @{
  83. */
  84. /**
  85. * @}
  86. */
  87. /** @addtogroup BKP_Private_FunctionPrototypes
  88. * @{
  89. */
  90. /**
  91. * @}
  92. */
  93. /** @addtogroup BKP_Private_Functions
  94. * @{
  95. */
  96. /**
  97. * @brief Deinitializes the BKP peripheral registers to their default reset values.
  98. */
  99. void BKP_DeInit(void)
  100. {
  101. RCC_EnableBackupReset(ENABLE);
  102. RCC_EnableBackupReset(DISABLE);
  103. }
  104. /**
  105. * @brief Configures the Tamper Pin active level.
  106. * @param BKP_TamperPinLevel specifies the Tamper Pin active level.
  107. * This parameter can be one of the following values:
  108. * @arg BKP_TP_HIGH Tamper pin active on high level
  109. * @arg BKP_TP_LOW Tamper pin active on low level
  110. */
  111. void BKP_ConfigTPLevel(uint16_t BKP_TamperPinLevel)
  112. {
  113. /* Check the parameters */
  114. assert_param(IS_BKP_TP_LEVEL(BKP_TamperPinLevel));
  115. *(__IO uint32_t*)CTRL_TP_ALEV_BB = BKP_TamperPinLevel;
  116. }
  117. /**
  118. * @brief Enables or disables the Tamper Pin activation.
  119. * @param Cmd new state of the Tamper Pin activation.
  120. * This parameter can be: ENABLE or DISABLE.
  121. */
  122. void BKP_TPEnable(FunctionalState Cmd)
  123. {
  124. /* Check the parameters */
  125. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  126. *(__IO uint32_t*)CTRL_TP_EN_BB = (uint32_t)Cmd;
  127. }
  128. /**
  129. * @brief Enables or disables the Tamper Pin Interrupt.
  130. * @param Cmd new state of the Tamper Pin Interrupt.
  131. * This parameter can be: ENABLE or DISABLE.
  132. */
  133. void BKP_TPIntEnable(FunctionalState Cmd)
  134. {
  135. /* Check the parameters */
  136. assert_param(IS_FUNCTIONAL_STATE(Cmd));
  137. *(__IO uint32_t*)CTRLSTS_TPINT_EN_BB = (uint32_t)Cmd;
  138. }
  139. /**
  140. * @brief Writes user data to the specified Data Backup Register.
  141. * @param BKP_DAT specifies the Data Backup Register.
  142. * This parameter can be BKP_DATx where x:[1, 42]
  143. * @param Data data to write
  144. */
  145. void BKP_WriteBkpData(uint16_t BKP_DAT, uint16_t Data)
  146. {
  147. __IO uint32_t tmp = 0;
  148. /* Check the parameters */
  149. assert_param(IS_BKP_DAT(BKP_DAT));
  150. tmp = (uint32_t)BKP_BASE;
  151. tmp += BKP_DAT;
  152. *(__IO uint32_t*)tmp = Data;
  153. }
  154. /**
  155. * @brief Reads data from the specified Data Backup Register.
  156. * @param BKP_DAT specifies the Data Backup Register.
  157. * This parameter can be BKP_DATx where x:[1, 42]
  158. * @return The content of the specified Data Backup Register
  159. */
  160. uint16_t BKP_ReadBkpData(uint16_t BKP_DAT)
  161. {
  162. __IO uint32_t tmp = 0;
  163. /* Check the parameters */
  164. assert_param(IS_BKP_DAT(BKP_DAT));
  165. tmp = (uint32_t)BKP_BASE;
  166. tmp += BKP_DAT;
  167. return (*(__IO uint16_t*)tmp);
  168. }
  169. /**
  170. * @brief Checks whether the Tamper Pin Event flag is set or not.
  171. * @return The new state of the Tamper Pin Event flag (SET or RESET).
  172. */
  173. FlagStatus BKP_GetTEFlag(void)
  174. {
  175. return (FlagStatus)(*(__IO uint32_t*)CTRLSTS_TEF_BB);
  176. }
  177. /**
  178. * @brief Clears Tamper Pin Event pending flag.
  179. */
  180. void BKP_ClrTEFlag(void)
  181. {
  182. /* Set CTE bit to clear Tamper Pin Event flag */
  183. BKP->CTRLSTS |= BKP_CTRLSTS_CLRTE;
  184. }
  185. /**
  186. * @brief Checks whether the Tamper Pin Interrupt has occurred or not.
  187. * @return The new state of the Tamper Pin Interrupt (SET or RESET).
  188. */
  189. INTStatus BKP_GetTINTFlag(void)
  190. {
  191. return (INTStatus)(*(__IO uint32_t*)CTRLSTS_TINTF_BB);
  192. }
  193. /**
  194. * @brief Clears Tamper Pin Interrupt pending bit.
  195. */
  196. void BKP_ClrTINTFlag(void)
  197. {
  198. /* Set CTI bit to clear Tamper Pin Interrupt pending bit */
  199. BKP->CTRLSTS |= BKP_CTRLSTS_CLRTINT;
  200. }
  201. /**
  202. * @}
  203. */
  204. /**
  205. * @}
  206. */
  207. /**
  208. * @}
  209. */