hc32_ll_smc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /**
  2. *******************************************************************************
  3. * @file hc32_ll_smc.h
  4. * @brief This file contains all the functions prototypes of the EXMC_SMC
  5. * (External Memory Controller: Static Memory Controller) driver 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_SMC_H__
  22. #define __HC32_LL_SMC_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_EXMC
  40. * @{
  41. */
  42. /**
  43. * @addtogroup LL_SMC
  44. * @{
  45. */
  46. #if (LL_SMC_ENABLE == DDL_ON)
  47. /*******************************************************************************
  48. * Global type definitions ('typedef')
  49. ******************************************************************************/
  50. /**
  51. * @defgroup EXMC_SMC_Global_Types EXMC_SMC Global Types
  52. * @{
  53. */
  54. /**
  55. * @brief EXMC_SMC Chip Configuration Structure definition
  56. */
  57. typedef struct {
  58. uint32_t u32ReadMode; /*!< Defines the read sync enable.
  59. This parameter can be a value of @ref EXMC_SMC_Memory_Read_Mode */
  60. uint32_t u32WriteMode; /*!< Defines the write sync enable.
  61. This parameter can be a value of @ref EXMC_SMC_Memory_Write_Mode */
  62. uint32_t u32MemoryWidth; /*!< Defines the SMC memory width.
  63. This parameter can be a value of @ref EXMC_SMC_Memory_Width. */
  64. uint32_t u32BAA; /*!< Defines the SMC BAA signal enable.
  65. This parameter can be a value of @ref EXMC_SMC_BAA_Port_Selection. */
  66. uint32_t u32ADV; /*!< Defines the SMC ADVS signal enable.
  67. This parameter can be a value of @ref EXMC_SMC_ADV_Port_Selection. */
  68. uint32_t u32BLS; /*!< Defines the SMC BLS signal selection.
  69. This parameter can be a value of @ref EXMC_SMC_BLS_Synchronization_Selection. */
  70. uint32_t u32AddrMatch; /*!< Defines the address match.
  71. This parameter can be a value between Min_Data = 0x60 and Max_Data = 0x7F */
  72. uint32_t u32AddrMask; /*!< Defines the address mask.
  73. This parameter can be a value of @ref EXMC_SMC_Mask_Address. */
  74. } stc_exmc_smc_chip_config_t;
  75. /**
  76. * @brief EXMC_SMC Timing Configuration Structure definition
  77. */
  78. typedef struct {
  79. uint8_t u8RC; /*!< Defines the RC in memory clock cycles.
  80. This parameter can be a value between Min_Data = 0 and Max_Data = 0x0F */
  81. uint8_t u8WC; /*!< Defines the WC in memory clock cycles.
  82. This parameter can be a value between Min_Data = 0 and Max_Data = 0x0F */
  83. uint8_t u8CEOE; /*!< Defines the CEOE in memory clock cycles.
  84. This parameter can be a value between Min_Data = 0 and Max_Data = 7 */
  85. uint8_t u8WP; /*!< Defines the WP in memory clock cycles.
  86. This parameter can be a value between Min_Data = 0 and Max_Data = 7 */
  87. uint8_t u8TR; /*!< Defines the TR in memory clock cycles.
  88. This parameter can be a value between Min_Data = 0 and Max_Data = 7 */
  89. uint8_t u8ADV; /*!< Defines the ADV in memory clock cycles.
  90. This parameter can be a value between Min_Data = 0 and Max_Data = 7 */
  91. } stc_exmc_smc_timing_config_t;
  92. /**
  93. * @brief EXMC_SMC Initialization Structure definition
  94. */
  95. typedef struct {
  96. stc_exmc_smc_chip_config_t stcChipConfig; /*!< SMC memory chip configure.
  97. This structure details refer @ref stc_exmc_smc_chip_config_t. */
  98. stc_exmc_smc_timing_config_t stcTimingConfig; /*!< SMC memory timing configure.
  99. This structure details refer @ref stc_exmc_smc_timing_config_t. */
  100. } stc_exmc_smc_init_t;
  101. /**
  102. * @}
  103. */
  104. /*******************************************************************************
  105. * Global pre-processor symbols/macros ('#define')
  106. ******************************************************************************/
  107. /**
  108. * @defgroup EXMC_SMC_Global_Macros EXMC_SMC Global Macros
  109. * @{
  110. */
  111. /**
  112. * @defgroup EXMC_SMC_Chip EXMC_SMC Chip
  113. * @{
  114. */
  115. #define EXMC_SMC_CHIP0 (0UL) /*!< Chip 0 */
  116. /**
  117. * @}
  118. */
  119. /**
  120. * @defgroup EXMC_SMC_Memory_Read_Mode EXMC_SMC Memory Read Mode
  121. * @{
  122. */
  123. #define EXMC_SMC_READ_ASYNC (0UL)
  124. #define EXMC_SMC_READ_SYNC (SMC_CPCR_RSYN)
  125. /**
  126. * @}
  127. */
  128. /**
  129. * @defgroup EXMC_SMC_Memory_Write_Mode EXMC_SMC Memory Write Mode
  130. * @{
  131. */
  132. #define EXMC_SMC_WRITE_ASYNC (0UL)
  133. #define EXMC_SMC_WRITE_SYNC (SMC_CPCR_WSYN)
  134. /**
  135. * @}
  136. */
  137. /**
  138. * @defgroup EXMC_SMC_Memory_Width EXMC_SMC Memory Width
  139. * @{
  140. */
  141. #define EXMC_SMC_MEMORY_WIDTH_8BIT (0UL)
  142. #define EXMC_SMC_MEMORY_WIDTH_16BIT (SMC_CPCR_MW_0)
  143. /**
  144. * @}
  145. */
  146. /**
  147. * @defgroup EXMC_SMC_BAA_Port_Selection EXMC_SMC BAA Port Selection
  148. * @{
  149. */
  150. #define EXMC_SMC_BAA_PORT_DISABLE (0UL)
  151. #define EXMC_SMC_BAA_PORT_ENABLE (SMC_CPCR_BAAS)
  152. /**
  153. * @}
  154. */
  155. /**
  156. * @defgroup EXMC_SMC_ADV_Port_Selection EXMC_SMC ADV Port Selection
  157. * @{
  158. */
  159. #define EXMC_SMC_ADV_PORT_DISABLE (0UL)
  160. #define EXMC_SMC_ADV_PORT_ENABLE (SMC_CPCR_ADVS)
  161. /**
  162. * @}
  163. */
  164. /**
  165. * @defgroup EXMC_SMC_BLS_Synchronization_Selection EXMC_SMC BLS Synchronization Selection
  166. * @{
  167. */
  168. #define EXMC_SMC_BLS_SYNC_CS (0UL)
  169. #define EXMC_SMC_BLS_SYNC_WE (SMC_CPCR_BLSS)
  170. /**
  171. * @}
  172. */
  173. /**
  174. * @defgroup EXMC_SMC_Command EXMC_SMC Command
  175. * @{
  176. */
  177. #define EXMC_SMC_CMD_MDREGCONFIG (SMC_CMDR_CMD_0) /*!< Command: MdRetConfig */
  178. #define EXMC_SMC_CMD_UPDATEREGS (SMC_CMDR_CMD_1) /*!< Command: UpdateRegs */
  179. #define EXMC_SMC_CMD_MDREGCONFIG_AND_UPDATEREGS (SMC_CMDR_CMD) /*!< Command: MdRetConfig & UpdateRegs */
  180. /**
  181. * @}
  182. */
  183. /**
  184. * @defgroup EXMC_SMC_CRE_Polarity EXMC_SMC CRE Polarity
  185. * @{
  186. */
  187. #define EXMC_SMC_CRE_POLARITY_LOW (0UL) /*!< CRE is LOW */
  188. #define EXMC_SMC_CRE_POLARITY_HIGH (SMC_CMDR_CRES) /*!< CRE is HIGH when ModeReg write occurs */
  189. /**
  190. * @}
  191. */
  192. /**
  193. * @defgroup EXMC_SMC_Status EXMC_SMC Status
  194. * @{
  195. */
  196. #define EXMC_SMC_READY (0UL) /*!< SMC is ready */
  197. #define EXMC_SMC_LOWPOWER (SMC_STSR_STATUS) /*!< SMC is low power */
  198. /**
  199. * @}
  200. */
  201. /**
  202. * @defgroup EXMC_SMC_Sample_Clock EXMC_SMC Sample Clock
  203. * @{
  204. */
  205. #define EXMC_SMC_SAMPLE_CLK_INTERNCLK (0UL) /*!< Internal EXCLK */
  206. #define EXMC_SMC_SAMPLE_CLK_INTERNCLK_INVT (SMC_BACR_CKSEL_0) /*!< Invert internal EXCLK */
  207. #define EXMC_SMC_SAMPLE_CLK_EXTCLK (SMC_BACR_CKSEL_1) /*!< External clock from EXMC_CLK port */
  208. /**
  209. * @}
  210. */
  211. /**
  212. * @defgroup EXMC_SMC_Mask_Address EXMC_SMC Mask Address
  213. * @{
  214. */
  215. #define EXMC_SMC_ADDR_MASK_16MB (0xFFUL)
  216. #define EXMC_SMC_ADDR_MASK_32MB (0xFEUL)
  217. #define EXMC_SMC_ADDR_MASK_64MB (0xFCUL)
  218. #define EXMC_SMC_ADDR_MASK_128MB (0xF8UL)
  219. #define EXMC_SMC_ADDR_MASK_256MB (0xF0UL)
  220. #define EXMC_SMC_ADDR_MASK_512MB (0xE0UL)
  221. /**
  222. * @}
  223. */
  224. /**
  225. * @defgroup EXMC_SMC_Address_Space EXMC_SMC Address Space
  226. * @{
  227. */
  228. #define EXMC_SMC_ADDR_MIN (0x60000000UL)
  229. #define EXMC_SMC_ADDR_MAX (0x7FFFFFFFUL)
  230. /**
  231. * @}
  232. */
  233. /**
  234. * @brief SMC device memory address shifting.
  235. * @param [in] mem_base_addr SMC base address
  236. * @param [in] mem_width SMC memory width
  237. * @param [in] addr SMC device memory address
  238. * @retval SMC device shifted address value
  239. */
  240. #define SMC_ADDR_SHIFT(mem_base_addr, mem_width, addr) \
  241. ( ((EXMC_SMC_MEMORY_WIDTH_16BIT == (mem_width))? (((mem_base_addr) + ((addr) << 1U))) : \
  242. (((mem_base_addr) + ((addr) << 2U)))))
  243. /**
  244. * @}
  245. */
  246. /*******************************************************************************
  247. * Global variable definitions ('extern')
  248. ******************************************************************************/
  249. /*******************************************************************************
  250. Global function prototypes (definition in C source)
  251. ******************************************************************************/
  252. /**
  253. * @addtogroup EXMC_SMC_Global_Functions
  254. * @{
  255. */
  256. /**
  257. * @brief SMC entry low power state
  258. * @param None
  259. * @retval None
  260. */
  261. __STATIC_INLINE void EXMC_SMC_EntryLowPower(void)
  262. {
  263. WRITE_REG32(CM_SMC->STCR0, SMC_STCR0_LPWIR);
  264. }
  265. /**
  266. * @brief SMC exit low power state
  267. * @param None
  268. * @retval None
  269. */
  270. __STATIC_INLINE void EXMC_SMC_ExitLowPower(void)
  271. {
  272. WRITE_REG32(CM_SMC->STCR1, SMC_STCR1_LPWOR);
  273. }
  274. /**
  275. * @brief Get SMC status
  276. * @param None
  277. * @retval Returned value can be one of the macros group @ref EXMC_SMC_Status
  278. * - EXMC_SMC_READY: SMC is ready
  279. * - EXMC_SMC_LOWPOWER: SMC is low power
  280. */
  281. __STATIC_INLINE uint32_t EXMC_SMC_GetStatus(void)
  282. {
  283. return READ_REG32_BIT(CM_SMC->STSR, SMC_STSR_STATUS);
  284. }
  285. /* Initialization and configuration EXMC_SMC functions */
  286. int32_t EXMC_SMC_StructInit(stc_exmc_smc_init_t *pstcSmcInit);
  287. int32_t EXMC_SMC_Init(uint32_t u32Chip, const stc_exmc_smc_init_t *pstcSmcInit);
  288. void EXMC_SMC_DeInit(void);
  289. void EXMC_SMC_Cmd(en_functional_state_t enNewState);
  290. void EXMC_SMC_PinMuxCmd(en_functional_state_t enNewState);
  291. void EXMC_SMC_SetSampleClock(uint32_t u32SampleClock);
  292. void EXMC_SMC_SetRefreshPeriod(uint8_t u8PeriodVal);
  293. void EXMC_SMC_SetCommand(uint32_t u32Chip, uint32_t u32Cmd, uint32_t u32CrePolarity, uint32_t u32Addr);
  294. uint32_t EXMC_SMC_GetChipStartAddr(uint32_t u32Chip);
  295. uint32_t EXMC_SMC_GetChipEndAddr(uint32_t u32Chip);
  296. int32_t EXMC_SMC_GetChipConfig(uint32_t u32Chip, stc_exmc_smc_chip_config_t *pstcChipConfig);
  297. int32_t EXMC_SMC_GetTimingConfig(uint32_t u32Chip, stc_exmc_smc_timing_config_t *pstcTimingConfig);
  298. /**
  299. * @}
  300. */
  301. #endif /* LL_SMC_ENABLE */
  302. /**
  303. * @}
  304. */
  305. /**
  306. * @}
  307. */
  308. /**
  309. * @}
  310. */
  311. #ifdef __cplusplus
  312. }
  313. #endif
  314. #endif /* __HC32_LL_SMC_H__ */
  315. /*******************************************************************************
  316. * EOF (not truncated)
  317. ******************************************************************************/