gd32f4xx_exmc.c 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237
  1. /*!
  2. \file gd32f4xx_exmc.c
  3. \brief EXMC driver
  4. \version 2016-08-15, V1.0.0, firmware for GD32F4xx
  5. \version 2018-12-12, V2.0.0, firmware for GD32F4xx
  6. \version 2020-09-30, V2.1.0, firmware for GD32F4xx
  7. */
  8. /*
  9. Copyright (c) 2020, GigaDevice Semiconductor Inc.
  10. Redistribution and use in source and binary forms, with or without modification,
  11. are permitted provided that the following conditions are met:
  12. 1. Redistributions of source code must retain the above copyright notice, this
  13. list of conditions and the following disclaimer.
  14. 2. Redistributions in binary form must reproduce the above copyright notice,
  15. this list of conditions and the following disclaimer in the documentation
  16. and/or other materials provided with the distribution.
  17. 3. Neither the name of the copyright holder nor the names of its contributors
  18. may be used to endorse or promote products derived from this software without
  19. specific prior written permission.
  20. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  22. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  23. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  24. INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  25. NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  26. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  27. WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
  29. OF SUCH DAMAGE.
  30. */
  31. #include "gd32f4xx_exmc.h"
  32. /* EXMC bank0 register reset value */
  33. #define BANK0_SNCTL_RESET ((uint32_t)0x000030DAU)
  34. #define BANK0_SNTCFG_RESET ((uint32_t)0x0FFFFFFFU)
  35. #define BANK0_SNWTCFG_RESET ((uint32_t)0x0FFFFFFFU)
  36. /* EXMC bank1/2 register reset mask */
  37. #define BANK1_2_NPCTL_RESET ((uint32_t)0x00000008U)
  38. #define BANK1_2_NPINTEN_RESET ((uint32_t)0x00000042U)
  39. #define BANK1_2_NPCTCFG_RESET ((uint32_t)0xFFFFFFFFU)
  40. #define BANK1_2_NPATCFG_RESET ((uint32_t)0xFFFFFFFFU)
  41. /* EXMC bank3 register reset mask */
  42. #define BANK3_NPCTL_RESET ((uint32_t)0x00000008U)
  43. #define BANK3_NPINTEN_RESET ((uint32_t)0x00000040U)
  44. #define BANK3_NPCTCFG_RESET ((uint32_t)0xFFFFFFFFU)
  45. #define BANK3_NPATCFG_RESET ((uint32_t)0xFFFFFFFFU)
  46. #define BANK3_PIOTCFG3_RESET ((uint32_t)0xFFFFFFFFU)
  47. /* EXMC SDRAM device register reset mask */
  48. #define SDRAM_DEVICE_SDCTL_RESET ((uint32_t)0x000002D0U)
  49. #define SDRAM_DEVICE_SDTCFG_RESET ((uint32_t)0x0FFFFFFFU)
  50. #define SDRAM_DEVICE_SDCMD_RESET ((uint32_t)0x00000000U)
  51. #define SDRAM_DEVICE_SDARI_RESET ((uint32_t)0x00000000U)
  52. #define SDRAM_DEVICE_SDSTAT_RESET ((uint32_t)0x00000000U)
  53. #define SDRAM_DEVICE_SDRSCTL_RESET ((uint32_t)0x00000000U)
  54. /* EXMC bank0 SQPI-PSRAM register reset mask */
  55. #define BANK0_SQPI_SINIT_RESET ((uint32_t)0x18010000U)
  56. #define BANK0_SQPI_SRCMD_RESET ((uint32_t)0x00000000U)
  57. #define BANK0_SQPI_SWCMD_RESET ((uint32_t)0x00000000U)
  58. #define BANK0_SQPI_SIDL_RESET ((uint32_t)0x00000000U)
  59. #define BANK0_SQPI_SIDH_RESET ((uint32_t)0x00000000U)
  60. /* EXMC register bit offset */
  61. #define SNCTL_NRMUX_OFFSET ((uint32_t)1U)
  62. #define SNCTL_SBRSTEN_OFFSET ((uint32_t)8U)
  63. #define SNCTL_WRAPEN_OFFSET ((uint32_t)10U)
  64. #define SNCTL_WREN_OFFSET ((uint32_t)12U)
  65. #define SNCTL_NRWTEN_OFFSET ((uint32_t)13U)
  66. #define SNCTL_EXMODEN_OFFSET ((uint32_t)14U)
  67. #define SNCTL_ASYNCWAIT_OFFSET ((uint32_t)15U)
  68. #define SNTCFG_AHLD_OFFSET ((uint32_t)4U)
  69. #define SNTCFG_DSET_OFFSET ((uint32_t)8U)
  70. #define SNTCFG_BUSLAT_OFFSET ((uint32_t)16U)
  71. #define NPCTL_NDWTEN_OFFSET ((uint32_t)1U)
  72. #define NPCTL_ECCEN_OFFSET ((uint32_t)6U)
  73. #define NPCTCFG_COMWAIT_OFFSET ((uint32_t)8U)
  74. #define NPCTCFG_COMHLD_OFFSET ((uint32_t)16U)
  75. #define NPCTCFG_COMHIZ_OFFSET ((uint32_t)24U)
  76. #define NPATCFG_ATTWAIT_OFFSET ((uint32_t)8U)
  77. #define NPATCFG_ATTHLD_OFFSET ((uint32_t)16U)
  78. #define NPATCFG_ATTHIZ_OFFSET ((uint32_t)24U)
  79. #define PIOTCFG_IOWAIT_OFFSET ((uint32_t)8U)
  80. #define PIOTCFG_IOHLD_OFFSET ((uint32_t)16U)
  81. #define PIOTCFG_IOHIZ_OFFSET ((uint32_t)24U)
  82. #define SDCTL_WPEN_OFFSET ((uint32_t)9U)
  83. #define SDCTL_BRSTRD_OFFSET ((uint32_t)12U)
  84. #define SDTCFG_XSRD_OFFSET ((uint32_t)4U)
  85. #define SDTCFG_RASD_OFFSET ((uint32_t)8U)
  86. #define SDTCFG_ARFD_OFFSET ((uint32_t)12U)
  87. #define SDTCFG_WRD_OFFSET ((uint32_t)16U)
  88. #define SDTCFG_RPD_OFFSET ((uint32_t)20U)
  89. #define SDTCFG_RCD_OFFSET ((uint32_t)24U)
  90. #define SDCMD_NARF_OFFSET ((uint32_t)5U)
  91. #define SDCMD_MRC_OFFSET ((uint32_t)9U)
  92. #define SDARI_ARINTV_OFFSET ((uint32_t)1U)
  93. #define SDRSCTL_SSCR_OFFSET ((uint32_t)1U)
  94. #define SDRSCTL_SDSC_OFFSET ((uint32_t)4U)
  95. #define SDSTAT_STA0_OFFSET ((uint32_t)1U)
  96. #define SDSTAT_STA1_OFFSET ((uint32_t)3U)
  97. #define SRCMD_RWAITCYCLE_OFFSET ((uint32_t)16U)
  98. #define SWCMD_WWAITCYCLE_OFFSET ((uint32_t)16U)
  99. #define INTEN_INTS_OFFSET ((uint32_t)3U)
  100. /*!
  101. \brief deinitialize EXMC NOR/SRAM region
  102. \param[in] exmc_norsram_region: select the region of bank0
  103. only one parameter can be selected which is shown as below:
  104. \arg EXMC_BANK0_NORSRAM_REGIONx(x=0..3)
  105. \param[out] none
  106. \retval none
  107. */
  108. void exmc_norsram_deinit(uint32_t exmc_norsram_region)
  109. {
  110. /* reset the registers */
  111. EXMC_SNCTL(exmc_norsram_region) = BANK0_SNCTL_RESET;
  112. EXMC_SNTCFG(exmc_norsram_region) = BANK0_SNTCFG_RESET;
  113. EXMC_SNWTCFG(exmc_norsram_region) = BANK0_SNWTCFG_RESET;
  114. }
  115. /*!
  116. \brief initialize exmc_norsram_parameter_struct with the default values
  117. \param[in] none
  118. \param[out] exmc_norsram_init_struct: the initialized struct exmc_norsram_parameter_struct pointer
  119. \retval none
  120. */
  121. void exmc_norsram_struct_para_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
  122. {
  123. /* configure the structure with default values */
  124. exmc_norsram_init_struct->norsram_region = EXMC_BANK0_NORSRAM_REGION0;
  125. exmc_norsram_init_struct->address_data_mux = ENABLE;
  126. exmc_norsram_init_struct->memory_type = EXMC_MEMORY_TYPE_SRAM;
  127. exmc_norsram_init_struct->databus_width = EXMC_NOR_DATABUS_WIDTH_8B;
  128. exmc_norsram_init_struct->burst_mode = DISABLE;
  129. exmc_norsram_init_struct->nwait_polarity = EXMC_NWAIT_POLARITY_LOW;
  130. exmc_norsram_init_struct->wrap_burst_mode = DISABLE;
  131. exmc_norsram_init_struct->nwait_config = EXMC_NWAIT_CONFIG_BEFORE;
  132. exmc_norsram_init_struct->memory_write = ENABLE;
  133. exmc_norsram_init_struct->nwait_signal = ENABLE;
  134. exmc_norsram_init_struct->extended_mode = DISABLE;
  135. exmc_norsram_init_struct->asyn_wait = DISABLE;
  136. exmc_norsram_init_struct->write_mode = EXMC_ASYN_WRITE;
  137. /* configure read/write timing */
  138. exmc_norsram_init_struct->read_write_timing->asyn_address_setuptime = 0xFU;
  139. exmc_norsram_init_struct->read_write_timing->asyn_address_holdtime = 0xFU;
  140. exmc_norsram_init_struct->read_write_timing->asyn_data_setuptime = 0xFFU;
  141. exmc_norsram_init_struct->read_write_timing->bus_latency = 0xFU;
  142. exmc_norsram_init_struct->read_write_timing->syn_clk_division = EXMC_SYN_CLOCK_RATIO_16_CLK;
  143. exmc_norsram_init_struct->read_write_timing->syn_data_latency = EXMC_DATALAT_17_CLK;
  144. exmc_norsram_init_struct->read_write_timing->asyn_access_mode = EXMC_ACCESS_MODE_A;
  145. /* write timing configure, when extended mode is used */
  146. exmc_norsram_init_struct->write_timing->asyn_address_setuptime = 0xFU;
  147. exmc_norsram_init_struct->write_timing->asyn_address_holdtime = 0xFU;
  148. exmc_norsram_init_struct->write_timing->asyn_data_setuptime = 0xFFU;
  149. exmc_norsram_init_struct->write_timing->bus_latency = 0xFU;
  150. exmc_norsram_init_struct->write_timing->asyn_access_mode = EXMC_ACCESS_MODE_A;
  151. }
  152. /*!
  153. \brief initialize EXMC NOR/SRAM region
  154. \param[in] exmc_norsram_parameter_struct: configure the EXMC NOR/SRAM parameter
  155. norsram_region: EXMC_BANK0_NORSRAM_REGIONx, x=0..3
  156. write_mode: EXMC_ASYN_WRITE, EXMC_SYN_WRITE
  157. extended_mode: ENABLE or DISABLE
  158. asyn_wait: ENABLE or DISABLE
  159. nwait_signal: ENABLE or DISABLE
  160. memory_write: ENABLE or DISABLE
  161. nwait_config: EXMC_NWAIT_CONFIG_BEFORE, EXMC_NWAIT_CONFIG_DURING
  162. wrap_burst_mode: ENABLE or DISABLE
  163. nwait_polarity: EXMC_NWAIT_POLARITY_LOW, EXMC_NWAIT_POLARITY_HIGH
  164. burst_mode: ENABLE or DISABLE
  165. databus_width: EXMC_NOR_DATABUS_WIDTH_8B, EXMC_NOR_DATABUS_WIDTH_16B
  166. memory_type: EXMC_MEMORY_TYPE_SRAM, EXMC_MEMORY_TYPE_PSRAM, EXMC_MEMORY_TYPE_NOR
  167. address_data_mux: ENABLE or DISABLE
  168. read_write_timing: struct exmc_norsram_timing_parameter_struct set the time
  169. asyn_access_mode: EXMC_ACCESS_MODE_A, EXMC_ACCESS_MODE_B, EXMC_ACCESS_MODE_C, EXMC_ACCESS_MODE_D
  170. syn_data_latency: EXMC_DATALAT_x_CLK, x=2..17
  171. syn_clk_division: EXMC_SYN_CLOCK_RATIO_x_CLK, x=2..16
  172. bus_latency: 0x0U~0xFU
  173. asyn_data_setuptime: 0x01U~0xFFU
  174. asyn_address_holdtime: 0x1U~0xFU
  175. asyn_address_setuptime: 0x0U~0xFU
  176. write_timing: struct exmc_norsram_timing_parameter_struct set the time
  177. asyn_access_mode: EXMC_ACCESS_MODE_A, EXMC_ACCESS_MODE_B, EXMC_ACCESS_MODE_C, EXMC_ACCESS_MODE_D
  178. syn_data_latency: EXMC_DATALAT_x_CLK, x=2..17
  179. syn_clk_division: EXMC_SYN_CLOCK_RATIO_x_CLK, x=2..16
  180. bus_latency: 0x0U~0xFU
  181. asyn_data_setuptime: 0x01U~0xFFU
  182. asyn_address_holdtime: 0x1U~0xFU
  183. asyn_address_setuptime: 0x0U~0xFU
  184. \param[out] none
  185. \retval none
  186. */
  187. void exmc_norsram_init(exmc_norsram_parameter_struct* exmc_norsram_init_struct)
  188. {
  189. uint32_t snctl = 0x00000000U,sntcfg = 0x00000000U,snwtcfg = 0x00000000U;
  190. /* get the register value */
  191. snctl = EXMC_SNCTL(exmc_norsram_init_struct->norsram_region);
  192. /* clear relative bits */
  193. snctl &= ((uint32_t)~(EXMC_SNCTL_NREN | EXMC_SNCTL_NRTP | EXMC_SNCTL_NRW | EXMC_SNCTL_SBRSTEN |
  194. EXMC_SNCTL_NRWTPOL | EXMC_SNCTL_WRAPEN | EXMC_SNCTL_NRWTCFG | EXMC_SNCTL_WREN |
  195. EXMC_SNCTL_NRWTEN | EXMC_SNCTL_EXMODEN | EXMC_SNCTL_ASYNCWAIT | EXMC_SNCTL_SYNCWR |
  196. EXMC_SNCTL_NRMUX ));
  197. snctl |= (uint32_t)(exmc_norsram_init_struct->address_data_mux << SNCTL_NRMUX_OFFSET) |
  198. exmc_norsram_init_struct->memory_type |
  199. exmc_norsram_init_struct->databus_width |
  200. (exmc_norsram_init_struct->burst_mode << SNCTL_SBRSTEN_OFFSET) |
  201. exmc_norsram_init_struct->nwait_polarity |
  202. (exmc_norsram_init_struct->wrap_burst_mode << SNCTL_WRAPEN_OFFSET) |
  203. exmc_norsram_init_struct->nwait_config |
  204. (exmc_norsram_init_struct->memory_write << SNCTL_WREN_OFFSET) |
  205. (exmc_norsram_init_struct->nwait_signal << SNCTL_NRWTEN_OFFSET) |
  206. (exmc_norsram_init_struct->extended_mode << SNCTL_EXMODEN_OFFSET) |
  207. (exmc_norsram_init_struct->asyn_wait << SNCTL_ASYNCWAIT_OFFSET) |
  208. exmc_norsram_init_struct->write_mode;
  209. sntcfg = (uint32_t)exmc_norsram_init_struct->read_write_timing->asyn_address_setuptime |
  210. (exmc_norsram_init_struct->read_write_timing->asyn_address_holdtime << SNTCFG_AHLD_OFFSET) |
  211. (exmc_norsram_init_struct->read_write_timing->asyn_data_setuptime << SNTCFG_DSET_OFFSET) |
  212. (exmc_norsram_init_struct->read_write_timing->bus_latency << SNTCFG_BUSLAT_OFFSET) |
  213. exmc_norsram_init_struct->read_write_timing->syn_clk_division |
  214. exmc_norsram_init_struct->read_write_timing->syn_data_latency |
  215. exmc_norsram_init_struct->read_write_timing->asyn_access_mode;
  216. /* nor flash access enable */
  217. if(EXMC_MEMORY_TYPE_NOR == exmc_norsram_init_struct->memory_type){
  218. snctl |= (uint32_t)EXMC_SNCTL_NREN;
  219. }
  220. /* extended mode configure */
  221. if(ENABLE == exmc_norsram_init_struct->extended_mode){
  222. snwtcfg = (uint32_t)exmc_norsram_init_struct->write_timing->asyn_address_setuptime |
  223. (exmc_norsram_init_struct->write_timing->asyn_address_holdtime << SNTCFG_AHLD_OFFSET )|
  224. (exmc_norsram_init_struct->write_timing->asyn_data_setuptime << SNTCFG_DSET_OFFSET) |
  225. (exmc_norsram_init_struct->write_timing->bus_latency << SNTCFG_BUSLAT_OFFSET) |
  226. exmc_norsram_init_struct->write_timing->asyn_access_mode;
  227. }else{
  228. snwtcfg = BANK0_SNWTCFG_RESET;
  229. }
  230. /* configure the registers */
  231. EXMC_SNCTL(exmc_norsram_init_struct->norsram_region) = snctl;
  232. EXMC_SNTCFG(exmc_norsram_init_struct->norsram_region) = sntcfg;
  233. EXMC_SNWTCFG(exmc_norsram_init_struct->norsram_region) = snwtcfg;
  234. }
  235. /*!
  236. \brief enable EXMC NOR/PSRAM bank region
  237. \param[in] exmc_norsram_region: specifie the region of NOR/PSRAM bank
  238. only one parameter can be selected which is shown as below:
  239. \arg EXMC_BANK0_NORSRAM_REGIONx(x=0..3)
  240. \param[out] none
  241. \retval none
  242. */
  243. void exmc_norsram_enable(uint32_t exmc_norsram_region)
  244. {
  245. EXMC_SNCTL(exmc_norsram_region) |= (uint32_t)EXMC_SNCTL_NRBKEN;
  246. }
  247. /*!
  248. \brief disable EXMC NOR/PSRAM bank region
  249. \param[in] exmc_norsram_region: specifie the region of NOR/PSRAM Bank
  250. only one parameter can be selected which is shown as below:
  251. \arg EXMC_BANK0_NORSRAM_REGIONx(x=0..3)
  252. \param[out] none
  253. \retval none
  254. */
  255. void exmc_norsram_disable(uint32_t exmc_norsram_region)
  256. {
  257. EXMC_SNCTL(exmc_norsram_region) &= ~(uint32_t)EXMC_SNCTL_NRBKEN;
  258. }
  259. /*!
  260. \brief deinitialize EXMC NAND bank
  261. \param[in] exmc_nand_bank: select the bank of NAND
  262. only one parameter can be selected which is shown as below:
  263. \arg EXMC_BANKx_NAND(x=1..2)
  264. \param[out] none
  265. \retval none
  266. */
  267. void exmc_nand_deinit(uint32_t exmc_nand_bank)
  268. {
  269. /* EXMC_BANK1_NAND or EXMC_BANK2_NAND */
  270. EXMC_NPCTL(exmc_nand_bank) = BANK1_2_NPCTL_RESET;
  271. EXMC_NPINTEN(exmc_nand_bank) = BANK1_2_NPINTEN_RESET;
  272. EXMC_NPCTCFG(exmc_nand_bank) = BANK1_2_NPCTCFG_RESET;
  273. EXMC_NPATCFG(exmc_nand_bank) = BANK1_2_NPATCFG_RESET;
  274. }
  275. /*!
  276. \brief initialize exmc_norsram_parameter_struct with the default values
  277. \param[in] none
  278. \param[out] the initialized struct exmc_norsram_parameter_struct pointer
  279. \retval none
  280. */
  281. void exmc_nand_struct_para_init(exmc_nand_parameter_struct* exmc_nand_init_struct)
  282. {
  283. /* configure the structure with default values */
  284. exmc_nand_init_struct->nand_bank = EXMC_BANK1_NAND;
  285. exmc_nand_init_struct->wait_feature = DISABLE;
  286. exmc_nand_init_struct->databus_width = EXMC_NAND_DATABUS_WIDTH_8B;
  287. exmc_nand_init_struct->ecc_logic = DISABLE;
  288. exmc_nand_init_struct->ecc_size = EXMC_ECC_SIZE_256BYTES;
  289. exmc_nand_init_struct->ctr_latency = 0x0U;
  290. exmc_nand_init_struct->atr_latency = 0x0U;
  291. exmc_nand_init_struct->common_space_timing->setuptime = 0xFCU;
  292. exmc_nand_init_struct->common_space_timing->waittime = 0xFCU;
  293. exmc_nand_init_struct->common_space_timing->holdtime = 0xFCU;
  294. exmc_nand_init_struct->common_space_timing->databus_hiztime = 0xFCU;
  295. exmc_nand_init_struct->attribute_space_timing->setuptime = 0xFCU;
  296. exmc_nand_init_struct->attribute_space_timing->waittime = 0xFCU;
  297. exmc_nand_init_struct->attribute_space_timing->holdtime = 0xFCU;
  298. exmc_nand_init_struct->attribute_space_timing->databus_hiztime = 0xFCU;
  299. }
  300. /*!
  301. \brief initialize EXMC NAND bank
  302. \param[in] exmc_nand_parameter_struct: configure the EXMC NAND parameter
  303. nand_bank: EXMC_BANK1_NAND,EXMC_BANK2_NAND
  304. ecc_size: EXMC_ECC_SIZE_xBYTES,x=256,512,1024,2048,4096
  305. atr_latency: EXMC_ALE_RE_DELAY_x_HCLK,x=1..16
  306. ctr_latency: EXMC_CLE_RE_DELAY_x_HCLK,x=1..16
  307. ecc_logic: ENABLE or DISABLE
  308. databus_width: EXMC_NAND_DATABUS_WIDTH_8B,EXMC_NAND_DATABUS_WIDTH_16B
  309. wait_feature: ENABLE or DISABLE
  310. common_space_timing: struct exmc_nand_pccard_timing_parameter_struct set the time
  311. databus_hiztime: 0x01U~0xFFU
  312. holdtime: 0x01U~0xFEU
  313. waittime: 0x02U~0xFFU
  314. setuptime: 0x01U~0xFFU
  315. attribute_space_timing: struct exmc_nand_pccard_timing_parameter_struct set the time
  316. databus_hiztime: 0x00U~0xFEU
  317. holdtime: 0x01U~0xFEU
  318. waittime: 0x02U~0xFFU
  319. setuptime: 0x01U~0xFFU
  320. \param[out] none
  321. \retval none
  322. */
  323. void exmc_nand_init(exmc_nand_parameter_struct* exmc_nand_init_struct)
  324. {
  325. uint32_t npctl = 0x00000000U, npctcfg = 0x00000000U, npatcfg = 0x00000000U;
  326. npctl = (uint32_t)(exmc_nand_init_struct->wait_feature << NPCTL_NDWTEN_OFFSET)|
  327. EXMC_NPCTL_NDTP |
  328. exmc_nand_init_struct->databus_width |
  329. (exmc_nand_init_struct->ecc_logic << NPCTL_ECCEN_OFFSET)|
  330. exmc_nand_init_struct->ecc_size |
  331. exmc_nand_init_struct->ctr_latency |
  332. exmc_nand_init_struct->atr_latency;
  333. npctcfg = (uint32_t)((exmc_nand_init_struct->common_space_timing->setuptime - 1U) & EXMC_NPCTCFG_COMSET ) |
  334. (((exmc_nand_init_struct->common_space_timing->waittime - 1U) << NPCTCFG_COMWAIT_OFFSET) & EXMC_NPCTCFG_COMWAIT ) |
  335. ((exmc_nand_init_struct->common_space_timing->holdtime << NPCTCFG_COMHLD_OFFSET) & EXMC_NPCTCFG_COMHLD ) |
  336. (((exmc_nand_init_struct->common_space_timing->databus_hiztime - 1U) << NPCTCFG_COMHIZ_OFFSET) & EXMC_NPCTCFG_COMHIZ );
  337. npatcfg = (uint32_t)((exmc_nand_init_struct->attribute_space_timing->setuptime - 1U) & EXMC_NPATCFG_ATTSET ) |
  338. (((exmc_nand_init_struct->attribute_space_timing->waittime - 1U) << NPATCFG_ATTWAIT_OFFSET) & EXMC_NPATCFG_ATTWAIT ) |
  339. ((exmc_nand_init_struct->attribute_space_timing->holdtime << NPATCFG_ATTHLD_OFFSET) & EXMC_NPATCFG_ATTHLD ) |
  340. ((exmc_nand_init_struct->attribute_space_timing->databus_hiztime << NPATCFG_ATTHIZ_OFFSET) & EXMC_NPATCFG_ATTHIZ );
  341. /* EXMC_BANK1_NAND or EXMC_BANK2_NAND initialize */
  342. EXMC_NPCTL(exmc_nand_init_struct->nand_bank) = npctl;
  343. EXMC_NPCTCFG(exmc_nand_init_struct->nand_bank) = npctcfg;
  344. EXMC_NPATCFG(exmc_nand_init_struct->nand_bank) = npatcfg;
  345. }
  346. /*!
  347. \brief enable NAND bank
  348. \param[in] exmc_nand_bank: specifie the NAND bank
  349. only one parameter can be selected which is shown as below:
  350. \arg EXMC_BANKx_NAND(x=1,2)
  351. \param[out] none
  352. \retval none
  353. */
  354. void exmc_nand_enable(uint32_t exmc_nand_bank)
  355. {
  356. EXMC_NPCTL(exmc_nand_bank) |= EXMC_NPCTL_NDBKEN;
  357. }
  358. /*!
  359. \brief disable NAND bank
  360. \param[in] exmc_nand_bank: specifie the NAND bank
  361. only one parameter can be selected which is shown as below:
  362. \arg EXMC_BANKx_NAND(x=1,2)
  363. \param[out] none
  364. \retval none
  365. */
  366. void exmc_nand_disable(uint32_t exmc_nand_bank)
  367. {
  368. EXMC_NPCTL(exmc_nand_bank) &= ~EXMC_NPCTL_NDBKEN;
  369. }
  370. /*!
  371. \brief deinitialize EXMC PC card bank
  372. \param[in] none
  373. \param[out] none
  374. \retval none
  375. */
  376. void exmc_pccard_deinit(void)
  377. {
  378. /* EXMC_BANK3_PCCARD */
  379. EXMC_NPCTL3 = BANK3_NPCTL_RESET;
  380. EXMC_NPINTEN3 = BANK3_NPINTEN_RESET;
  381. EXMC_NPCTCFG3 = BANK3_NPCTCFG_RESET;
  382. EXMC_NPATCFG3 = BANK3_NPATCFG_RESET;
  383. EXMC_PIOTCFG3 = BANK3_PIOTCFG3_RESET;
  384. }
  385. /*!
  386. \brief initialize exmc_pccard_parameter_struct with the default values
  387. \param[in] none
  388. \param[out] the initialized struct exmc_pccard_parameter_struct pointer
  389. \retval none
  390. */
  391. void exmc_pccard_struct_para_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct)
  392. {
  393. /* configure the structure with default values */
  394. exmc_pccard_init_struct->wait_feature = DISABLE;
  395. exmc_pccard_init_struct->ctr_latency = 0x0U;
  396. exmc_pccard_init_struct->atr_latency = 0x0U;
  397. exmc_pccard_init_struct->common_space_timing->setuptime = 0xFCU;
  398. exmc_pccard_init_struct->common_space_timing->waittime = 0xFCU;
  399. exmc_pccard_init_struct->common_space_timing->holdtime = 0xFCU;
  400. exmc_pccard_init_struct->common_space_timing->databus_hiztime = 0xFCU;
  401. exmc_pccard_init_struct->attribute_space_timing->setuptime = 0xFCU;
  402. exmc_pccard_init_struct->attribute_space_timing->waittime = 0xFCU;
  403. exmc_pccard_init_struct->attribute_space_timing->holdtime = 0xFCU;
  404. exmc_pccard_init_struct->attribute_space_timing->databus_hiztime = 0xFCU;
  405. exmc_pccard_init_struct->io_space_timing->setuptime = 0xFCU;
  406. exmc_pccard_init_struct->io_space_timing->waittime = 0xFCU;
  407. exmc_pccard_init_struct->io_space_timing->holdtime = 0xFCU;
  408. exmc_pccard_init_struct->io_space_timing->databus_hiztime = 0xFCU;
  409. }
  410. /*!
  411. \brief initialize EXMC PC card bank
  412. \param[in] exmc_pccard_parameter_struct: configure the EXMC NAND parameter
  413. atr_latency: EXMC_ALE_RE_DELAY_x_HCLK,x=1..16
  414. ctr_latency: EXMC_CLE_RE_DELAY_x_HCLK,x=1..16
  415. wait_feature: ENABLE or DISABLE
  416. common_space_timing: struct exmc_nand_pccard_timing_parameter_struct set the time
  417. databus_hiztime: 0x01U~0xFFU
  418. holdtime: 0x01U~0xFEU
  419. waittime: 0x02U~0xFFU
  420. setuptime: 0x01U~0xFFU
  421. attribute_space_timing: struct exmc_nand_pccard_timing_parameter_struct set the time
  422. databus_hiztime: 0x00U~0xFEU
  423. holdtime: 0x01U~0xFEU
  424. waittime: 0x02U~0xFFU
  425. setuptime: 0x01U~0xFFU
  426. io_space_timing: exmc_nand_pccard_timing_parameter_struct set the time
  427. databus_hiztime: 0x00U~0xFFU
  428. holdtime: 0x01U~0xFFU
  429. waittime: 0x02U~0x100U
  430. setuptime: 0x01U~0x100U
  431. \param[out] none
  432. \retval none
  433. */
  434. void exmc_pccard_init(exmc_pccard_parameter_struct* exmc_pccard_init_struct)
  435. {
  436. /* configure the EXMC bank3 PC card control register */
  437. EXMC_NPCTL3 = (uint32_t)(exmc_pccard_init_struct->wait_feature << NPCTL_NDWTEN_OFFSET) |
  438. EXMC_NAND_DATABUS_WIDTH_16B |
  439. exmc_pccard_init_struct->ctr_latency |
  440. exmc_pccard_init_struct->atr_latency ;
  441. /* configure the EXMC bank3 PC card common space timing configuration register */
  442. EXMC_NPCTCFG3 = (uint32_t)((exmc_pccard_init_struct->common_space_timing->setuptime - 1U) & EXMC_NPCTCFG_COMSET ) |
  443. (((exmc_pccard_init_struct->common_space_timing->waittime - 1U) << NPCTCFG_COMWAIT_OFFSET) & EXMC_NPCTCFG_COMWAIT ) |
  444. ((exmc_pccard_init_struct->common_space_timing->holdtime << NPCTCFG_COMHLD_OFFSET) & EXMC_NPCTCFG_COMHLD ) |
  445. (((exmc_pccard_init_struct->common_space_timing->databus_hiztime - 1U) << NPCTCFG_COMHIZ_OFFSET) & EXMC_NPCTCFG_COMHIZ );
  446. /* configure the EXMC bank3 PC card attribute space timing configuration register */
  447. EXMC_NPATCFG3 = (uint32_t)((exmc_pccard_init_struct->attribute_space_timing->setuptime - 1U) & EXMC_NPATCFG_ATTSET ) |
  448. (((exmc_pccard_init_struct->attribute_space_timing->waittime - 1U) << NPATCFG_ATTWAIT_OFFSET) & EXMC_NPATCFG_ATTWAIT ) |
  449. ((exmc_pccard_init_struct->attribute_space_timing->holdtime << NPATCFG_ATTHLD_OFFSET) & EXMC_NPATCFG_ATTHLD ) |
  450. ((exmc_pccard_init_struct->attribute_space_timing->databus_hiztime << NPATCFG_ATTHIZ_OFFSET) & EXMC_NPATCFG_ATTHIZ);
  451. /* configure the EXMC bank3 PC card io space timing configuration register */
  452. EXMC_PIOTCFG3 = (uint32_t)((exmc_pccard_init_struct->io_space_timing->setuptime - 1U) & EXMC_PIOTCFG3_IOSET ) |
  453. (((exmc_pccard_init_struct->io_space_timing->waittime - 1U) << PIOTCFG_IOWAIT_OFFSET) & EXMC_PIOTCFG3_IOWAIT ) |
  454. ((exmc_pccard_init_struct->io_space_timing->holdtime << PIOTCFG_IOHLD_OFFSET) & EXMC_PIOTCFG3_IOHLD ) |
  455. ((exmc_pccard_init_struct->io_space_timing->databus_hiztime << PIOTCFG_IOHIZ_OFFSET) & EXMC_PIOTCFG3_IOHIZ );
  456. }
  457. /*!
  458. \brief enable PC Card Bank
  459. \param[in] none
  460. \param[out] none
  461. \retval none
  462. */
  463. void exmc_pccard_enable(void)
  464. {
  465. EXMC_NPCTL3 |= EXMC_NPCTL_NDBKEN;
  466. }
  467. /*!
  468. \brief disable PC Card Bank
  469. \param[in] none
  470. \param[out] none
  471. \retval none
  472. */
  473. void exmc_pccard_disable(void)
  474. {
  475. EXMC_NPCTL3 &= ~EXMC_NPCTL_NDBKEN;
  476. }
  477. /*!
  478. \brief deinitialize EXMC SDRAM device
  479. \param[in] exmc_sdram_device: select the SRAM device
  480. only one parameter can be selected which is shown as below:
  481. \arg EXMC_SDRAM_DEVICEx(x=0, 1)
  482. \param[in] none
  483. \param[out] none
  484. \retval none
  485. */
  486. void exmc_sdram_deinit(uint32_t exmc_sdram_device)
  487. {
  488. /* reset SDRAM registers */
  489. EXMC_SDCTL(exmc_sdram_device) = SDRAM_DEVICE_SDCTL_RESET;
  490. EXMC_SDTCFG(exmc_sdram_device) = SDRAM_DEVICE_SDTCFG_RESET;
  491. EXMC_SDCMD = SDRAM_DEVICE_SDCMD_RESET;
  492. EXMC_SDARI = SDRAM_DEVICE_SDARI_RESET;
  493. EXMC_SDRSCTL = SDRAM_DEVICE_SDRSCTL_RESET;
  494. }
  495. /*!
  496. \brief initialize exmc_sdram_parameter_struct with the default values
  497. \param[in] none
  498. \param[out] the initialized struct exmc_pccard_parameter_struct pointer
  499. \retval none
  500. */
  501. void exmc_sdram_struct_para_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
  502. {
  503. /* configure the structure with default values */
  504. exmc_sdram_init_struct->sdram_device = EXMC_SDRAM_DEVICE0;
  505. exmc_sdram_init_struct->column_address_width = EXMC_SDRAM_COW_ADDRESS_8;
  506. exmc_sdram_init_struct->row_address_width = EXMC_SDRAM_ROW_ADDRESS_11;
  507. exmc_sdram_init_struct->data_width = EXMC_SDRAM_DATABUS_WIDTH_16B;
  508. exmc_sdram_init_struct->internal_bank_number = EXMC_SDRAM_4_INTER_BANK;
  509. exmc_sdram_init_struct->cas_latency = EXMC_CAS_LATENCY_1_SDCLK;
  510. exmc_sdram_init_struct->write_protection = ENABLE;
  511. exmc_sdram_init_struct->sdclock_config = EXMC_SDCLK_DISABLE;
  512. exmc_sdram_init_struct->brust_read_switch = DISABLE;
  513. exmc_sdram_init_struct->pipeline_read_delay = EXMC_PIPELINE_DELAY_0_HCLK;
  514. exmc_sdram_init_struct->timing->load_mode_register_delay = 16U;
  515. exmc_sdram_init_struct->timing->exit_selfrefresh_delay = 16U;
  516. exmc_sdram_init_struct->timing->row_address_select_delay = 16U;
  517. exmc_sdram_init_struct->timing->auto_refresh_delay = 16U;
  518. exmc_sdram_init_struct->timing->write_recovery_delay = 16U;
  519. exmc_sdram_init_struct->timing->row_precharge_delay = 16U;
  520. exmc_sdram_init_struct->timing->row_to_column_delay = 16U;
  521. }
  522. /*!
  523. \brief initialize EXMC SDRAM device
  524. \param[in] exmc_sdram_parameter_struct: configure the EXMC SDRAM parameter
  525. sdram_device: EXMC_SDRAM_DEVICE0,EXMC_SDRAM_DEVICE1
  526. pipeline_read_delay: EXMC_PIPELINE_DELAY_x_HCLK,x=0..2
  527. brust_read_switch: ENABLE or DISABLE
  528. sdclock_config: EXMC_SDCLK_DISABLE,EXMC_SDCLK_PERIODS_2_HCLK,EXMC_SDCLK_PERIODS_3_HCLK
  529. write_protection: ENABLE or DISABLE
  530. cas_latency: EXMC_CAS_LATENCY_x_SDCLK,x=1..3
  531. internal_bank_number: EXMC_SDRAM_2_INTER_BANK,EXMC_SDRAM_4_INTER_BANK
  532. data_width: EXMC_SDRAM_DATABUS_WIDTH_8B,EXMC_SDRAM_DATABUS_WIDTH_16B,EXMC_SDRAM_DATABUS_WIDTH_32B
  533. row_address_width: EXMC_SDRAM_ROW_ADDRESS_x,x=11..13
  534. column_address_width: EXMC_SDRAM_COW_ADDRESS_x,x=8..11
  535. timing: exmc_sdram_timing_parameter_struct set the time
  536. row_to_column_delay: 1U~16U
  537. row_precharge_delay: 1U~16U
  538. write_recovery_delay: 1U~16U
  539. auto_refresh_delay: 1U~16U
  540. row_address_select_delay: 1U~16U
  541. exit_selfrefresh_delay: 1U~16U
  542. load_mode_register_delay: 1U~16U
  543. \param[out] none
  544. \retval none
  545. */
  546. void exmc_sdram_init(exmc_sdram_parameter_struct* exmc_sdram_init_struct)
  547. {
  548. uint32_t sdctl0, sdctl1, sdtcfg0, sdtcfg1;
  549. /* configuration EXMC_SDCTL0 or EXMC_SDCTL1 */
  550. if(EXMC_SDRAM_DEVICE0 == exmc_sdram_init_struct->sdram_device){
  551. /* configuration EXMC_SDCTL0 */
  552. EXMC_SDCTL(EXMC_SDRAM_DEVICE0) = (uint32_t)exmc_sdram_init_struct->column_address_width |
  553. exmc_sdram_init_struct->row_address_width |
  554. exmc_sdram_init_struct->data_width |
  555. exmc_sdram_init_struct->internal_bank_number |
  556. exmc_sdram_init_struct->cas_latency |
  557. (exmc_sdram_init_struct->write_protection << SDCTL_WPEN_OFFSET)|
  558. exmc_sdram_init_struct->sdclock_config |
  559. (exmc_sdram_init_struct->brust_read_switch << SDCTL_BRSTRD_OFFSET)|
  560. exmc_sdram_init_struct->pipeline_read_delay;
  561. /* configuration EXMC_SDTCFG0 */
  562. EXMC_SDTCFG(EXMC_SDRAM_DEVICE0) = (uint32_t)((exmc_sdram_init_struct->timing->load_mode_register_delay)-1U) |
  563. (((exmc_sdram_init_struct->timing->exit_selfrefresh_delay)-1U) << SDTCFG_XSRD_OFFSET) |
  564. (((exmc_sdram_init_struct->timing->row_address_select_delay)-1U) << SDTCFG_RASD_OFFSET) |
  565. (((exmc_sdram_init_struct->timing->auto_refresh_delay)-1U) << SDTCFG_ARFD_OFFSET) |
  566. (((exmc_sdram_init_struct->timing->write_recovery_delay)-1U) << SDTCFG_WRD_OFFSET) |
  567. (((exmc_sdram_init_struct->timing->row_precharge_delay)-1U) << SDTCFG_RPD_OFFSET) |
  568. (((exmc_sdram_init_struct->timing->row_to_column_delay)-1U) << SDTCFG_RCD_OFFSET);
  569. }else{
  570. /* configuration EXMC_SDCTL0 and EXMC_SDCTL1 */
  571. /* some bits in the EXMC_SDCTL1 register are reserved */
  572. sdctl0 = EXMC_SDCTL(EXMC_SDRAM_DEVICE0) & (~( EXMC_SDCTL_PIPED | EXMC_SDCTL_BRSTRD | EXMC_SDCTL_SDCLK ));
  573. sdctl0 |= (uint32_t)exmc_sdram_init_struct->sdclock_config |
  574. exmc_sdram_init_struct->brust_read_switch |
  575. exmc_sdram_init_struct->pipeline_read_delay;
  576. sdctl1 = (uint32_t)exmc_sdram_init_struct->column_address_width |
  577. exmc_sdram_init_struct->row_address_width |
  578. exmc_sdram_init_struct->data_width |
  579. exmc_sdram_init_struct->internal_bank_number |
  580. exmc_sdram_init_struct->cas_latency |
  581. exmc_sdram_init_struct->write_protection ;
  582. EXMC_SDCTL(EXMC_SDRAM_DEVICE0) = sdctl0;
  583. EXMC_SDCTL(EXMC_SDRAM_DEVICE1) = sdctl1;
  584. /* configuration EXMC_SDTCFG0 and EXMC_SDTCFG1 */
  585. /* some bits in the EXMC_SDTCFG1 register are reserved */
  586. sdtcfg0 = EXMC_SDTCFG(EXMC_SDRAM_DEVICE0) & (~(EXMC_SDTCFG_RPD | EXMC_SDTCFG_WRD | EXMC_SDTCFG_ARFD));
  587. sdtcfg0 |= (uint32_t)(((exmc_sdram_init_struct->timing->auto_refresh_delay)-1U) << SDTCFG_ARFD_OFFSET) |
  588. (((exmc_sdram_init_struct->timing->row_precharge_delay)-1U) << SDTCFG_RPD_OFFSET) |
  589. (((exmc_sdram_init_struct->timing->write_recovery_delay)-1U) << SDTCFG_WRD_OFFSET);
  590. sdtcfg1 = (uint32_t)((exmc_sdram_init_struct->timing->load_mode_register_delay)-1U) |
  591. (((exmc_sdram_init_struct->timing->exit_selfrefresh_delay)-1U) << SDTCFG_XSRD_OFFSET) |
  592. (((exmc_sdram_init_struct->timing->row_address_select_delay)-1U) << SDTCFG_RASD_OFFSET) |
  593. (((exmc_sdram_init_struct->timing->row_to_column_delay)-1U) << SDTCFG_RCD_OFFSET);
  594. EXMC_SDTCFG(EXMC_SDRAM_DEVICE0) = sdtcfg0;
  595. EXMC_SDTCFG(EXMC_SDRAM_DEVICE1) = sdtcfg1;
  596. }
  597. }
  598. /*!
  599. \brief deinitialize exmc SQPIPSRAM
  600. \param[in] none
  601. \param[out] none
  602. \retval none
  603. */
  604. void exmc_sqpipsram_deinit(void)
  605. {
  606. /* reset the registers */
  607. EXMC_SINIT = BANK0_SQPI_SINIT_RESET;
  608. EXMC_SRCMD = BANK0_SQPI_SRCMD_RESET;
  609. EXMC_SWCMD = BANK0_SQPI_SWCMD_RESET;
  610. EXMC_SIDL = BANK0_SQPI_SIDL_RESET;
  611. EXMC_SIDH = BANK0_SQPI_SIDH_RESET;
  612. }
  613. /*!
  614. \brief initialize exmc_sqpipsram_parameter_struct with the default values
  615. \param[in] the struct exmc_sqpipsram_parameter_struct pointer
  616. \param[out] none
  617. \retval none
  618. */
  619. void exmc_sqpipsram_struct_para_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct)
  620. {
  621. /* configure the structure with default values */
  622. exmc_sqpipsram_init_struct->sample_polarity = EXMC_SQPIPSRAM_SAMPLE_RISING_EDGE;
  623. exmc_sqpipsram_init_struct->id_length = EXMC_SQPIPSRAM_ID_LENGTH_64B;
  624. exmc_sqpipsram_init_struct->address_bits = EXMC_SQPIPSRAM_ADDR_LENGTH_24B;
  625. exmc_sqpipsram_init_struct->command_bits = EXMC_SQPIPSRAM_COMMAND_LENGTH_8B;
  626. }
  627. /*!
  628. \brief initialize EXMC SQPIPSRAM
  629. \param[in] exmc_sqpipsram_parameter_struct: configure the EXMC SQPIPSRAM parameter
  630. sample_polarity: EXMC_SQPIPSRAM_SAMPLE_RISING_EDGE,EXMC_SQPIPSRAM_SAMPLE_FALLING_EDGE
  631. id_length: EXMC_SQPIPSRAM_ID_LENGTH_xB,x=8,16,32,64
  632. address_bits: EXMC_SQPIPSRAM_ADDR_LENGTH_xB,x=1..26
  633. command_bits: EXMC_SQPIPSRAM_COMMAND_LENGTH_xB,x=4,8,16
  634. \param[out] none
  635. \retval none
  636. */
  637. void exmc_sqpipsram_init(exmc_sqpipsram_parameter_struct* exmc_sqpipsram_init_struct)
  638. {
  639. /* initialize SQPI controller */
  640. EXMC_SINIT = (uint32_t)exmc_sqpipsram_init_struct->sample_polarity |
  641. exmc_sqpipsram_init_struct->id_length |
  642. exmc_sqpipsram_init_struct->address_bits |
  643. exmc_sqpipsram_init_struct->command_bits;
  644. }
  645. /*!
  646. \brief configure consecutive clock
  647. \param[in] clock_mode: specifie when the clock is generated
  648. only one parameter can be selected which is shown as below:
  649. \arg EXMC_CLOCK_SYN_MODE: the clock is generated only during synchronous access
  650. \arg EXMC_CLOCK_UNCONDITIONALLY: the clock is generated unconditionally
  651. \param[out] none
  652. \retval none
  653. */
  654. void exmc_norsram_consecutive_clock_config(uint32_t clock_mode)
  655. {
  656. if (EXMC_CLOCK_UNCONDITIONALLY == clock_mode){
  657. EXMC_SNCTL(EXMC_BANK0_NORSRAM_REGION0) |= EXMC_CLOCK_UNCONDITIONALLY;
  658. }else{
  659. EXMC_SNCTL(EXMC_BANK0_NORSRAM_REGION0) &= ~EXMC_CLOCK_UNCONDITIONALLY;
  660. }
  661. }
  662. /*!
  663. \brief configure CRAM page size
  664. \param[in] exmc_norsram_region: select the region of bank0
  665. only one parameter can be selected which is shown as below:
  666. \arg EXMC_BANK0_NORSRAM_REGIONx(x=0..3)
  667. \param[in] page_size: CRAM page size
  668. only one parameter can be selected which is shown as below:
  669. \arg EXMC_CRAM_AUTO_SPLIT: the clock is generated only during synchronous access
  670. \arg EXMC_CRAM_PAGE_SIZE_128_BYTES: page size is 128 bytes
  671. \arg EXMC_CRAM_PAGE_SIZE_256_BYTES: page size is 256 bytes
  672. \arg EXMC_CRAM_PAGE_SIZE_512_BYTES: page size is 512 bytes
  673. \arg EXMC_CRAM_PAGE_SIZE_1024_BYTES: page size is 1024 bytes
  674. \param[out] none
  675. \retval none
  676. */
  677. void exmc_norsram_page_size_config(uint32_t exmc_norsram_region, uint32_t page_size)
  678. {
  679. /* reset the bits */
  680. EXMC_SNCTL(exmc_norsram_region) &= ~EXMC_SNCTL_CPS;
  681. /* set the CPS bits */
  682. EXMC_SNCTL(exmc_norsram_region) |= page_size;
  683. }
  684. /*!
  685. \brief enable or disable the EXMC NAND ECC function
  686. \param[in] exmc_nand_bank: specifie the NAND bank
  687. only one parameter can be selected which is shown as below:
  688. \arg EXMC_BANKx_NAND(x=1,2)
  689. \param[in] newvalue: ENABLE or DISABLE
  690. \param[out] none
  691. \retval none
  692. */
  693. void exmc_nand_ecc_config(uint32_t exmc_nand_bank, ControlStatus newvalue)
  694. {
  695. if (ENABLE == newvalue){
  696. /* enable the selected NAND bank ECC function */
  697. EXMC_NPCTL(exmc_nand_bank) |= EXMC_NPCTL_ECCEN;
  698. }else{
  699. /* disable the selected NAND bank ECC function */
  700. EXMC_NPCTL(exmc_nand_bank) &= ~EXMC_NPCTL_ECCEN;
  701. }
  702. }
  703. /*!
  704. \brief get the EXMC ECC value
  705. \param[in] exmc_nand_bank: specifie the NAND bank
  706. only one parameter can be selected which is shown as below:
  707. \arg EXMC_BANKx_NAND(x=1,2)
  708. \param[out] none
  709. \retval the error correction code(ECC) value
  710. */
  711. uint32_t exmc_ecc_get(uint32_t exmc_nand_bank)
  712. {
  713. return(EXMC_NECC(exmc_nand_bank));
  714. }
  715. /*!
  716. \brief enable or disable read sample
  717. \param[in] newvalue: ENABLE or DISABLE
  718. \param[out] none
  719. \retval none
  720. */
  721. void exmc_sdram_readsample_enable(ControlStatus newvalue)
  722. {
  723. if (ENABLE == newvalue){
  724. EXMC_SDRSCTL |= EXMC_SDRSCTL_RSEN;
  725. }else{
  726. EXMC_SDRSCTL &= (uint32_t)(~EXMC_SDRSCTL_RSEN);
  727. }
  728. }
  729. /*!
  730. \brief configure the delayed sample clock of read data
  731. \param[in] delay_cell: SDRAM the delayed sample clock of read data
  732. only one parameter can be selected which is shown as below:
  733. \arg EXMC_SDRAM_x_DELAY_CELL(x=0..15)
  734. \param[in] extra_hclk: sample cycle of read data
  735. only one parameter can be selected which is shown as below:
  736. \arg EXMC_SDRAM_READSAMPLE_x_EXTRAHCLK(x=0,1)
  737. \param[out] none
  738. \retval none
  739. */
  740. void exmc_sdram_readsample_config(uint32_t delay_cell, uint32_t extra_hclk)
  741. {
  742. uint32_t sdrsctl = 0U;
  743. /* reset the bits */
  744. sdrsctl = EXMC_SDRSCTL & (~(EXMC_SDRSCTL_SDSC | EXMC_SDRSCTL_SSCR));
  745. /* set the bits */
  746. sdrsctl |= (uint32_t)(delay_cell & EXMC_SDRSCTL_SDSC) |
  747. ((extra_hclk << SDRSCTL_SSCR_OFFSET) & EXMC_SDRSCTL_SSCR);
  748. EXMC_SDRSCTL = sdrsctl;
  749. }
  750. /*!
  751. \brief configure the SDRAM memory command
  752. \param[in] exmc_sdram_command_init_struct: initialize EXMC SDRAM command
  753. mode_register_content:
  754. auto_refresh_number: EXMC_SDRAM_AUTO_REFLESH_x_SDCLK, x=1..15
  755. bank_select: EXMC_SDRAM_DEVICE0_SELECT, EXMC_SDRAM_DEVICE1_SELECT, EXMC_SDRAM_DEVICE0_1_SELECT
  756. command: EXMC_SDRAM_NORMAL_OPERATION, EXMC_SDRAM_CLOCK_ENABLE, EXMC_SDRAM_PRECHARGE_ALL,
  757. EXMC_SDRAM_AUTO_REFRESH, EXMC_SDRAM_LOAD_MODE_REGISTER, EXMC_SDRAM_SELF_REFRESH,
  758. EXMC_SDRAM_POWERDOWN_ENTRY
  759. \param[out] none
  760. \retval none
  761. */
  762. void exmc_sdram_command_config(exmc_sdram_command_parameter_struct* exmc_sdram_command_init_struct)
  763. {
  764. /* configure command register */
  765. EXMC_SDCMD = (uint32_t)((exmc_sdram_command_init_struct->command) |
  766. (exmc_sdram_command_init_struct->bank_select) |
  767. ((exmc_sdram_command_init_struct->auto_refresh_number)) |
  768. ((exmc_sdram_command_init_struct->mode_register_content)<<SDCMD_MRC_OFFSET) );
  769. }
  770. /*!
  771. \brief set auto-refresh interval
  772. \param[in] exmc_count: the number SDRAM clock cycles unit between two successive auto-refresh commands, 0x0000~0x1FFF
  773. \param[out] none
  774. \retval none
  775. */
  776. void exmc_sdram_refresh_count_set(uint32_t exmc_count)
  777. {
  778. uint32_t sdari;
  779. sdari = EXMC_SDARI & (~EXMC_SDARI_ARINTV);
  780. EXMC_SDARI = sdari | (uint32_t)((exmc_count << SDARI_ARINTV_OFFSET) & EXMC_SDARI_ARINTV);
  781. }
  782. /*!
  783. \brief set the number of successive auto-refresh command
  784. \param[in] exmc_number: the number of successive Auto-refresh cycles will be send, 1~15
  785. \param[out] none
  786. \retval none
  787. */
  788. void exmc_sdram_autorefresh_number_set(uint32_t exmc_number)
  789. {
  790. uint32_t sdcmd;
  791. sdcmd = EXMC_SDCMD & (~EXMC_SDCMD_NARF);
  792. EXMC_SDCMD = sdcmd | (uint32_t)((exmc_number << SDCMD_NARF_OFFSET) & EXMC_SDCMD_NARF) ;
  793. }
  794. /*!
  795. \brief config the write protection function
  796. \param[in] exmc_sdram_device: specifie the SDRAM device
  797. only one parameter can be selected which is shown as below:
  798. \arg EXMC_SDRAM_DEVICEx(x=0,1)
  799. \param[in] newvalue: ENABLE or DISABLE
  800. \param[out] none
  801. \retval none
  802. */
  803. void exmc_sdram_write_protection_config(uint32_t exmc_sdram_device, ControlStatus newvalue)
  804. {
  805. if (ENABLE == newvalue){
  806. EXMC_SDCTL(exmc_sdram_device) |= (uint32_t)EXMC_SDCTL_WPEN;
  807. }else{
  808. EXMC_SDCTL(exmc_sdram_device) &= ~((uint32_t)EXMC_SDCTL_WPEN);
  809. }
  810. }
  811. /*!
  812. \brief get the status of SDRAM device0 or device1
  813. \param[in] exmc_sdram_device: specifie the SDRAM device
  814. only one parameter can be selected which is shown as below:
  815. \arg EXMC_SDRAM_DEVICEx(x=0,1)
  816. \param[out] none
  817. \retval the status of SDRAM device
  818. */
  819. uint32_t exmc_sdram_bankstatus_get(uint32_t exmc_sdram_device)
  820. {
  821. uint32_t sdstat = 0U;
  822. if(EXMC_SDRAM_DEVICE0 == exmc_sdram_device){
  823. sdstat = ((uint32_t)(EXMC_SDSTAT & EXMC_SDSDAT_STA0) >> SDSTAT_STA0_OFFSET);
  824. }else{
  825. sdstat = ((uint32_t)(EXMC_SDSTAT & EXMC_SDSDAT_STA1) >> SDSTAT_STA1_OFFSET);
  826. }
  827. return sdstat;
  828. }
  829. /*!
  830. \brief set the read command
  831. \param[in] read_command_mode: configure SPI PSRAM read command mode
  832. only one parameter can be selected which is shown as below:
  833. \arg EXMC_SQPIPSRAM_READ_MODE_DISABLE: not SPI mode
  834. \arg EXMC_SQPIPSRAM_READ_MODE_SPI: SPI mode
  835. \arg EXMC_SQPIPSRAM_READ_MODE_SQPI: SQPI mode
  836. \arg EXMC_SQPIPSRAM_READ_MODE_QPI: QPI mode
  837. \param[in] read_wait_cycle: wait cycle number after address phase,0..15
  838. \param[in] read_command_code: read command for AHB read transfer
  839. \param[out] none
  840. \retval none
  841. */
  842. void exmc_sqpipsram_read_command_set(uint32_t read_command_mode,uint32_t read_wait_cycle, uint32_t read_command_code)
  843. {
  844. uint32_t srcmd;
  845. srcmd = (uint32_t) read_command_mode |
  846. ((read_wait_cycle << SRCMD_RWAITCYCLE_OFFSET) & EXMC_SRCMD_RWAITCYCLE) |
  847. ((read_command_code & EXMC_SRCMD_RCMD));
  848. EXMC_SRCMD = srcmd;
  849. }
  850. /*!
  851. \brief set the write command
  852. \param[in] write_command_mode: configure SPI PSRAM write command mode
  853. only one parameter can be selected which is shown as below:
  854. \arg EXMC_SQPIPSRAM_WRITE_MODE_DISABLE: not SPI mode
  855. \arg EXMC_SQPIPSRAM_WRITE_MODE_SPI: SPI mode
  856. \arg EXMC_SQPIPSRAM_WRITE_MODE_SQPI: SQPI mode
  857. \arg EXMC_SQPIPSRAM_WRITE_MODE_QPI: QPI mode
  858. \param[in] write_wait_cycle: wait cycle number after address phase,0..15
  859. \param[in] write_command_code: read command for AHB read transfer
  860. \param[out] none
  861. \retval none
  862. */
  863. void exmc_sqpipsram_write_command_set(uint32_t write_command_mode,uint32_t write_wait_cycle, uint32_t write_command_code)
  864. {
  865. uint32_t swcmd;
  866. swcmd = (uint32_t) write_command_mode |
  867. ((write_wait_cycle << SWCMD_WWAITCYCLE_OFFSET) & EXMC_SWCMD_WWAITCYCLE) |
  868. ((write_command_code & EXMC_SWCMD_WCMD));
  869. EXMC_SWCMD = swcmd;
  870. }
  871. /*!
  872. \brief send SPI read ID command
  873. \param[in] none
  874. \param[out] none
  875. \retval none
  876. */
  877. void exmc_sqpipsram_read_id_command_send(void)
  878. {
  879. EXMC_SRCMD |= EXMC_SRCMD_RDID;
  880. }
  881. /*!
  882. \brief send SPI special command which does not have address and data phase
  883. \param[in] none
  884. \param[out] none
  885. \retval none
  886. */
  887. void exmc_sqpipsram_write_cmd_send(void)
  888. {
  889. EXMC_SWCMD |= EXMC_SWCMD_SC;
  890. }
  891. /*!
  892. \brief get the EXMC SPI ID low data
  893. \param[in] none
  894. \param[out] none
  895. \retval the ID low data
  896. */
  897. uint32_t exmc_sqpipsram_low_id_get(void)
  898. {
  899. return (EXMC_SIDL);
  900. }
  901. /*!
  902. \brief get the EXMC SPI ID high data
  903. \param[in] none
  904. \param[out] none
  905. \retval the ID high data
  906. */
  907. uint32_t exmc_sqpipsram_high_id_get(void)
  908. {
  909. return (EXMC_SIDH);
  910. }
  911. /*!
  912. \brief get the bit value of EXMC send write command bit or read ID command
  913. \param[in] send_command_flag: the send command flag
  914. only one parameter can be selected which is shown as below:
  915. \arg EXMC_SEND_COMMAND_FLAG_RDID: EXMC_SRCMD_RDID flag bit
  916. \arg EXMC_SEND_COMMAND_FLAG_SC: EXMC_SWCMD_SC flag bit
  917. \param[out] none
  918. \retval the new value of send command flag
  919. */
  920. FlagStatus exmc_sqpipsram_send_command_state_get(uint32_t send_command_flag)
  921. {
  922. uint32_t flag = 0x00000000U;
  923. if(EXMC_SEND_COMMAND_FLAG_RDID == send_command_flag){
  924. flag = EXMC_SRCMD;
  925. }else if(EXMC_SEND_COMMAND_FLAG_SC == send_command_flag){
  926. flag = EXMC_SWCMD;
  927. }else{
  928. }
  929. if (flag & send_command_flag){
  930. /* flag is set */
  931. return SET;
  932. }else{
  933. /* flag is reset */
  934. return RESET;
  935. }
  936. }
  937. /*!
  938. \brief enable EXMC interrupt
  939. \param[in] exmc_bank: specifies the NAND bank,PC card bank or SDRAM device
  940. only one parameter can be selected which is shown as below:
  941. \arg EXMC_BANK1_NAND: the NAND bank1
  942. \arg EXMC_BANK2_NAND: the NAND bank2
  943. \arg EXMC_BANK3_PCCARD: the PC card bank
  944. \arg EXMC_SDRAM_DEVICE0: the SDRAM device0
  945. \arg EXMC_SDRAM_DEVICE1: the SDRAM device1
  946. \param[in] interrupt: specify get which interrupt flag
  947. only one parameter can be selected which is shown as below:
  948. \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: rising edge interrupt and flag
  949. \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: high-level interrupt and flag
  950. \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: falling edge interrupt and flag
  951. \arg EXMC_SDRAM_INT_FLAG_REFRESH: refresh error interrupt and flag
  952. \param[out] none
  953. \retval none
  954. */
  955. void exmc_interrupt_enable(uint32_t exmc_bank, uint32_t interrupt)
  956. {
  957. if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
  958. /* NAND bank1,bank2 or PC card bank3 */
  959. EXMC_NPINTEN(exmc_bank) |= interrupt;
  960. }else{
  961. /* SDRAM device0 or device1 */
  962. EXMC_SDARI |= EXMC_SDARI_REIE;
  963. }
  964. }
  965. /*!
  966. \brief disable EXMC interrupt
  967. \param[in] exmc_bank: specifies the NAND bank , PC card bank or SDRAM device
  968. only one parameter can be selected which is shown as below:
  969. \arg EXMC_BANK1_NAND: the NAND bank1
  970. \arg EXMC_BANK2_NAND: the NAND bank2
  971. \arg EXMC_BANK3_PCCARD: the PC card bank
  972. \arg EXMC_SDRAM_DEVICE0: the SDRAM device0
  973. \arg EXMC_SDRAM_DEVICE1: the SDRAM device1
  974. \param[in] interrupt: specify get which interrupt flag
  975. only one parameter can be selected which is shown as below:
  976. \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: rising edge interrupt and flag
  977. \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: high-level interrupt and flag
  978. \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: falling edge interrupt and flag
  979. \arg EXMC_SDRAM_INT_FLAG_REFRESH: refresh error interrupt and flag
  980. \param[out] none
  981. \retval none
  982. */
  983. void exmc_interrupt_disable(uint32_t exmc_bank, uint32_t interrupt)
  984. {
  985. if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
  986. /* NAND bank1,bank2 or PC card bank3 */
  987. EXMC_NPINTEN(exmc_bank) &= ~interrupt;
  988. }else{
  989. /* SDRAM device0 or device1 */
  990. EXMC_SDARI &= ~EXMC_SDARI_REIE;
  991. }
  992. }
  993. /*!
  994. \brief get EXMC flag status
  995. \param[in] exmc_bank: specifies the NAND bank , PC card bank or SDRAM device
  996. only one parameter can be selected which is shown as below:
  997. \arg EXMC_BANK1_NAND: the NAND bank1
  998. \arg EXMC_BANK2_NAND: the NAND bank2
  999. \arg EXMC_BANK3_PCCARD: the PC Card bank
  1000. \arg EXMC_SDRAM_DEVICE0: the SDRAM device0
  1001. \arg EXMC_SDRAM_DEVICE1: the SDRAM device1
  1002. \param[in] flag: EXMC status and flag
  1003. only one parameter can be selected which is shown as below:
  1004. \arg EXMC_NAND_PCCARD_FLAG_RISE: interrupt rising edge status
  1005. \arg EXMC_NAND_PCCARD_FLAG_LEVEL: interrupt high-level status
  1006. \arg EXMC_NAND_PCCARD_FLAG_FALL: interrupt falling edge status
  1007. \arg EXMC_NAND_PCCARD_FLAG_FIFOE: FIFO empty flag
  1008. \arg EXMC_SDRAM_FLAG_REFRESH: refresh error interrupt flag
  1009. \arg EXMC_SDRAM_FLAG_NREADY: not ready status
  1010. \param[out] none
  1011. \retval FlagStatus: SET or RESET
  1012. */
  1013. FlagStatus exmc_flag_get(uint32_t exmc_bank,uint32_t flag)
  1014. {
  1015. uint32_t status = 0x00000000U;
  1016. if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
  1017. /* NAND bank1,bank2 or PC card bank3 */
  1018. status = EXMC_NPINTEN(exmc_bank);
  1019. }else{
  1020. /* SDRAM device0 or device1 */
  1021. status = EXMC_SDSTAT;
  1022. }
  1023. if ((status & flag) != (uint32_t)flag ){
  1024. /* flag is reset */
  1025. return RESET;
  1026. }else{
  1027. /* flag is set */
  1028. return SET;
  1029. }
  1030. }
  1031. /*!
  1032. \brief clear EXMC flag status
  1033. \param[in] exmc_bank: specifie the NAND bank , PCCARD bank or SDRAM device
  1034. only one parameter can be selected which is shown as below:
  1035. \arg EXMC_BANK1_NAND: the NAND bank1
  1036. \arg EXMC_BANK2_NAND: the NAND bank2
  1037. \arg EXMC_BANK3_PCCARD: the PC card bank
  1038. \arg EXMC_SDRAM_DEVICE0: the SDRAM device0
  1039. \arg EXMC_SDRAM_DEVICE1: the SDRAM device1
  1040. \param[in] flag: EXMC status and flag
  1041. only one parameter can be selected which is shown as below:
  1042. \arg EXMC_NAND_PCCARD_FLAG_RISE: interrupt rising edge status
  1043. \arg EXMC_NAND_PCCARD_FLAG_LEVEL: interrupt high-level status
  1044. \arg EXMC_NAND_PCCARD_FLAG_FALL: interrupt falling edge status
  1045. \arg EXMC_NAND_PCCARD_FLAG_FIFOE: FIFO empty flag
  1046. \arg EXMC_SDRAM_FLAG_REFRESH: refresh error interrupt flag
  1047. \arg EXMC_SDRAM_FLAG_NREADY: not ready status
  1048. \param[out] none
  1049. \retval none
  1050. */
  1051. void exmc_flag_clear(uint32_t exmc_bank, uint32_t flag)
  1052. {
  1053. if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
  1054. /* NAND bank1,bank2 or PC card bank3 */
  1055. EXMC_NPINTEN(exmc_bank) &= ~flag;
  1056. }else{
  1057. /* SDRAM device0 or device1 */
  1058. EXMC_SDSTAT &= ~flag;
  1059. }
  1060. }
  1061. /*!
  1062. \brief get EXMC interrupt flag
  1063. \param[in] exmc_bank: specifies the NAND bank , PC card bank or SDRAM device
  1064. only one parameter can be selected which is shown as below:
  1065. \arg EXMC_BANK1_NAND: the NAND bank1
  1066. \arg EXMC_BANK2_NAND: the NAND bank2
  1067. \arg EXMC_BANK3_PCCARD: the PC card bank
  1068. \arg EXMC_SDRAM_DEVICE0: the SDRAM device0
  1069. \arg EXMC_SDRAM_DEVICE1: the SDRAM device1
  1070. \param[in] interrupt: EXMC interrupt flag
  1071. only one parameter can be selected which is shown as below:
  1072. \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: rising edge interrupt and flag
  1073. \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: high-level interrupt and flag
  1074. \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: falling edge interrupt and flag
  1075. \arg EXMC_SDRAM_INT_FLAG_REFRESH: refresh error interrupt and flag
  1076. \param[out] none
  1077. \retval FlagStatus: SET or RESET
  1078. */
  1079. FlagStatus exmc_interrupt_flag_get(uint32_t exmc_bank, uint32_t interrupt)
  1080. {
  1081. uint32_t status = 0x00000000U,interrupt_enable = 0x00000000U,interrupt_state = 0x00000000U;
  1082. if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
  1083. /* NAND bank1,bank2 or PC card bank3 */
  1084. status = EXMC_NPINTEN(exmc_bank);
  1085. interrupt_state = (status & (interrupt >> INTEN_INTS_OFFSET));
  1086. }else{
  1087. /* SDRAM device0 or device1 */
  1088. status = EXMC_SDARI;
  1089. interrupt_state = (EXMC_SDSTAT & EXMC_SDSDAT_REIF);
  1090. }
  1091. interrupt_enable = (status & interrupt);
  1092. if ((interrupt_enable) && (interrupt_state)){
  1093. /* interrupt flag is set */
  1094. return SET;
  1095. }else{
  1096. /* interrupt flag is reset */
  1097. return RESET;
  1098. }
  1099. }
  1100. /*!
  1101. \brief clear EXMC interrupt flag
  1102. \param[in] exmc_bank: specifies the NAND bank , PC card bank or SDRAM device
  1103. only one parameter can be selected which is shown as below:
  1104. \arg EXMC_BANK1_NAND: the NAND bank1
  1105. \arg EXMC_BANK2_NAND: the NAND bank2
  1106. \arg EXMC_BANK3_PCCARD: the PC card bank
  1107. \arg EXMC_SDRAM_DEVICE0: the SDRAM device0
  1108. \arg EXMC_SDRAM_DEVICE1: the SDRAM device1
  1109. \param[in] interrupt: EXMC interrupt flag
  1110. only one parameter can be selected which is shown as below:
  1111. \arg EXMC_NAND_PCCARD_INT_FLAG_RISE: rising edge interrupt and flag
  1112. \arg EXMC_NAND_PCCARD_INT_FLAG_LEVEL: high-level interrupt and flag
  1113. \arg EXMC_NAND_PCCARD_INT_FLAG_FALL: falling edge interrupt and flag
  1114. \arg EXMC_SDRAM_INT_FLAG_REFRESH: refresh error interrupt and flag
  1115. \param[out] none
  1116. \retval none
  1117. */
  1118. void exmc_interrupt_flag_clear(uint32_t exmc_bank, uint32_t interrupt)
  1119. {
  1120. if((EXMC_BANK1_NAND == exmc_bank) || (EXMC_BANK2_NAND == exmc_bank) || (EXMC_BANK3_PCCARD == exmc_bank)){
  1121. /* NAND bank1,bank2 or PC card bank3 */
  1122. EXMC_NPINTEN(exmc_bank) &= ~(interrupt >> INTEN_INTS_OFFSET);
  1123. }else{
  1124. /* SDRAM device0 or device1 */
  1125. EXMC_SDARI |= EXMC_SDARI_REC;
  1126. }
  1127. }