hc32f460_sram.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /******************************************************************************
  2. * Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
  3. *
  4. * This software component is licensed by HDSC under BSD 3-Clause license
  5. * (the "License"); You may not use this file except in compliance with the
  6. * License. You may obtain a copy of the License at:
  7. * opensource.org/licenses/BSD-3-Clause
  8. */
  9. /******************************************************************************/
  10. /** \file hc32f460_sram.h
  11. **
  12. ** A detailed description is available at
  13. ** @link SramGroup Internal SRAM description @endlink
  14. **
  15. ** - 2018-10-17 CDT First version for Device Driver Library of SRAM.
  16. **
  17. ******************************************************************************/
  18. #ifndef __HC32F460_SRAM_H__
  19. #define __HC32F460_SRAM_H__
  20. /*******************************************************************************
  21. * Include files
  22. ******************************************************************************/
  23. #include "hc32_common.h"
  24. #include "ddl_config.h"
  25. #if (DDL_SRAM_ENABLE == DDL_ON)
  26. /* C binding of definitions if building with C++ compiler */
  27. #ifdef __cplusplus
  28. extern "C"
  29. {
  30. #endif
  31. /**
  32. *******************************************************************************
  33. * \defgroup SramGroup Internal SRAM
  34. **
  35. ******************************************************************************/
  36. //@{
  37. /*******************************************************************************
  38. * Global type definitions ('typedef')
  39. ******************************************************************************/
  40. ///< SRAM wait cycle register, parity/ECC check register protect code definition
  41. #define SRAM_PROTECT_CODE (0x0000003Bu)
  42. /*******************************************************************************
  43. Start addr. End addr. Size Function
  44. SRAM1 0x20000000 0x2000FFFF 64KB Even Parity Check
  45. SRAM2 0x20010000 0x2001FFFF 64KB Even Parity Check
  46. SRAM3 0x20020000 0x20026FFF 28KB ECC Check
  47. SRAM_Ret 0x200F0000 0x200F0FFF 4KB Even Parity Check
  48. SRAM_HS 0x1FFF8000 0x1FFFFFFF 32KB Even Parity Check
  49. ******************************************************************************/
  50. ///< SRAM1 base address definition
  51. #define SRAM1_BASE_ADDR (*((volatile unsigned int*)(0x20000000UL)))
  52. ///< SRAM2 base address definition
  53. #define SRAM2_BASE_ADDR (*((volatile unsigned int*)(0x20010000UL)))
  54. ///< SRAM3 base address definition
  55. #define SRAM3_BASE_ADDR (*((volatile unsigned int*)(0x20020000UL)))
  56. ///< Retention SRAM base address definition
  57. #define SRAMRET_BASE_ADDR (*((volatile unsigned int*)(0x200F0000UL)))
  58. ///< High speed SRAM base address definition
  59. #define SRAMHS_BASE_ADDR (*((volatile unsigned int*)(0x1FFF8000UL)))
  60. typedef enum en_sram_index
  61. {
  62. Sram12Idx = 1u << 0,
  63. Sram3Idx = 1u << 1,
  64. SramHsIdx = 1u << 2,
  65. SramRetIdx = 1u << 3,
  66. }en_sram_index_t;
  67. /**
  68. *******************************************************************************
  69. ** \brief Enumeration to the write/read cycles of SRAM
  70. **
  71. ** \note
  72. ******************************************************************************/
  73. typedef enum en_sram_rw_cycle
  74. {
  75. SramCycle1 = 0u,
  76. SramCycle2 = 1u,
  77. SramCycle3 = 2u,
  78. SramCycle4 = 3u,
  79. SramCycle5 = 4u,
  80. SramCycle6 = 5u,
  81. SramCycle7 = 6u,
  82. SramCycle8 = 7u,
  83. }en_sram_rw_cycle_t;
  84. /**
  85. *******************************************************************************
  86. ** \brief Enumeration to ECC check mode
  87. **
  88. ** \note
  89. ******************************************************************************/
  90. typedef enum en_ecc_mode
  91. {
  92. EccMode0 = 0u, ///< disable ECC check function
  93. EccMode1 = 1u, ///< no 1 bit ECC flag, interrupt/reset if 1 bit-ECC is detected
  94. ///< generate 2 bit ECC flag, interrupt/reset if 2 bit-ECC is detected
  95. EccMode2 = 2u, ///< generate 1 bit ECC flag, but no interrupt/reset if 1 bit-ECC is detected
  96. ///< generate 2 bit ECC flag, interrupt/reset if 2 bit-ECC is detected
  97. EccMode3 = 3u, ///< generate 1 bit ECC flag, interrupt/reset if 1 bit-ECC is detected
  98. ///< generate 2 bit ECC flag, interrupt/reset if 2 bit-ECC is detected
  99. }en_ecc_mode_t;
  100. /**
  101. *******************************************************************************
  102. ** \brief Enumeration to operation after ECC/Parity error
  103. **
  104. ** \note
  105. ******************************************************************************/
  106. typedef enum en_ecc_py_err_op
  107. {
  108. SramNmi = 0u, ///< Generate NMI after ECC/Parity error detected
  109. SramReset = 1u, ///< Generate Reset after ECC/Parity error detected
  110. }en_ecc_py_err_op_t;
  111. /**
  112. *******************************************************************************
  113. ** \brief Enumeration to the ECC/Parity error status of each SRAM
  114. **
  115. ** \note
  116. ******************************************************************************/
  117. typedef enum en_sram_err_status
  118. {
  119. Sram3EccErr1 = 1u << 0, ///< SRAM3 1 bit ECC error
  120. Sram3EccErr2 = 1u << 1, ///< SRAM3 2 bit ECC error
  121. Sram12ParityErr = 1u << 2, ///< SRAM1/2 parity error
  122. SramHSParityErr = 1u << 3, ///< High speed SRAM parity error
  123. SramRetParityErr = 1u << 4, ///< Retention SRAM parity error
  124. }en_sram_err_status_t;
  125. /**
  126. *******************************************************************************
  127. ** \brief SRAM configuration
  128. **
  129. ** \note The SRAM configuration structure
  130. ******************************************************************************/
  131. typedef struct stc_sram_config
  132. {
  133. uint8_t u8SramIdx; ///< SRAM index, ref @ en_sram_index_t for details
  134. en_sram_rw_cycle_t enSramRC; ///< SRAM read wait cycle setting
  135. en_sram_rw_cycle_t enSramWC; ///< SRAM write wait cycle setting
  136. en_ecc_mode_t enSramEccMode; ///< SRAM ECC mode setting
  137. en_ecc_py_err_op_t enSramEccOp; ///< SRAM3 ECC error handling setting
  138. en_ecc_py_err_op_t enSramPyOp; ///< SRAM1/2/HS/Ret Parity error handling setting
  139. }stc_sram_config_t;
  140. /*******************************************************************************
  141. * Global pre-processor symbols/macros ('#define')
  142. ******************************************************************************/
  143. /*******************************************************************************
  144. * Global variable definitions ('extern')
  145. ******************************************************************************/
  146. /*******************************************************************************
  147. * Global function prototypes (definition in C source)
  148. ******************************************************************************/
  149. extern en_result_t SRAM_Init(const stc_sram_config_t *pstcSramConfig);
  150. extern en_result_t SRAM_DeInit(void);
  151. extern en_result_t SRAM_WT_Disable(void);
  152. extern en_result_t SRAM_WT_Enable(void);
  153. extern en_result_t SRAM_CK_Disable(void);
  154. extern en_result_t SRAM_CK_Enable(void);
  155. extern en_flag_status_t SRAM_GetStatus(en_sram_err_status_t enSramErrStatus);
  156. extern en_result_t SRAM_ClrStatus(en_sram_err_status_t enSramErrStatus);
  157. //@} // SramGroup
  158. #ifdef __cplusplus
  159. }
  160. #endif
  161. #endif /* DDL_SRAM_ENABLE */
  162. #endif /* __HC32F460_SRAM_H__ */
  163. /*******************************************************************************
  164. * EOF (not truncated)
  165. ******************************************************************************/