hc32_ll_sram.h 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_sram.h
  4. * @brief This file contains all the functions prototypes of the SRAM driver
  5. * library.
  6. @verbatim
  7. Change Logs:
  8. Date Author Notes
  9. 2022-12-31 CDT First version
  10. @endverbatim
  11. *******************************************************************************
  12. * Copyright (C) 2022, Xiaohua Semiconductor Co., Ltd. All rights reserved.
  13. *
  14. * This software component is licensed by XHSC under BSD 3-Clause license
  15. * (the "License"); You may not use this file except in compliance with the
  16. * License. You may obtain a copy of the License at:
  17. * opensource.org/licenses/BSD-3-Clause
  18. *
  19. *******************************************************************************
  20. */
  21. #ifndef __HC32_LL_SRAM_H__
  22. #define __HC32_LL_SRAM_H__
  23. /* C binding of definitions if building with C++ compiler */
  24. #ifdef __cplusplus
  25. extern "C"
  26. {
  27. #endif
  28. /*******************************************************************************
  29. * Include files
  30. ******************************************************************************/
  31. #include "hc32_ll_def.h"
  32. #include "hc32f4xx.h"
  33. #include "hc32f4xx_conf.h"
  34. /**
  35. * @addtogroup LL_Driver
  36. * @{
  37. */
  38. /**
  39. * @addtogroup LL_SRAM
  40. * @{
  41. */
  42. #if (LL_SRAM_ENABLE == DDL_ON)
  43. /*******************************************************************************
  44. * Global type definitions ('typedef')
  45. ******************************************************************************/
  46. /*******************************************************************************
  47. * Global pre-processor symbols/macros ('#define')
  48. ******************************************************************************/
  49. /**
  50. * @defgroup SRAM_Global_Macros SRAM Global Macros
  51. * @{
  52. */
  53. /**
  54. * @defgroup SRAM_Sel SRAM Selection
  55. * @{
  56. */
  57. #define SRAM_SRAMH (1UL << 1U) /*!< SRAMH: 0x1FFF8000~0x1FFFFFFF, 32KB */
  58. #define SRAM_SRAM0 (1UL << 0U) /*!< SRAM0: 0x20000000~0x20007FFF, 32KB */
  59. #define SRAM_SRAMB (1UL << 2U) /*!< SRAMB: 0x200F0000~0x200F0FFF, 4KB */
  60. #define SRAM_SRAM_ALL (SRAM_SRAMH | SRAM_SRAM0 | SRAM_SRAMB)
  61. #define SRAM_ECC_SRAM0 (SRAM_SRAM0)
  62. #define SRAM_ECC_SRAMB (SRAM_SRAMB)
  63. /**
  64. * @}
  65. */
  66. /**
  67. * @defgroup SRAM_Access_Wait_Cycle SRAM Access Wait Cycle
  68. * @{
  69. */
  70. #define SRAM_WAIT_CYCLE0 (0U) /*!< Wait 0 CPU cycle. */
  71. #define SRAM_WAIT_CYCLE1 (1U) /*!< Wait 1 CPU cycle. */
  72. #define SRAM_WAIT_CYCLE2 (2U) /*!< Wait 2 CPU cycles. */
  73. #define SRAM_WAIT_CYCLE3 (3U) /*!< Wait 3 CPU cycles. */
  74. #define SRAM_WAIT_CYCLE4 (4U) /*!< Wait 4 CPU cycles. */
  75. #define SRAM_WAIT_CYCLE5 (5U) /*!< Wait 5 CPU cycles. */
  76. #define SRAM_WAIT_CYCLE6 (6U) /*!< Wait 6 CPU cycles. */
  77. #define SRAM_WAIT_CYCLE7 (7U) /*!< Wait 7 CPU cycles. */
  78. /**
  79. * @}
  80. */
  81. /**
  82. * @defgroup SRAM_Err_Mode SRAM Error Mode
  83. * @note Even-parity check error, ECC check error.
  84. * @{
  85. */
  86. #define SRAM_ERR_MD_NMI (0UL) /*!< Non-maskable interrupt occurres while check error occurres. */
  87. #define SRAM_ERR_MD_RST (1UL) /*!< System reset occurres while check error occurres. */
  88. /**
  89. * @}
  90. */
  91. /**
  92. * @defgroup SRAM_ECC_Mode SRAM ECC Mode
  93. * @{
  94. */
  95. #define SRAM_ECC_MD_INVD (0U) /*!< The ECC mode is invalid. */
  96. #define SRAM_ECC_MD1 (SRAMC_CKCR_ECCMOD_0) /*!< When 1-bit error occurres:
  97. ECC error corrects.
  98. No 1-bit-error status flag setting, no interrupt or reset.
  99. When 2-bit error occurres:
  100. ECC error detects.
  101. 2-bit-error status flag sets and interrupt or reset occurres. */
  102. #define SRAM_ECC_MD2 (SRAMC_CKCR_ECCMOD_1) /*!< When 1-bit error occurres:
  103. ECC error corrects.
  104. 1-bit-error status flag sets, no interrupt or reset.
  105. When 2-bit error occurres:
  106. ECC error detects.
  107. 2-bit-error status flag sets and interrupt or reset occurres. */
  108. #define SRAM_ECC_MD3 (SRAMC_CKCR_ECCMOD) /*!< When 1-bit error occurres:
  109. ECC error corrects.
  110. 1-bit-error status flag sets and interrupt or reset occurres.
  111. When 2-bit error occurres:
  112. ECC error detects.
  113. 2-bit-error status flag sets and interrupt or reset occurres. */
  114. /**
  115. * @}
  116. */
  117. /**
  118. * @defgroup SRAM_Err_Status_Flag SRAM Error Status Flag
  119. * @{
  120. */
  121. #define SRAM_FLAG_SRAMH_PYERR (SRAMC_CKSR_SRAMH_PYERR) /*!< SRAMH parity error. */
  122. #define SRAM_FLAG_SRAM0_1ERR (SRAMC_CKSR_SRAM0_1ERR) /*!< SRAM0 ECC 1-bit error. */
  123. #define SRAM_FLAG_SRAM0_2ERR (SRAMC_CKSR_SRAM0_2ERR) /*!< SRAM0 ECC 2-bit error. */
  124. #define SRAM_FLAG_SRAMB_1ERR (SRAMC_CKSR_SRAMB_1ERR) /*!< SRAMB ECC 1-bit error. */
  125. #define SRAM_FLAG_SRAMB_2ERR (SRAMC_CKSR_SRAMB_2ERR) /*!< SRAMB ECC 2-bit error. */
  126. #define SRAM_FLAG_CACHE_PYERR (SRAMC_CKSR_CACHE_PYERR) /*!< Cache RAM parity error. */
  127. #define SRAM_FLAG_ALL (0x1F8UL)
  128. /**
  129. * @}
  130. */
  131. /**
  132. * @defgroup SRAM_Reg_Protect_Key SRAM Register Protect Key
  133. * @{
  134. */
  135. #define SRAM_REG_LOCK_KEY (0x76U)
  136. #define SRAM_REG_UNLOCK_KEY (0x77U)
  137. /**
  138. * @}
  139. */
  140. /**
  141. * @defgroup SRAM_Err_Inject_Bit_Range SRAM Error Inject Bit Range
  142. * @{
  143. */
  144. #define SRAM_ERR_INJECT_BIT0_TO_BIT31 (0U)
  145. #define SRAM_ERR_INJECT_BIT32_TO_BIT38 (1U)
  146. /**
  147. * @}
  148. */
  149. /**
  150. * @}
  151. */
  152. /*******************************************************************************
  153. * Global variable definitions ('extern')
  154. ******************************************************************************/
  155. /*******************************************************************************
  156. Global function prototypes (definition in C source)
  157. ******************************************************************************/
  158. /**
  159. * @addtogroup SRAM_Global_Functions
  160. * @{
  161. */
  162. /**
  163. * @brief Lock SRAM registers, write protect.
  164. * @param None
  165. * @retval None
  166. */
  167. __STATIC_INLINE void SRAM_REG_Lock(void)
  168. {
  169. WRITE_REG32(CM_SRAMC->WTPR, SRAM_REG_LOCK_KEY);
  170. WRITE_REG32(CM_SRAMC->CKPR, SRAM_REG_LOCK_KEY);
  171. }
  172. /**
  173. * @brief Unlock SRAM registers, write enable.
  174. * @param None
  175. * @retval None
  176. */
  177. __STATIC_INLINE void SRAM_REG_Unlock(void)
  178. {
  179. WRITE_REG32(CM_SRAMC->WTPR, SRAM_REG_UNLOCK_KEY);
  180. WRITE_REG32(CM_SRAMC->CKPR, SRAM_REG_UNLOCK_KEY);
  181. }
  182. void SRAM_Init(void);
  183. void SRAM_DeInit(void);
  184. void SRAM_REG_Lock(void);
  185. void SRAM_REG_Unlock(void);
  186. void SRAM_SetWaitCycle(uint32_t u32SramSel, uint32_t u32WriteCycle, uint32_t u32ReadCycle);
  187. void SRAM_SetEccMode(uint32_t u32SramSel, uint32_t u32EccMode);
  188. void SRAM_SetErrorMode(uint32_t u32SramSel, uint32_t u32ErrMode);
  189. en_flag_status_t SRAM_GetStatus(uint32_t u32Flag);
  190. void SRAM_ClearStatus(uint32_t u32Flag);
  191. void SRAM_ErrorInjectCmd(uint32_t u32SramSel, en_functional_state_t enNewState);
  192. void SRAM_ErrorInjectBitCmd(uint32_t u32SramSel, uint32_t u32BitRange, uint32_t u32BitSel, en_functional_state_t enNewState);
  193. uint32_t SRAM_GetEccErrorAddr(uint32_t u32SramSel);
  194. /**
  195. * @}
  196. */
  197. #endif /* LL_SRAM_ENABLE */
  198. /**
  199. * @}
  200. */
  201. /**
  202. * @}
  203. */
  204. #ifdef __cplusplus
  205. }
  206. #endif
  207. #endif /* __HC32_LL_SRAM_H__ */
  208. /*******************************************************************************
  209. * EOF (not truncated)
  210. ******************************************************************************/