fsl_semc.h 35 KB

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