fsl_semc.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  1. /*
  2. * Copyright 2017 NXP
  3. *
  4. * Redistribution and use in source and binary forms, with or without modification,
  5. * are permitted provided that the following conditions are met:
  6. *
  7. * o Redistributions of source code must retain the above copyright notice, this list
  8. * of conditions and the following disclaimer.
  9. *
  10. * o Redistributions in binary form must reproduce the above copyright notice, this
  11. * list of conditions and the following disclaimer in the documentation and/or
  12. * other materials provided with the distribution.
  13. *
  14. * o Neither the name of the copyright holder nor the names of its
  15. * contributors may be used to endorse or promote products derived from this
  16. * software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  22. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  25. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29. #ifndef _FSL_SEMC_H_
  30. #define _FSL_SEMC_H_
  31. #include "fsl_common.h"
  32. /*!
  33. * @addtogroup semc
  34. * @{
  35. */
  36. /*******************************************************************************
  37. * Definitions
  38. ******************************************************************************/
  39. /*! @name Driver version */
  40. /*@{*/
  41. /*! @brief SEMC driver version 2.0.0. */
  42. #define FSL_SEMC_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
  43. /*@}*/
  44. /*! @brief SEMC status. */
  45. enum _semc_status
  46. {
  47. kStatus_SEMC_InvalidDeviceType = MAKE_STATUS(kStatusGroup_SEMC, 0),
  48. kStatus_SEMC_IpCommandExecutionError = MAKE_STATUS(kStatusGroup_SEMC, 1),
  49. kStatus_SEMC_AxiCommandExecutionError = MAKE_STATUS(kStatusGroup_SEMC, 2),
  50. kStatus_SEMC_InvalidMemorySize = MAKE_STATUS(kStatusGroup_SEMC, 3),
  51. kStatus_SEMC_InvalidIpcmdDataSize = MAKE_STATUS(kStatusGroup_SEMC, 4),
  52. kStatus_SEMC_InvalidAddressPortWidth = MAKE_STATUS(kStatusGroup_SEMC, 5),
  53. kStatus_SEMC_InvalidDataPortWidth = MAKE_STATUS(kStatusGroup_SEMC, 6),
  54. kStatus_SEMC_InvalidSwPinmuxSelection = MAKE_STATUS(kStatusGroup_SEMC, 7),
  55. kStatus_SEMC_InvalidBurstLength = MAKE_STATUS(kStatusGroup_SEMC, 8),
  56. kStatus_SEMC_InvalidColumnAddressBitWidth = MAKE_STATUS(kStatusGroup_SEMC, 9),
  57. kStatus_SEMC_InvalidBaseAddress = MAKE_STATUS(kStatusGroup_SEMC, 10),
  58. kStatus_SEMC_InvalidTimerSetting = MAKE_STATUS(kStatusGroup_SEMC, 11),
  59. };
  60. /*! @brief SEMC memory device type. */
  61. typedef enum _semc_mem_type {
  62. kSEMC_MemType_SDRAM = 0, /*!< SDRAM */
  63. kSEMC_MemType_SRAM, /*!< SRAM */
  64. kSEMC_MemType_NOR, /*!< NOR */
  65. kSEMC_MemType_NAND, /*!< NAND */
  66. kSEMC_MemType_8080 /*!< 8080. */
  67. } semc_mem_type_t;
  68. /*! @brief SEMC WAIT/RDY polarity. */
  69. typedef enum _semc_waitready_polarity {
  70. kSEMC_LowActive = 0, /*!< Low active. */
  71. kSEMC_HighActive, /*!< High active. */
  72. } semc_waitready_polarity_t;
  73. /*! @brief SEMC SDRAM Chip selection . */
  74. typedef enum _semc_sdram_cs {
  75. kSEMC_SDRAM_CS0 = 0, /*!< SEMC SDRAM CS0. */
  76. kSEMC_SDRAM_CS1, /*!< SEMC SDRAM CS1. */
  77. kSEMC_SDRAM_CS2, /*!< SEMC SDRAM CS2. */
  78. kSEMC_SDRAM_CS3 /*!< SEMC SDRAM CS3. */
  79. } semc_sdram_cs_t;
  80. /*! @brief SEMC NAND device type. */
  81. typedef enum _semc_nand_type {
  82. kSEMC_NAND_AXI = 0,
  83. kSEMC_NAND_IP,
  84. } semc_nand_type_t;
  85. /*! @brief SEMC interrupts . */
  86. typedef enum _semc_interrupt_enable {
  87. kSEMC_IPCmdDoneInterrupt = SEMC_INTEN_IPCMDDONEEN_MASK, /*!< Ip command done interrupt. */
  88. kSEMC_IPCmdErrInterrupt = SEMC_INTEN_IPCMDERREN_MASK, /*!< Ip command error interrupt. */
  89. kSEMC_AXICmdErrInterrupt = SEMC_INTEN_AXICMDERREN_MASK, /*!< AXI command error interrupt. */
  90. kSEMC_AXIBusErrInterrupt = SEMC_INTEN_AXIBUSERREN_MASK /*!< AXI bus error interrupt. */
  91. } semc_interrupt_enable_t;
  92. /*! @brief SEMC IP command data size in bytes. */
  93. typedef enum _semc_ipcmd_datasize {
  94. kSEMC_IPcmdDataSize_1bytes = 1, /*!< The IP command data size 1 byte. */
  95. kSEMC_IPcmdDataSize_2bytes, /*!< The IP command data size 2 byte. */
  96. kSEMC_IPcmdDataSize_3bytes, /*!< The IP command data size 3 byte. */
  97. kSEMC_IPcmdDataSize_4bytes /*!< The IP command data size 4 byte. */
  98. } semc_ipcmd_datasize_t;
  99. /*! @brief SEMC auto-refresh timing. */
  100. typedef enum _semc_refresh_time {
  101. kSEMC_RefreshThreeClocks = 0x0U, /*!< The refresh timing with three bus clocks. */
  102. kSEMC_RefreshSixClocks, /*!< The refresh timing with six bus clocks. */
  103. kSEMC_RefreshNineClocks /*!< The refresh timing with nine bus clocks. */
  104. } semc_refresh_time_t;
  105. /*! @brief CAS latency */
  106. typedef enum _semc_caslatency {
  107. kSEMC_LatencyOne = 1, /*!< Latency 1. */
  108. kSEMC_LatencyTwo, /*!< Latency 2. */
  109. kSEMC_LatencyThree, /*!< Latency 3. */
  110. } semc_caslatency_t;
  111. /*! @brief SEMC sdram column address bit number. */
  112. typedef enum _semc_sdram_column_bit_num {
  113. kSEMC_SdramColunm_12bit = 0x0U, /*!< 12 bit. */
  114. kSEMC_SdramColunm_11bit, /*!< 11 bit. */
  115. kSEMC_SdramColunm_10bit, /*!< 10 bit. */
  116. kSEMC_SdramColunm_9bit, /*!< 9 bit. */
  117. } semc_sdram_column_bit_num_t;
  118. /*! @brief SEMC sdram burst length. */
  119. typedef enum _semc_sdram_burst_len {
  120. kSEMC_Sdram_BurstLen1 = 0, /*!< Burst length 1*/
  121. kSEMC_Sdram_BurstLen2, /*!< Burst length 2*/
  122. kSEMC_Sdram_BurstLen4, /*!< Burst length 4*/
  123. kSEMC_Sdram_BurstLen8 /*!< Burst length 8*/
  124. } sem_sdram_burst_len_t;
  125. /*! @brief SEMC nand column address bit number. */
  126. typedef enum _semc_nand_column_bit_num {
  127. kSEMC_NandColum_16bit = 0x0U, /*!< 16 bit. */
  128. kSEMC_NandColum_15bit, /*!< 15 bit. */
  129. kSEMC_NandColum_14bit, /*!< 14 bit. */
  130. kSEMC_NandColum_13bit, /*!< 13 bit. */
  131. kSEMC_NandColum_12bit, /*!< 12 bit. */
  132. kSEMC_NandColum_11bit, /*!< 11 bit. */
  133. kSEMC_NandColum_10bit, /*!< 10 bit. */
  134. kSEMC_NandColum_9bit, /*!< 9 bit. */
  135. } semc_nand_column_bit_num_t;
  136. /*! @brief SEMC nand burst length. */
  137. typedef enum _semc_nand_burst_len {
  138. kSEMC_Nand_BurstLen1 = 0, /*!< Burst length 1*/
  139. kSEMC_Nand_BurstLen2, /*!< Burst length 2*/
  140. kSEMC_Nand_BurstLen4, /*!< Burst length 4*/
  141. kSEMC_Nand_BurstLen8, /*!< Burst length 8*/
  142. kSEMC_Nand_BurstLen16, /*!< Burst length 16*/
  143. kSEMC_Nand_BurstLen32, /*!< Burst length 32*/
  144. kSEMC_Nand_BurstLen64 /*!< Burst length 64*/
  145. } sem_nand_burst_len_t;
  146. /*! @brief SEMC nor/sram column address bit number. */
  147. typedef enum _semc_norsram_column_bit_num {
  148. kSEMC_NorColum_12bit = 0x0U, /*!< 12 bit. */
  149. kSEMC_NorColum_11bit, /*!< 11 bit. */
  150. kSEMC_NorColum_10bit, /*!< 10 bit. */
  151. kSEMC_NorColum_9bit, /*!< 9 bit. */
  152. kSEMC_NorColum_8bit, /*!< 8 bit. */
  153. kSEMC_NorColum_7bit, /*!< 7 bit. */
  154. kSEMC_NorColum_6bit, /*!< 6 bit. */
  155. kSEMC_NorColum_5bit, /*!< 5 bit. */
  156. kSEMC_NorColum_4bit, /*!< 4 bit. */
  157. kSEMC_NorColum_3bit, /*!< 3 bit. */
  158. kSEMC_NorColum_2bit /*!< 2 bit. */
  159. } semc_norsram_column_bit_num_t;
  160. /*! @brief SEMC nor/sram burst length. */
  161. typedef enum _semc_norsram_burst_len {
  162. kSEMC_Nor_BurstLen1 = 0, /*!< Burst length 1*/
  163. kSEMC_Nor_BurstLen2, /*!< Burst length 2*/
  164. kSEMC_Nor_BurstLen4, /*!< Burst length 4*/
  165. kSEMC_Nor_BurstLen8, /*!< Burst length 8*/
  166. kSEMC_Nor_BurstLen16, /*!< Burst length 16*/
  167. kSEMC_Nor_BurstLen32, /*!< Burst length 32*/
  168. kSEMC_Nor_BurstLen64 /*!< Burst length 64*/
  169. } sem_norsram_burst_len_t;
  170. /*! @brief SEMC dbi column address bit number. */
  171. typedef enum _semc_dbi_column_bit_num {
  172. kSEMC_Dbi_Colum_12bit = 0x0U, /*!< 12 bit. */
  173. kSEMC_Dbi_Colum_11bit, /*!< 11 bit. */
  174. kSEMC_Dbi_Colum_10bit, /*!< 10 bit. */
  175. kSEMC_Dbi_Colum_9bit, /*!< 9 bit. */
  176. kSEMC_Dbi_Colum_8bit, /*!< 8 bit. */
  177. kSEMC_Dbi_Colum_7bit, /*!< 7 bit. */
  178. kSEMC_Dbi_Colum_6bit, /*!< 6 bit. */
  179. kSEMC_Dbi_Colum_5bit, /*!< 5 bit. */
  180. kSEMC_Dbi_Colum_4bit, /*!< 4 bit. */
  181. kSEMC_Dbi_Colum_3bit, /*!< 3 bit. */
  182. kSEMC_Dbi_Colum_2bit /*!< 2 bit. */
  183. } semc_dbi_column_bit_num_t;
  184. /*! @brief SEMC dbi burst length. */
  185. typedef enum _semc_dbi_burst_len {
  186. kSEMC_Dbi_BurstLen1 = 0, /*!< Burst length 1*/
  187. kSEMC_Dbi_BurstLen2, /*!< Burst length 2*/
  188. kSEMC_Dbi_Dbi_BurstLen4, /*!< Burst length 4*/
  189. kSEMC_Dbi_BurstLen8, /*!< Burst length 8*/
  190. kSEMC_Dbi_BurstLen16, /*!< Burst length 16*/
  191. kSEMC_Dbi_BurstLen32, /*!< Burst length 32*/
  192. kSEMC_Dbi_BurstLen64 /*!< Burst length 64*/
  193. } sem_dbi_burst_len_t;
  194. /*! @brief SEMC IOMUXC. */
  195. typedef enum _semc_iomux_pin {
  196. kSEMC_MUXA8 = SEMC_IOCR_MUX_A8_SHIFT, /*!< MUX A8 pin. */
  197. kSEMC_MUXCSX0 = SEMC_IOCR_MUX_CSX0_SHIFT, /*!< MUX CSX0 pin */
  198. kSEMC_MUXCSX1 = SEMC_IOCR_MUX_CSX1_SHIFT, /*!< MUX CSX1 Pin.*/
  199. kSEMC_MUXCSX2 = SEMC_IOCR_MUX_CSX2_SHIFT, /*!< MUX CSX2 Pin. */
  200. kSEMC_MUXCSX3 = SEMC_IOCR_MUX_CSX3_SHIFT, /*!< MUX CSX3 Pin. */
  201. kSEMC_MUXRDY = SEMC_IOCR_MUX_RDY_SHIFT /*!< MUX RDY pin. */
  202. } semc_iomux_pin;
  203. /*! @brief SEMC NOR/PSRAM Address bit 27 A27. */
  204. typedef enum _semc_iomux_nora27_pin {
  205. kSEMC_MORA27_NONE = 0, /*!< No NOR/SRAM A27 pin. */
  206. kSEMC_NORA27_MUXCSX3 = SEMC_IOCR_MUX_CSX3_SHIFT, /*!< MUX CSX3 Pin. */
  207. kSEMC_NORA27_MUXRDY = SEMC_IOCR_MUX_RDY_SHIFT /*!< MUX RDY pin. */
  208. } semc_iomux_nora27_pin;
  209. /*! @brief SEMC port size. */
  210. typedef enum _semc_port_size {
  211. kSEMC_PortSize8Bit = 0, /*!< 8-Bit port size. */
  212. kSEMC_PortSize16Bit /*!< 16-Bit port size. */
  213. } smec_port_size_t;
  214. /*! @brief SEMC address mode. */
  215. typedef enum _semc_addr_mode {
  216. kSEMC_AddrDataMux = 0, /*!< SEMC address/data mux mode. */
  217. kSEMC_AdvAddrdataMux, /*!< Advanced address/data mux mode. */
  218. kSEMC_AddrDataNonMux /*!< Address/data non-mux mode. */
  219. } semc_addr_mode_t;
  220. /*! @brief SEMC DQS read strobe mode. */
  221. typedef enum _semc_dqs_mode {
  222. kSEMC_Loopbackinternal = 0, /*!< Dummy read strobe loopbacked internally. */
  223. kSEMC_Loopbackdqspad, /*!< Dummy read strobe loopbacked from DQS pad. */
  224. } semc_dqs_mode_t;
  225. /*! @brief SEMC ADV signal active polarity. */
  226. typedef enum _semc_adv_polarity {
  227. kSEMC_AdvActiveLow = 0, /*!< Adv active low. */
  228. kSEMC_AdvActivehigh, /*!< Adv active low. */
  229. } semc_adv_polarity_t;
  230. /*! @brief SEMC RDY signal active polarity. */
  231. typedef enum _semc_rdy_polarity {
  232. kSEMC_RdyActiveLow = 0, /*!< Adv active low. */
  233. kSEMC_RdyActivehigh, /*!< Adv active low. */
  234. } semc_rdy_polarity_t;
  235. /*! @brief SEMC IP command for NAND: address mode. */
  236. typedef enum _semc_ipcmd_nand_addrmode {
  237. kSEMC_NANDAM_ColumnRow = 0x0U, /*!< Address mode: column and row address(5Byte-CA0/CA1/RA0/RA1/RA2). */
  238. kSEMC_NANDAM_ColumnCA0, /*!< Address mode: column address only(1 Byte-CA0). */
  239. kSEMC_NANDAM_ColumnCA0CA1, /*!< Address mode: column address only(2 Byte-CA0/CA1). */
  240. kSEMC_NANDAM_RawRA0, /*!< Address mode: row address only(1 Byte-RA0). */
  241. kSEMC_NANDAM_RawRA0RA1, /*!< Address mode: row address only(2 Byte-RA0/RA1). */
  242. kSEMC_NANDAM_RawRA0RA1RA2 /*!< Address mode: row address only(3 Byte-RA0). */
  243. } semc_ipcmd_nand_addrmode_t;
  244. /*! @brief SEMC IP command for NAND: command mode. */
  245. typedef enum _semc_ipcmd_nand_cmdmode {
  246. kSEMC_NANDCM_AXICmdAddrRead = 0x0U, /*!< For AXI read. */
  247. kSEMC_NANDCM_AXICmdAddrWrite, /*!< For AXI write. */
  248. kSEMC_NANDCM_Command, /*!< command. */
  249. kSEMC_NANDCM_CommandHold, /*!< Command hold. */
  250. kSEMC_NANDCM_CommandAddress, /*!< Command address. */
  251. kSEMC_NANDCM_CommandAddressHold, /*!< Command address hold. */
  252. kSEMC_NANDCM_CommandAddressRead, /*!< Command address read. */
  253. kSEMC_NANDCM_CommandAddressWrite, /*!< Command address write. */
  254. kSEMC_NANDCM_CommandRead, /*!< Command read. */
  255. kSEMC_NANDCM_CommandWrite, /*!< Command write. */
  256. kSEMC_NANDCM_Read, /*!< Read. */
  257. kSEMC_NANDCM_Write /*!< Write. */
  258. } semc_ipcmd_nand_cmdmode_t;
  259. /*! @brief SEMC NAND address option. */
  260. typedef enum _semc_nand_address_option {
  261. kSEMC_NandAddrOption_5byte_CA2RA3 = 0U, /*!< CA0+CA1+RA0+RA1+RA2 */
  262. kSEMC_NandAddrOption_4byte_CA2RA2 = 2U, /*!< CA0+CA1+RA0+RA1 */
  263. kSEMC_NandAddrOption_3byte_CA2RA1 = 4U, /*!< CA0+CA1+RA0 */
  264. kSEMC_NandAddrOption_4byte_CA1RA3 = 1U, /*!< CA0+RA0+RA1+RA2 */
  265. kSEMC_NandAddrOption_3byte_CA1RA2 = 3U, /*!< CA0+RA0+RA1 */
  266. kSEMC_NandAddrOption_2byte_CA1RA1 = 7U, /*!< CA0+RA0 */
  267. } semc_nand_address_option_t;
  268. /*! @brief SEMC IP command for NOR. */
  269. typedef enum _semc_ipcmd_nor_dbi {
  270. kSEMC_NORDBICM_Read = 0x2U, /*!< NOR read. */
  271. kSEMC_NORDBICM_Write /*!< NOR write. */
  272. } semc_ipcmd_nor_dbi_t;
  273. /*! @brief SEMC IP command for SRAM. */
  274. typedef enum _semc_ipcmd_sram {
  275. kSEMC_SRAMCM_ArrayRead = 0x2U, /*!< SRAM memory array read. */
  276. kSEMC_SRAMCM_ArrayWrite, /*!< SRAM memory array write. */
  277. kSEMC_SRAMCM_RegRead, /*!< SRAM memory register read. */
  278. kSEMC_SRAMCM_RegWrite /*!< SRAM memory register write. */
  279. } semc_ipcmd_sram_t;
  280. /*! @brief SEMC IP command for SDARM. */
  281. typedef enum _semc_ipcmd_sdram {
  282. kSEMC_SDRAMCM_Read = 0x8U, /*!< SDRAM memory read. */
  283. kSEMC_SDRAMCM_Write, /*!< SDRAM memory write. */
  284. kSEMC_SDRAMCM_Modeset, /*!< SDRAM MODE SET. */
  285. kSEMC_SDRAMCM_Active, /*!< SDRAM active. */
  286. kSEMC_SDRAMCM_AutoRefresh, /*!< SDRAM auto-refresh. */
  287. kSEMC_SDRAMCM_SelfRefresh, /*!< SDRAM self-refresh. */
  288. kSEMC_SDRAMCM_Precharge, /*!< SDRAM precharge. */
  289. kSEMC_SDRAMCM_Prechargeall /*!< SDRAM precharge all. */
  290. } semc_ipcmd_sdram_t;
  291. /*! @brief SEMC SDRAM configuration structure.
  292. *
  293. * 1. The memory size in the configuration is in the unit of KB. So memsize_kbytes
  294. * should be set as 2^2, 2^3, 2^4 .etc which is base 2KB exponential function.
  295. * Take refer to BR0~BR3 register in RM for details.
  296. * 2. The prescalePeriod_N16Cycle is in unit of 16 clock cycle. It is a exception for prescaleTimer_n16cycle = 0,
  297. * it means the prescaler timer period is 256 * 16 clock cycles. For precalerIf precalerTimer_n16cycle not equal to 0,
  298. * The prescaler timer period is prescalePeriod_N16Cycle * 16 clock cycles.
  299. * idleTimeout_NprescalePeriod, refreshUrgThreshold_NprescalePeriod, refreshPeriod_NprescalePeriod are
  300. * similar to prescalePeriod_N16Cycle.
  301. *
  302. */
  303. typedef struct _semc_sdram_config
  304. {
  305. semc_iomux_pin csxPinMux; /*!< CS pin mux. The kSEMC_MUXA8 is not valid in sdram pin mux setting. */
  306. uint32_t address; /*!< The base address. */
  307. uint32_t memsize_kbytes; /*!< The memory size in unit of kbytes. */
  308. smec_port_size_t portSize; /*!< Port size. */
  309. sem_sdram_burst_len_t burstLen; /*!< Burst length. */
  310. semc_sdram_column_bit_num_t columnAddrBitNum; /*!< Column address bit number. */
  311. semc_caslatency_t casLatency; /*!< CAS latency. */
  312. uint8_t tPrecharge2Act_Ns; /*!< Precharge to active wait time in unit of nanosecond. */
  313. uint8_t tAct2ReadWrtie_Ns; /*!< Act to read/write wait time in unit of nanosecond. */
  314. uint8_t tRefreshRecovery_Ns; /*!< Refresh recovery time in unit of nanosecond. */
  315. uint8_t tWriteRecovery_Ns; /*!< write recovery time in unit of nanosecond. */
  316. uint8_t tCkeOff_Ns; /*!< CKE off minimum time in unit of nanosecond. */
  317. uint8_t tAct2Prechage_Ns; /*!< Active to precharge in unit of nanosecond. */
  318. uint8_t tSelfRefRecovery_Ns; /*!< Self refresh recovery time in unit of nanosecond. */
  319. uint8_t tRefresh2Refresh_Ns; /*!< Refresh to refresh wait time in unit of nanosecond. */
  320. uint8_t tAct2Act_Ns; /*!< Active to active wait time in unit of nanosecond. */
  321. uint32_t tPrescalePeriod_Ns; /*!< Prescaler timer period should not be larger than 256 * 16 * clock cycle. */
  322. uint32_t tIdleTimeout_Ns; /*!< Idle timeout in unit of prescale time period. */
  323. uint32_t refreshPeriod_nsPerRow; /*!< Refresh timer period like 64ms * 1000000/8192 . */
  324. uint32_t refreshUrgThreshold; /*!< Refresh urgent threshold. */
  325. uint8_t refreshBurstLen; /*!< Refresh burst length. */
  326. } semc_sdram_config_t;
  327. /*! @brief SEMC NAND configuration structure. */
  328. typedef struct _semc_nand_config
  329. {
  330. semc_iomux_pin cePinMux; /*!< The CE pin mux setting. The kSEMC_MUXRDY is not valid for CE pin setting. */
  331. uint32_t axiAddress; /*!< The base address for AXI nand. */
  332. uint32_t axiMemsize_kbytes; /*!< The memory size in unit of kbytes for AXI nand. */
  333. uint32_t ipgAddress; /*!< The base address for IPG nand . */
  334. uint32_t ipgMemsize_kbytes; /*!< The memory size in unit of kbytes for IPG nand. */
  335. semc_rdy_polarity_t rdyactivePolarity; /*!< Wait ready polarity. */
  336. bool edoModeEnabled; /*!< EDO mode enabled. */
  337. semc_nand_column_bit_num_t columnAddrBitNum; /*!< Column address bit number. */
  338. semc_nand_address_option_t arrayAddrOption; /*!< Address option. */
  339. sem_nand_burst_len_t burstLen; /*!< Burst length. */
  340. smec_port_size_t portSize; /*!< Port size. */
  341. uint8_t tCeSetup_Ns; /*!< CE setup time: tCS. */
  342. uint8_t tCeHold_Ns; /*!< CE hold time: tCH. */
  343. uint8_t tCeInterval_Ns; /*!< CE interval time:tCEITV. */
  344. uint8_t tWeLow_Ns; /*!< WE low time: tWP. */
  345. uint8_t tWeHigh_Ns; /*!< WE high time: tWH. */
  346. uint8_t tReLow_Ns; /*!< RE low time: tRP. */
  347. uint8_t tReHigh_Ns; /*!< RE high time: tREH. */
  348. uint8_t tTurnAround_Ns; /*!< Turnaround time for async mode: tTA. */
  349. uint8_t tWehigh2Relow_Ns; /*!< WE# high to RE# wait time: tWHR. */
  350. uint8_t tRehigh2Welow_Ns; /*!< RE# high to WE# low wait time: tRHW. */
  351. uint8_t tAle2WriteStart_Ns; /*!< ALE to write start wait time: tADL. */
  352. uint8_t tReady2Relow_Ns; /*!< Ready to RE# low min wait time: tRR. */
  353. uint8_t tWehigh2Busy_Ns; /*!< WE# high to busy wait time: tWB. */
  354. } semc_nand_config_t;
  355. /*! @brief SEMC NOR configuration structure. */
  356. typedef struct _semc_nor_config
  357. {
  358. semc_iomux_pin cePinMux; /*!< The CE# pin mux setting. */
  359. semc_iomux_nora27_pin addr27; /*!< The Addr bit 27 pin mux setting. */
  360. uint32_t address; /*!< The base address. */
  361. uint32_t memsize_kbytes; /*!< The memory size in unit of kbytes. */
  362. uint8_t addrPortWidth; /*!< The address port width. */
  363. semc_rdy_polarity_t rdyactivePolarity; /*!< Wait ready polarity. */
  364. semc_adv_polarity_t advActivePolarity; /*!< ADV# polarity. */
  365. semc_norsram_column_bit_num_t columnAddrBitNum; /*!< Column address bit number. */
  366. semc_addr_mode_t addrMode; /*!< Address mode. */
  367. sem_norsram_burst_len_t burstLen; /*!< Burst length. */
  368. smec_port_size_t portSize; /*!< Port size. */
  369. uint8_t tCeSetup_Ns; /*!< The CE setup time. */
  370. uint8_t tCeHold_Ns; /*!< The CE hold time. */
  371. uint8_t tCeInterval_Ns; /*!< CE interval minimum time. */
  372. uint8_t tAddrSetup_Ns; /*!< The address setup time. */
  373. uint8_t tAddrHold_Ns; /*!< The address hold time. */
  374. uint8_t tWeLow_Ns; /*!< WE low time for async mode. */
  375. uint8_t tWeHigh_Ns; /*!< WE high time for async mode. */
  376. uint8_t tReLow_Ns; /*!< RE low time for async mode. */
  377. uint8_t tReHigh_Ns; /*!< RE high time for async mode. */
  378. uint8_t tTurnAround_Ns; /*!< Turnaround time for async mode. */
  379. uint8_t tAddr2WriteHold_Ns; /*!< Address to write data hold time for async mode. */
  380. uint8_t tWriteSetup_Ns; /*!< Write data setup time for sync mode.*/
  381. uint8_t tWriteHold_Ns; /*!< Write hold time for sync mode. */
  382. uint8_t latencyCount; /*!< Latency count for sync mode. */
  383. uint8_t readCycle; /*!< Read cycle time for sync mode. */
  384. } semc_nor_config_t;
  385. /*! @brief SEMC SRAM configuration structure. */
  386. typedef struct _semc_sram_config
  387. {
  388. semc_iomux_pin cePinMux; /*!< The CE# pin mux setting. */
  389. semc_iomux_nora27_pin addr27; /*!< The Addr bit 27 pin mux setting. */
  390. uint32_t address; /*!< The base address. */
  391. uint32_t memsize_kbytes; /*!< The memory size in unit of kbytes. */
  392. uint8_t addrPortWidth; /*!< The address port width. */
  393. semc_adv_polarity_t advActivePolarity; /*!< ADV# polarity 1: active high, 0: active low. */
  394. semc_addr_mode_t addrMode; /*!< Address mode. */
  395. sem_norsram_burst_len_t burstLen; /*!< Burst length. */
  396. smec_port_size_t portSize; /*!< Port size. */
  397. uint8_t tCeSetup_Ns; /*!< The CE setup time. */
  398. uint8_t tCeHold_Ns; /*!< The CE hold time. */
  399. uint8_t tCeInterval_Ns; /*!< CE interval minimum time. */
  400. uint8_t tAddrSetup_Ns; /*!< The address setup time. */
  401. uint8_t tAddrHold_Ns; /*!< The address hold time. */
  402. uint8_t tWeLow_Ns; /*!< WE low time for async mode. */
  403. uint8_t tWeHigh_Ns; /*!< WE high time for async mode. */
  404. uint8_t tReLow_Ns; /*!< RE low time for async mode. */
  405. uint8_t tReHigh_Ns; /*!< RE high time for async mode. */
  406. uint8_t tTurnAround_Ns; /*!< Turnaround time for async mode. */
  407. uint8_t tAddr2WriteHold_Ns; /*!< Address to write data hold time for async mode. */
  408. uint8_t tWriteSetup_Ns; /*!< Write data setup time for sync mode.*/
  409. uint8_t tWriteHold_Ns; /*!< Write hold time for sync mode. */
  410. uint8_t latencyCount; /*!< Latency count for sync mode. */
  411. uint8_t readCycle; /*!< Read cycle time for sync mode. */
  412. } semc_sram_config_t;
  413. /*! @brief SEMC DBI configuration structure. */
  414. typedef struct _semc_dbi_config
  415. {
  416. semc_iomux_pin csxPinMux; /*!< The CE# pin mux. */
  417. uint32_t address; /*!< The base address. */
  418. uint32_t memsize_kbytes; /*!< The memory size in unit of 4kbytes. */
  419. semc_dbi_column_bit_num_t columnAddrBitNum; /*!< Column address bit number. */
  420. sem_dbi_burst_len_t burstLen; /*!< Burst length. */
  421. smec_port_size_t portSize; /*!< Port size. */
  422. uint8_t tCsxSetup_Ns; /*!< The CSX setup time. */
  423. uint8_t tCsxHold_Ns; /*!< The CSX hold time. */
  424. uint8_t tWexLow_Ns; /*!< WEX low time. */
  425. uint8_t tWexHigh_Ns; /*!< WEX high time. */
  426. uint8_t tRdxLow_Ns; /*!< RDX low time. */
  427. uint8_t tRdxHigh_Ns; /*!< RDX high time. */
  428. uint8_t tCsxInterval_Ns; /*!< Write data setup time.*/
  429. } semc_dbi_config_t;
  430. /*! @brief SEMC AXI queue a weight setting. */
  431. typedef struct _semc_queuea_weight
  432. {
  433. uint32_t qos : 4; /*!< weight of qos for queue 0 . */
  434. uint32_t aging : 4; /*!< weight of aging for queue 0.*/
  435. uint32_t slaveHitSwith : 8; /*!< weight of read/write switch for queue 0.*/
  436. uint32_t slaveHitNoswitch : 8; /*!< weight of read/write no switch for queue 0 .*/
  437. } semc_queuea_weight_t;
  438. /*! @brief SEMC AXI queue b weight setting. */
  439. typedef struct _semc_queueb_weight
  440. {
  441. uint32_t qos : 4; /*!< weight of qos for queue 1. */
  442. uint32_t aging : 4; /*!< weight of aging for queue 1.*/
  443. uint32_t slaveHitSwith : 8; /*!< weight of read/write switch for queue 1.*/
  444. uint32_t weightPagehit : 8; /*!< weight of page hit for queue 1 only .*/
  445. uint32_t bankRotation : 8; /*!< weight of bank rotation for queue 1 only .*/
  446. } semc_queueb_weight_t;
  447. /*! @brief SEMC AXI queue weight setting. */
  448. typedef struct _semc_axi_queueweight
  449. {
  450. semc_queuea_weight_t *queueaWeight; /*!< Weight settings for queue a. */
  451. semc_queueb_weight_t *queuebWeight; /*!< Weight settings for queue b. */
  452. } semc_axi_queueweight_t;
  453. /*!
  454. * @brief SEMC configuration structure.
  455. *
  456. * busTimeoutCycles: when busTimeoutCycles is zero, the bus timeout cycle is
  457. * 255*1024. otherwise the bus timeout cycles is busTimeoutCycles*1024.
  458. * cmdTimeoutCycles: is used for command execution timeout cycles. it's
  459. * similar to the busTimeoutCycles.
  460. */
  461. typedef struct _semc_config_t
  462. {
  463. semc_dqs_mode_t dqsMode; /*!< Dummy read strobe mode: use enum in "semc_dqs_mode_t". */
  464. uint8_t cmdTimeoutCycles; /*!< Command execution timeout cycles. */
  465. uint8_t busTimeoutCycles; /*!< Bus timeout cycles. */
  466. semc_axi_queueweight_t queueWeight; /*!< AXI queue weight. */
  467. } semc_config_t;
  468. /*******************************************************************************
  469. * API
  470. ******************************************************************************/
  471. #if defined(__cplusplus)
  472. extern "C" {
  473. #endif
  474. /*!
  475. * @name SEMC Initialization and De-initialization
  476. * @{
  477. */
  478. /*!
  479. * @brief Gets the SEMC default basic configuration structure.
  480. *
  481. * The purpose of this API is to get the default SEMC
  482. * configure structure for SEMC_Init(). User may use the initialized
  483. * structure unchanged in SEMC_Init(), or modify some fields of the
  484. * structure before calling SEMC_Init().
  485. * Example:
  486. @code
  487. semc_config_t config;
  488. SEMC_GetDefaultConfig(&config);
  489. @endcode
  490. * @param config The SEMC configuration structure pointer.
  491. */
  492. void SEMC_GetDefaultConfig(semc_config_t *config);
  493. /*!
  494. * @brief Initializes SEMC.
  495. * This function ungates the SEMC clock and initializes SEMC.
  496. * This function must be called before calling any other SEMC driver functions.
  497. *
  498. * @param base SEMC peripheral base address.
  499. * @param configure The SEMC configuration structure pointer.
  500. */
  501. void SEMC_Init(SEMC_Type *base, semc_config_t *configure);
  502. /*!
  503. * @brief Deinitializes the SEMC module and gates the clock.
  504. * This function gates the SEMC clock. As a result, the SEMC
  505. * module doesn't work after calling this function.
  506. *
  507. * @param base SEMC peripheral base address.
  508. */
  509. void SEMC_Deinit(SEMC_Type *base);
  510. /* @} */
  511. /*!
  512. * @name SEMC Configuration Operation For Each Memory Type
  513. * @{
  514. */
  515. /*!
  516. * @brief Configures SDRAM controller in SEMC.
  517. *
  518. * @param base SEMC peripheral base address.
  519. * @param cs The chip selection.
  520. * @param config The sdram configuration.
  521. * @param clkSrc_Hz The SEMC clock frequency.
  522. */
  523. status_t SEMC_ConfigureSDRAM(SEMC_Type *base, semc_sdram_cs_t cs, semc_sdram_config_t *config, uint32_t clkSrc_Hz);
  524. /*!
  525. * @brief Configures NAND controller in SEMC.
  526. *
  527. * @param base SEMC peripheral base address.
  528. * @param config The nand configuration.
  529. * @param clkSrc_Hz The SEMC clock frequency.
  530. */
  531. status_t SEMC_ConfigureNAND(SEMC_Type *base, semc_nand_config_t *config, uint32_t clkSrc_Hz);
  532. /*!
  533. * @brief Configures NOR controller in SEMC.
  534. *
  535. * @param base SEMC peripheral base address.
  536. * @param config The nor configuration.
  537. * @param clkSrc_Hz The SEMC clock frequency.
  538. */
  539. status_t SEMC_ConfigureNOR(SEMC_Type *base, semc_nor_config_t *config, uint32_t clkSrc_Hz);
  540. /*!
  541. * @brief Configures SRAM controller in SEMC.
  542. *
  543. * @param base SEMC peripheral base address.
  544. * @param config The sram configuration.
  545. * @param clkSrc_Hz The SEMC clock frequency.
  546. */
  547. status_t SEMC_ConfigureSRAM(SEMC_Type *base, semc_sram_config_t *config, uint32_t clkSrc_Hz);
  548. /*!
  549. * @brief Configures DBI controller in SEMC.
  550. *
  551. * @param base SEMC peripheral base address.
  552. * @param config The dbi configuration.
  553. * @param clkSrc_Hz The SEMC clock frequency.
  554. */
  555. status_t SEMC_ConfigureDBI(SEMC_Type *base, semc_dbi_config_t *config, uint32_t clkSrc_Hz);
  556. /* @} */
  557. /*!
  558. * @name SEMC Interrupt Operation
  559. * @{
  560. */
  561. /*!
  562. * @brief Enables the SEMC interrupt.
  563. *
  564. * This function enables the SEMC interrupts according to the provided mask. The mask
  565. * is a logical OR of enumeration members. See @ref semc_interrupt_enable_t.
  566. * For example, to enable the IP command done and error interrupt, do the following.
  567. * @code
  568. * SEMC_EnableInterrupts(ENET, kSEMC_IPCmdDoneInterrupt | kSEMC_IPCmdErrInterrupt);
  569. * @endcode
  570. *
  571. * @param base SEMC peripheral base address.
  572. * @param mask SEMC interrupts to enable. This is a logical OR of the
  573. * enumeration :: semc_interrupt_enable_t.
  574. */
  575. static inline void SEMC_EnableInterrupts(SEMC_Type *base, uint32_t mask)
  576. {
  577. base->INTEN |= mask;
  578. }
  579. /*!
  580. * @brief Disables the SEMC interrupt.
  581. *
  582. * This function disables the SEMC interrupts according to the provided mask. The mask
  583. * is a logical OR of enumeration members. See @ref semc_interrupt_enable_t.
  584. * For example, to disable the IP command done and error interrupt, do the following.
  585. * @code
  586. * SEMC_DisableInterrupts(ENET, kSEMC_IPCmdDoneInterrupt | kSEMC_IPCmdErrInterrupt);
  587. * @endcode
  588. *
  589. * @param base SEMC peripheral base address.
  590. * @param mask SEMC interrupts to disable. This is a logical OR of the
  591. * enumeration :: semc_interrupt_enable_t.
  592. */
  593. static inline void SEMC_DisableInterrupts(SEMC_Type *base, uint32_t mask)
  594. {
  595. base->INTEN &= ~mask;
  596. }
  597. /*!
  598. * @brief Gets the SEMC status.
  599. *
  600. * This function gets the SEMC interrupts event status.
  601. * User can use the a logical OR of enumeration member as a mask.
  602. * See @ref semc_interrupt_enable_t.
  603. *
  604. * @param base SEMC peripheral base address.
  605. * @return status flag, use status flag in semc_interrupt_enable_t to get the related status.
  606. */
  607. static inline bool SEMC_GetStatusFlag(SEMC_Type *base)
  608. {
  609. return base->INTR;
  610. }
  611. /*!
  612. * @brief Clears the SEMC status flag state.
  613. *
  614. * The following status register flags can be cleared SEMC interrupt status.
  615. *
  616. * @param base SEMC base pointer
  617. * @param mask The status flag mask, a logical OR of enumeration member @ref semc_interrupt_enable_t.
  618. */
  619. static inline void SEMC_ClearStatusFlags(SEMC_Type *base, uint32_t mask)
  620. {
  621. base->INTR |= mask;
  622. }
  623. /* @} */
  624. /*!
  625. * @name SEMC Memory Access Operation
  626. * @{
  627. */
  628. /*!
  629. * @brief Check if SEMC is in idle.
  630. *
  631. * @param base SEMC peripheral base address.
  632. * @return True SEMC is in idle, false is not in idle.
  633. */
  634. static inline bool SEMC_IsInIdle(SEMC_Type *base)
  635. {
  636. return (base->STS0 & SEMC_STS0_IDLE_MASK) ? true : false;
  637. }
  638. /*!
  639. * @brief SEMC IP command access.
  640. *
  641. * @param base SEMC peripheral base address.
  642. * @param type SEMC memory type. refer to "semc_mem_type_t"
  643. * @param address SEMC device address.
  644. * @param command SEMC IP command.
  645. * For NAND device, we should use the SEMC_BuildNandIPCommand to get the right nand command.
  646. * For NOR/DBI device, take refer to "semc_ipcmd_nor_dbi_t".
  647. * For SRAM device, take refer to "semc_ipcmd_sram_t".
  648. * For SDRAM device, take refer to "semc_ipcmd_sdram_t".
  649. * @param write Data for write access.
  650. * @param read Data pointer for read data out.
  651. */
  652. status_t SEMC_SendIPCommand(
  653. SEMC_Type *base, semc_mem_type_t type, uint32_t address, uint16_t command, uint32_t write, uint32_t *read);
  654. /*!
  655. * @brief Build SEMC IP command for NAND.
  656. *
  657. * This function build SEMC NAND IP command. The command is build of user command code,
  658. * SEMC address mode and SEMC command mode.
  659. *
  660. * @param userCommand NAND device normal command.
  661. * @param addrMode NAND address mode. Refer to "semc_ipcmd_nand_addrmode_t".
  662. * @param cmdMode NAND command mode. Refer to "semc_ipcmd_nand_cmdmode_t".
  663. */
  664. static inline uint16_t SEMC_BuildNandIPCommand(uint8_t userCommand,
  665. semc_ipcmd_nand_addrmode_t addrMode,
  666. semc_ipcmd_nand_cmdmode_t cmdMode)
  667. {
  668. return (uint16_t)((uint16_t)userCommand << 8) | (uint16_t)(addrMode << 4) | ((uint8_t)cmdMode & 0x0Fu);
  669. }
  670. /*!
  671. * @brief Check if the NAND device is ready.
  672. *
  673. * @param base SEMC peripheral base address.
  674. * @return True NAND is ready, false NAND is not ready.
  675. */
  676. static inline bool SEMC_IsNandReady(SEMC_Type *base)
  677. {
  678. return (base->STS0 & SEMC_STS0_NARDY_MASK) ? true : false;
  679. }
  680. /*!
  681. * @brief SEMC NAND device memory write through IP command.
  682. *
  683. * @param base SEMC peripheral base address.
  684. * @param address SEMC NAND device address.
  685. * @param data Data for write access.
  686. * @param size_bytes Data length.
  687. */
  688. status_t SEMC_IPCommandNandWrite(SEMC_Type *base, uint32_t address, uint8_t *data, uint32_t size_bytes);
  689. /*!
  690. * @brief SEMC NAND device memory read through IP command.
  691. *
  692. * @param base SEMC peripheral base address.
  693. * @param address SEMC NAND device address.
  694. * @param data Data pointer for data read out.
  695. * @param size_bytes Data length.
  696. */
  697. status_t SEMC_IPCommandNandRead(SEMC_Type *base, uint32_t address, uint8_t *data, uint32_t size_bytes);
  698. /*!
  699. * @brief SEMC NOR device memory write through IP command.
  700. *
  701. * @param base SEMC peripheral base address.
  702. * @param address SEMC NOR device address.
  703. * @param data Data for write access.
  704. * @param size_bytes Data length.
  705. */
  706. status_t SEMC_IPCommandNorWrite(SEMC_Type *base, uint32_t address, uint8_t *data, uint32_t size_bytes);
  707. /*!
  708. * @brief SEMC NOR device memory read through IP command.
  709. *
  710. * @param base SEMC peripheral base address.
  711. * @param address SEMC NOR device address.
  712. * @param data Data pointer for data read out.
  713. * @param size_bytes Data length.
  714. */
  715. status_t SEMC_IPCommandNorRead(SEMC_Type *base, uint32_t address, uint8_t *data, uint32_t size_bytes);
  716. /* @} */
  717. #if defined(__cplusplus)
  718. }
  719. #endif
  720. /*! @}*/
  721. #endif /* _FSL_SEMC_H_*/