1
0

lpc_emc.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. /**********************************************************************
  2. * $Id$ lpc_emc.h 2011-06-02
  3. *//**
  4. * @file lpc_emc.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support for EMC firmware library on LPC
  7. * @version 1.0
  8. * @date 02. June. 2011
  9. * @author NXP MCU SW Application Team
  10. *
  11. * Copyright(C) 2011, NXP Semiconductor
  12. * All rights reserved.
  13. *
  14. ***********************************************************************
  15. * Software that is described herein is for illustrative purposes only
  16. * which provides customers with programming information regarding the
  17. * products. This software is supplied "AS IS" without any warranties.
  18. * NXP Semiconductors assumes no responsibility or liability for the
  19. * use of the software, conveys no license or title under any patent,
  20. * copyright, or mask work right to the product. NXP Semiconductors
  21. * reserves the right to make changes in the software without
  22. * notification. NXP Semiconductors also make no representation or
  23. * warranty that such application will be suitable for the specified
  24. * use without further testing or modification.
  25. * Permission to use, copy, modify, and distribute this software and its
  26. * documentation is hereby granted, under NXP Semiconductors'
  27. * relevant copyright in the software, without fee, provided that it
  28. * is used in conjunction with NXP Semiconductors microcontrollers. This
  29. * copyright, permission, and disclaimer notice must appear in all copies of
  30. * this code.
  31. **********************************************************************/
  32. /* Peripheral group ----------------------------------------------------------- */
  33. /** @defgroup EMC EMC (External Memory Controller)
  34. * @ingroup LPC_CMSIS_FwLib_Drivers
  35. * @{
  36. */
  37. #ifndef __LPC_EMC_H_
  38. #define __LPC_EMC_H_
  39. #include "lpc_types.h"
  40. #include "LPC407x_8x_177x_8x.h"
  41. /** @defgroup EMC_Private_Macros EMC Private Macros
  42. * @{
  43. */
  44. /***********************************************************************
  45. * EMC Control Register (EMCControl)
  46. **********************************************************************/
  47. /* Control register mask */
  48. #define EMC_Control_MASK ((uint32_t )0x07)
  49. /* Control register EMC: Enable control. */
  50. #define EMC_Control_E ((uint32_t )(1<<0))
  51. /* Control register EMC: Address mirror control. */
  52. #define EMC_Control_M ((uint32_t )(1<<1))
  53. /* Control register EMC: Low-power mode control. */
  54. #define EMC_Control_L ((uint32_t )(1<<2))
  55. /***********************************************************************
  56. * EMC Status Register (EMCStatus)
  57. **********************************************************************/
  58. /* Status register mask */
  59. #define EMC_Status_MASK ((uint32_t )0x07)
  60. /* Status register EMC: Busy. */
  61. #define EMC_Status_B ((uint32_t )(1<<0))
  62. /* Status register EMC: Write buffer status. */
  63. #define EMC_Status_S ((uint32_t )(1<<1))
  64. /* Status register EMC: Self-refresh acknowledge.. */
  65. #define EMC_Status_SA ((uint32_t )(1<<2))
  66. /***********************************************************************
  67. * EMC Configuration register (EMCConfig)
  68. **********************************************************************/
  69. /* EMC Configuration register : Little Endian. */
  70. #define EMC_Config_Little_Endian_Mode ((uint32_t )(0<<0))
  71. /* EMC Configuration register : Big Endian. */
  72. #define EMC_Config_Big_Endian_Mode ((uint32_t )(1<<0))
  73. /* EMC Configuration: Endian Mask */
  74. #define EMC_Config_Endian_Mask (0x01<<0)
  75. /* EMC Configuration register: CLKOUT ratio 1:1. */
  76. #define EMC_Config_CCLK_1_1 ((uinr32_t)(0<<8))
  77. /* EMC Configuration register: CLKOUT ratio 1:1. */
  78. #define EMC_Config_CCLK_1_2 ((uinr32_t)(1<<8))
  79. /* EMC Configuration register mask */
  80. #define EMC_Config_MASK ((uint32_t)(0x101))
  81. /***********************************************************************
  82. * Dynamic Memory Control register (EMCDynamicControl)
  83. **********************************************************************/
  84. /* Dynamic Memory Control register EMC: Dynamic memory clock enable. */
  85. #define EMC_DYNAMIC_CTRL_MEMCLK_EN_POS (0)
  86. #define EMC_DYNAMIC_CTRL_MEMCLK_EN_BMASK (1<<EMC_DYNAMIC_CTRL_MEMCLK_EN_POS)
  87. #define EMC_DYNAMIC_CTRL_CE_SAVEPWR (0<<EMC_DYNAMIC_CTRL_MEMCLK_EN_POS)
  88. #define EMC_DYNAMIC_CTRL_CE_ALLCLK_HI (1<<EMC_DYNAMIC_CTRL_MEMCLK_EN_POS)
  89. /* Dynamic Memory Control register EMC: Dynamic memory clock control */
  90. #define EMC_DYNAMIC_CTRL_CLKCTRL_POS (1)
  91. #define EMC_DYNAMIC_CTRL_CLKCTRL_BMASK (1<<EMC_DYNAMIC_CTRL_CLKCTRL_POS)
  92. #define EMC_DYNAMIC_CTRL_CS_CLKOUT_STOP (0<<EMC_DYNAMIC_CTRL_CLKCTRL_POS)
  93. #define EMC_DYNAMIC_CTRL_CE_CLKOUT_CONT (1<<EMC_DYNAMIC_CTRL_CLKCTRL_POS)
  94. /* Dynamic Memory Control register EMC: Self-refresh request, EMCSREFREQ*/
  95. #define EMC_DYNAMIC_CTRL_SELFREFRESH_REQ_POS (2)
  96. #define EMC_DYNAMIC_CTRL_SELFREFRESH_REQ_BMASK (1<<EMC_DYNAMIC_CTRL_SELFREFRESH_REQ_POS)
  97. #define EMC_DYNAMIC_CTRL_SR_NORMALMODE (0<<EMC_DYNAMIC_CTRL_SELFREFRESH_REQ_POS)
  98. #define EMC_DYNAMIC_CTRL_SR_SELFREFRESH (1<<EMC_DYNAMIC_CTRL_SELFREFRESH_REQ_POS)
  99. /* Dynamic Memory Control register EMC: Memory clock control (MMC)*/
  100. #define EMC_DYNAMIC_CTRL_MMC_CLKOUTCTRL_POS (5)
  101. #define EMC_DYNAMIC_CTRL_MMC_CLKOUTCTRL_BMASK (1<<EMC_DYNAMIC_CTRL_MMC_CLKOUTCTRL_POS)
  102. #define EMC_DYNAMIC_CTRL_MMC_CLKOUT_ENABLED (0<<EMC_DYNAMIC_CTRL_MMC_CLKOUTCTRL_POS)
  103. #define EMC_DYNAMIC_CTRL_MMC_CLKOUT_DISABLED (1<<EMC_DYNAMIC_CTRL_MMC_CLKOUTCTRL_POS)
  104. /* Dynamic Memory Control register EMC: SDRAM initialization*/
  105. #define EMC_DYNAMIC_CTRL_SDRAM_INIT_POS (7)
  106. #define EMC_DYNAMIC_CTRL_SDRAM_INIT_BMASK (0x03<<EMC_DYNAMIC_CTRL_SDRAM_INIT_POS)
  107. #define EMC_DYNAMIC_CTRL_SDRAM_NORMAL (0<<EMC_DYNAMIC_CTRL_SDRAM_INIT_POS)
  108. #define EMC_DYNAMIC_CTRL_SDRAM_MODE (1<<EMC_DYNAMIC_CTRL_SDRAM_INIT_POS)
  109. #define EMC_DYNAMIC_CTRL_SDRAM_PALL (2<<EMC_DYNAMIC_CTRL_SDRAM_INIT_POS)
  110. #define EMC_DYNAMIC_CTRL_SDRAM_NOP (3<<EMC_DYNAMIC_CTRL_SDRAM_INIT_POS)
  111. /* Dynamic Memory Control register EMC: Low-power SDRAM deep-sleep mode (DP)*/
  112. #define EMC_DYNAMIC_CTRL_SDRAM_PWRMODE_POS (13)
  113. #define EMC_DYNAMIC_CTRL_SDRAM_PWRMODE_BMASK (0x01<<EMC_DYNAMIC_CTRL_SDRAM_PWRMODE_POS)
  114. #define EMC_DYNAMIC_CTRL_DP_NORMAL (0<<EMC_DYNAMIC_CTRL_SDRAM_PWRMODE_POS)
  115. #define EMC_DYNAMIC_CTRL_DP_DEEPSLEEP (1<<EMC_DYNAMIC_CTRL_SDRAM_PWRMODE_POS)
  116. /***********************************************************************
  117. * Dynamic Memory Refresh Timer register (EMCDynamicRefresh)
  118. **********************************************************************/
  119. /* Dynamic Memory Refresh Timer register EMC: Refresh timer (REFRESH) */
  120. #define EMC_DynamicRefresh_REFRESH(n) ((uint32_t ) (n & 0x3ff))
  121. /***********************************************************************
  122. * Dynamic Memory Read Configuration register (EMCDynamicReadConfig)
  123. **********************************************************************/
  124. /* EMCDynamicReadConfig register EMC:Read data strategy (RD) */
  125. #define EMC_DynamicReadConfig_RD(n) ((uint32_t )(n & 0x03))
  126. /***********************************************************************
  127. * Dynamic Memory Percentage Command Period register (EMCDynamictRP)
  128. **********************************************************************/
  129. /* EMCDynamictRP register EMC: Precharge command period (tRP). */
  130. #define EMC_DynamictRP_tRP(n) ((uint32_t )(n & 0x0f))
  131. /***********************************************************************
  132. * Dynamic Memory Active to Precharge Command Period register (EMCDynamictRAS)
  133. **********************************************************************/
  134. /* EMCDynamictRAS register EMC: Active to precharge command period (tRAS) */
  135. #define EMC_DynamictRP_tRAS(n) ((uint32_t )(n & 0x0f))
  136. /***********************************************************************
  137. * Dynamic Memory Self-refresh Exit Time register (EMCDynamictSREX)
  138. **********************************************************************/
  139. /* EMCDynamictSREX register EMC: self-refresh exit time (tSREX)) */
  140. #define EMC_DynamictRP_tSREX(n) ((uint32_t )(n & 0x0f))
  141. /***********************************************************************
  142. * Dynamic Memory Last Data Out to Active Time register (EMCDynamictAPR)
  143. **********************************************************************/
  144. /* EMCDynamictAPR register EMC: Last-data-out to active command time (tAPR) */
  145. #define EMC_DynamictAPR_tAPR(n) ((uint32_t )(n & 0x0f))
  146. /***********************************************************************
  147. * Dynamic Memory Data-in to Active Command Time register (EMCDynamictDAL)
  148. **********************************************************************/
  149. /* EMCDynamictDAL register EMC: Data-in to active command (tDAL)*/
  150. #define EMC_DynamictDAL_tDAL(n) ((uint32_t )(n & 0x0f))
  151. /***********************************************************************
  152. * Dynamic Memory Write Recovery Time register (EMCDynamictWR)
  153. **********************************************************************/
  154. /* EMCDynamictWR register EMC: Write recovery time (tWR)*/
  155. #define EMC_DynamictWR_tWR(n) (uint32_t )(n & 0x0f)
  156. /***********************************************************************
  157. * Dynamic Memory Active to Active Command Period register (EMCDynamictRC)
  158. **********************************************************************/
  159. /* EMCDynamictRC register EMC: Active to active command period (tRC)*/
  160. #define EMC_DynamictRC_tRC(n) (uint32_t )(n & 0x1f)
  161. /***********************************************************************
  162. * Dynamic Memory Auto-refresh Period register (EMCDynamictRFC)
  163. **********************************************************************/
  164. /* EMCDynamictRFC register EMC: Auto-refresh period and auto-refresh to active command period (tRFC)*/
  165. #define EMC_DynamictRFC_tRFC(n) ((uint32_t )(n & 0x1f))
  166. /***********************************************************************
  167. * Dynamic Memory Exit Self-refresh register (EMCDynamictXSR)
  168. **********************************************************************/
  169. /* EMCDynamictXSR register EMC: Exit self-refresh to active command time (tXSR)*/
  170. #define EMC_DynamictXSR_tXSR(n) ((uint32_t )(n & 0x1f))
  171. /***********************************************************************
  172. * Dynamic Memory Active Bank A to Active Bank B Time register (EMCDynamictRRD)
  173. **********************************************************************/
  174. /* EMCDynamictRRD register EMC: Active bank A to active bank B latency (tRRD )*/
  175. #define EMC_DynamictRRD_tRRD(n) ((uint32_t )(n & 0x0f))
  176. /***********************************************************************
  177. Dynamic Memory Load Mode register to Active Command Time (EMCDynamictMRD)
  178. **********************************************************************/
  179. /* EMCDynamictMRD register EMC: Load mode register to active command time (tMRD)*/
  180. #define EMC_DynamictMRD_tMRD(n) ((uint32_t )(n & 0x1f))
  181. /***********************************************************************
  182. * Static Memory Extended Wait Register (EMCStaticExtendedWait)
  183. **********************************************************************/
  184. /* StaticExtendedWait register EMC: External wait time out. */
  185. #define EMC_StaticExtendedWait_EXTENDEDWAIT(n) ((uint32_t )(n & 0x3ff))
  186. /***********************************************************************
  187. * Dynamic Memory Configuration registers (EMCDynamicConfig0-3)
  188. **********************************************************************/
  189. /* DynamicConfig register EMC: Memory device (MD). */
  190. #define EMC_DYNAMIC_CFG_MEMDEV_POS (3)
  191. #define EMC_DYNAMIC_CFG_MEMDEV_BMASK (0x03 << EMC_DYNAMIC_CFG_MEMDEV_POS)
  192. #define EMC_DYNAMIC_CFG_MEMDEV_SDRAM (0 << EMC_DYNAMIC_CFG_MEMDEV_POS)
  193. #define EMC_DYNAMIC_CFG_MEMDEV_LOWPWR_SDRAM (1 << EMC_DYNAMIC_CFG_MEMDEV_POS)
  194. /* DynamicConfig register EMC: Address mapping (AM) */
  195. #define EMC_DYNAMIC_CFG_ADD_MAP_P1_POS (7)
  196. #define EMC_DYNAMIC_CFG_ADD_MAP_P1_MASK (0x3F<<EMC_DYNAMIC_CFG_ADD_MAP_P1_POS)
  197. #define EMC_DYNAMIC_CFG_ADD_MAP_P2_POS (12)
  198. #define EMC_DYNAMIC_CFG_ADD_MAP_P2_MASK (0x01 << EMC_DYNAMIC_CFG_ADD_MAP_P2_POS)
  199. #define EMC_DYNAMIC_CFG_ADD_MAP_P3_POS (14)
  200. #define EMC_DYNAMIC_CFG_ADD_MAP_P3_MASK (0x01 << EMC_DYNAMIC_CFG_ADD_MAP_P3_POS)
  201. #define EMC_DYNAMIC_CFG_ADD_MAP_P1(n) ( (n<<EMC_DYNAMIC_CFG_ADD_MAP_P1_POS)&EMC_DYNAMIC_CFG_ADD_MAP_P1_MASK)
  202. #define EMC_DYNAMIC_CFG_ADD_MAP_P2(n) ( (n<<EMC_DYNAMIC_CFG_ADD_MAP_P2_POS)&EMC_DYNAMIC_CFG_ADD_MAP_P2_MASK)
  203. #define EMC_DYNAMIC_CFG_ADD_MAP_P3(n) ( (n<<EMC_DYNAMIC_CFG_ADD_MAP_P3_POS)&EMC_DYNAMIC_CFG_ADD_MAP_P3_MASK)
  204. #define EMC_ADD_MAP_ROW_BANK_COL (0)
  205. #define EMC_ADD_MAP_BANK_ROW_COL (1)
  206. /* DynamicConfig register EMC: Buffer enable */
  207. #define EMC_DYNAMIC_CFG_BUFFENABLE_POS (19)
  208. #define EMC_DYNAMIC_CFG_BUFFENABLE_BMASK (0x01<<EMC_DYNAMIC_CFG_BUFFENABLE_POS)
  209. #define EMC_DYNAMIC_CFG_BUFF_DISABLED (0<<EMC_DYNAMIC_CFG_BUFFENABLE_POS)
  210. #define EMC_DYNAMIC_CFG_BUFF_ENABLED (1<<EMC_DYNAMIC_CFG_BUFFENABLE_POS)
  211. /* DynamicConfig register EMC: Write protect (P) */
  212. #define EMC_DYNAMIC_CFG_WRPROTECT_POS (20)
  213. #define EMC_DYNAMIC_CFG_WRPROTECT_BMASK (0x01<<EMC_DYNAMIC_CFG_WRPROTECT_POS)
  214. #define EMC_DYNAMIC_CFG_WR_UNPROTECTED (0<<EMC_DYNAMIC_CFG_WRPROTECT_POS)
  215. #define EMC_DYNAMIC_CFG_WR_PROTECTED (1<<EMC_DYNAMIC_CFG_WRPROTECT_POS)
  216. /***********************************************************************
  217. * Dynamic Memory RAS & CAS Delay registers (EMCDynamicRASCAS0-3)
  218. **********************************************************************/
  219. /* DynamicRASCAS register EMC: RAS latency (active to read/write delay) (RAS). */
  220. #define EMC_DYNAMIC_RASCAS_RASCFG_POS (0)
  221. #define EMC_DYNAMIC_RASCAS_RASCFG_BMASK (0x03<<EMC_DYNAMIC_RASCAS_RASCFG_POS)
  222. #define EMC_DYNAMIC_RASCAS_RASLATENCY_RESVD (0<<EMC_DYNAMIC_RASCAS_RASCFG_POS)
  223. #define EMC_DYNAMIC_RASCAS_RASLATENCY_1CLK (1<<EMC_DYNAMIC_RASCAS_RASCFG_POS)
  224. #define EMC_DYNAMIC_RASCAS_RASLATENCY_2CLK (2<<EMC_DYNAMIC_RASCAS_RASCFG_POS)
  225. #define EMC_DYNAMIC_RASCAS_RASLATENCY_3CLK (3<<EMC_DYNAMIC_RASCAS_RASCFG_POS)
  226. /* DynamicRASCAS register EMC: CAS latency (CAS)*/
  227. #define EMC_DYNAMIC_RASCAS_CASCFG_POS (8)
  228. #define EMC_DYNAMIC_RASCAS_CASCFG_BMASK (0x03<<EMC_DYNAMIC_RASCAS_CASCFG_POS)
  229. #define EMC_DYNAMIC_RASCAS_CASLATENCY_RESVD (0<<EMC_DYNAMIC_RASCAS_CASCFG_POS)
  230. #define EMC_DYNAMIC_RASCAS_CASLATENCY_1CLK (1<<EMC_DYNAMIC_RASCAS_CASCFG_POS)
  231. #define EMC_DYNAMIC_RASCAS_CASLATENCY_2CLK (2<<EMC_DYNAMIC_RASCAS_CASCFG_POS)
  232. #define EMC_DYNAMIC_RASCAS_CASLATENCY_3CLK (3<<EMC_DYNAMIC_RASCAS_CASCFG_POS)
  233. /***********************************************************************
  234. * Static Memory Configuration registers (EMCStaticConfig0-3)
  235. **********************************************************************/
  236. /* StaticConfig register EMC: Memory width (MW). */
  237. #define EMC_STATIC_CFG_MEMWIDTH_POS (0)
  238. #define EMC_STATIC_CFG_MEMWIDTH_BMASK (0x03<<EMC_STATIC_CFG_MEMWIDTH_POS)
  239. #define EMC_StaticConfig_MW(n) ((uint32_t )((n<<EMC_STATIC_CFG_MEMWIDTH_POS) & EMC_STATIC_CFG_MEMWIDTH_BMASK))
  240. /* StaticConfig register EMC: Memory width 8bit . */
  241. #define EMC_STATIC_CFG_MW_8BITS (EMC_StaticConfig_MW(0))
  242. /* StaticConfig register EMC: Memory width 16bit . */
  243. #define EMC_STATIC_CFG_MW_16BITS (EMC_StaticConfig_MW(1))
  244. /* StaticConfig register EMC: Memory width 32bit . */
  245. #define EMC_STATIC_CFG_MW_32BITS (EMC_StaticConfig_MW(2))
  246. /* StaticConfig register EMC: Page mode (PM) */
  247. #define EMC_STATIC_CFG_PAGEMODE_POS (3)
  248. #define EMC_STATIC_CFG_PAGEMODE_MASK (1<<EMC_STATIC_CFG_PAGEMODE_POS)
  249. #define EMC_CFG_PM_DISABLE (0<<EMC_STATIC_CFG_PAGEMODE_POS)
  250. #define EMC_CFG_PM_ASYNC_ENABLE (1<<EMC_STATIC_CFG_PAGEMODE_POS)
  251. /* StaticConfig register EMC: Chip select polarity (PC) */
  252. #define EMC_STATIC_CFG_CHIPPOLARITY_POS (6)
  253. #define EMC_STATIC_CFG_CHIPPOLARITY_MASK (1<<EMC_STATIC_CFG_CHIPPOLARITY_POS)
  254. #define EMC_CFG_BYTELAND_PC_ACTIVE_LO (0<<EMC_STATIC_CFG_CHIPPOLARITY_POS)
  255. #define EMC_CFG_BYTELAND_PC_ACTIVE_HI (1<<EMC_STATIC_CFG_CHIPPOLARITY_POS)
  256. /* StaticConfig register EMC: Byte lane state (PB) */
  257. #define EMC_STATIC_CFG_BYTELAND_POS (7)
  258. #define EMC_STATIC_CFG_BYTELAND_MASK (1<<EMC_STATIC_CFG_BYTELAND_POS)
  259. #define EMC_CFG_BYTELAND_READ_BITSHIGH (0<<EMC_STATIC_CFG_BYTELAND_POS)
  260. #define EMC_CFG_BYTELAND_READ_BITSLOW (1<<EMC_STATIC_CFG_BYTELAND_POS)
  261. /* StaticConfig register EMC: Extended wait (EW) */
  262. #define EMC_STATIC_CFG_EXTWAIT_POS (8)
  263. #define EMC_STATIC_CFG_EXTWAIT_MASK (1<<EMC_STATIC_CFG_EXTWAIT_POS)
  264. #define EMC_CFG_EW_DISABLED (0<<EMC_STATIC_CFG_EXTWAIT_POS)
  265. #define EMC_CFG_EW_ENABLED (1<<EMC_STATIC_CFG_EXTWAIT_POS)
  266. /* StaticConfig register EMC: Buffer enable (B) */
  267. #define EMC_STATIC_CFG_BUFENABLE_POS (19)
  268. #define EMC_STATIC_CFG_BUFENABLE_MASK (1<<EMC_STATIC_CFG_BUFENABLE_POS)
  269. #define EMC_CFG_BUF_DISABLED (0<<EMC_STATIC_CFG_BUFENABLE_POS)
  270. #define EMC_CFG_BUF_ENABLED (1<<EMC_STATIC_CFG_BUFENABLE_POS)
  271. /* StaticConfig register EMC: Write protect (P) */
  272. #define EMC_STATIC_CFG_WRIEPROTECT_POS (20)
  273. #define EMC_STATIC_CFG_WRIEPROTECT_MASK (1<<EMC_STATIC_CFG_WRIEPROTECT_POS)
  274. #define EMC_CFG_WRITEPROTECT_DISABLED (0<<EMC_STATIC_CFG_WRIEPROTECT_POS)
  275. #define EMC_CFG_WRITEPROTECT_ENABLED (1<<EMC_STATIC_CFG_WRIEPROTECT_POS)
  276. /***********************************************************************
  277. * Static Memory Write Enable Delay registers (EMCStaticWaitWen0-3)
  278. **********************************************************************/
  279. /* StaticWaitWen register EMC: Wait write enable (WAITWEN). */
  280. #define EMC_StaticWaitWen_WAITWEN(n) ((uint32_t )(n & 0x0f))
  281. /***********************************************************************
  282. * Static Memory Output Enable Delay registers (EMCStaticWaitOen0-3)
  283. **********************************************************************/
  284. /* StaticWaitOen register EMC: Wait output enable (WAITOEN). */
  285. #define EMC_StaticWaitOen_WAITOEN(n) ((uint32_t )(n & 0x0f))
  286. /***********************************************************************
  287. * Static Memory Read Delay registers (EMCStaticWaitRd0-3)
  288. **********************************************************************/
  289. /* StaticWaitRd register EMC: Non-page mode read wait states or asynchronous page mode
  290. read first access wait state (WAITRD) */
  291. #define EMC_StaticWaitRd_WAITRD(n) ((uint32_t )(n & 0x1f))
  292. /***********************************************************************
  293. * Static Memory Page Mode Read Delay registers (EMCStaticwaitPage0-3)
  294. **********************************************************************/
  295. /* StaticwaitPage register EMC: Asynchronous page mode read after the first
  296. read wait states (WAITPAGE). */
  297. #define EMC_StaticwaitPage_WAITPAGE(n) ((uint32_t )(n & 0x1f))
  298. /***********************************************************************
  299. * Static Memory Write Delay registers (EMCStaticWaitwr0-3)
  300. **********************************************************************/
  301. /* StaticWaitwr register EMC: Write wait states (WAITWR). */
  302. #define EMC_StaticWaitwr_WAITWR(n) ((uint32_t )(n & 0x1f))
  303. /***********************************************************************
  304. * Static Memory Turn Round Delay registers (EMCStaticWaitTurn0-3)
  305. **********************************************************************/
  306. /* StaticWaitTurn register EMC: Bus turnaround cycles (WAITTURN). */
  307. #define EMC_StaticWaitTurn_WAITTURN(n) ((uint32_t )(n & 0x0f))
  308. /***********************************************************************
  309. * Delay Control register (EMCDLYCTL)
  310. **********************************************************************/
  311. #define EMC_DLYCTL_CMDDLY(n) ((uint32_t)(n&0x1F))
  312. #define EMC_DLYCTL_FBCLKDLY(n) ((uint32_t)((n&0x1F)<<8))
  313. #define EMC_DLYCTL_CLKOUT0DLY(n) ((uint32_t)((n&0x1F)<<16))
  314. #define EMC_DLYCTL_CLKOUT1DLY(n) ((uint32_t)((n&0x1F)<<24))
  315. /***********************************************************************
  316. * EMC Calibration register (EMCCAL)
  317. **********************************************************************/
  318. #define EMC_CAL_CALVALUE(n) ((uint32_t)(n&0xFF))
  319. #define EMC_CAL_START ((uint32_t)(1<<14))
  320. #define EMC_CAL_DONE ((uint32_t)(1<<15))
  321. /***********************************************************************
  322. * EMC Function Return codes
  323. **********************************************************************/
  324. typedef int32_t EMC_FUNC_CODE;
  325. #define EMC_FUNC_OK (0)
  326. #define EMC_FUNC_ERR (0x01)
  327. #define EMC_FUNC_INVALID_PARAM (0x02)
  328. /**
  329. * @}
  330. */
  331. /* Public Types --------------------------------------------------------------- */
  332. /** @defgroup EMC_Public_Types EMC Public Types
  333. * @{
  334. */
  335. /*EMC dynamic memory registers enum*/
  336. typedef enum
  337. {
  338. EMC_DYN_MEM_REFRESH_TIMER,
  339. EMC_DYN_MEM_READ_CONFIG,
  340. EMC_DYN_MEM_TRP,
  341. EMC_DYN_MEM_TRAS,
  342. EMC_DYN_MEM_TSREX,
  343. EMC_DYN_MEM_TAPR,
  344. EMC_DYN_MEM_TDAL,
  345. EMC_DYN_MEM_TWR,
  346. EMC_DYN_MEM_TRC,
  347. EMC_DYN_MEM_TRFC,
  348. EMC_DYN_MEM_TXSR,
  349. EMC_DYN_MEM_TRRD,
  350. EMC_DYN_MEM_TMRD
  351. } EMC_DYN_MEM_PAR;
  352. /*EMC static memory registers enum*/
  353. typedef enum
  354. {
  355. EMC_STA_MEM_WAITWEN,
  356. EMC_STA_MEM_WAITOEN,
  357. EMC_STA_MEM_WAITRD,
  358. EMC_STA_MEM_WAITPAGE,
  359. EMC_STA_MEM_WAITWR,
  360. EMC_STA_MEM_WAITTURN,
  361. } EMC_STA_MEM_PAR;
  362. /* SDRAM Config Struct */
  363. typedef struct
  364. {
  365. uint8_t CSn; // 0/1/2/3
  366. uint32_t TotalSize; // SDRAM TotalSize
  367. uint16_t ChipSize; // chip size(Mb): 16Mb, 64Mb, 128Mb, 256Mb, 512Mb
  368. uint8_t DataWidth; // 8bit, 16 bit, 32bit
  369. uint8_t AddrBusWidth; // 16bit, 32bit
  370. uint8_t AddrMap; // EMC_ADD_MAP_BANK_ROW_COL/ EMC_ADD_MAP_ROW_BANK_COL
  371. /* timming */
  372. uint16_t RefreshTime; // Dynamic Refresh Time
  373. uint8_t ReadConfig; // Read Config Strategy
  374. uint8_t PrechargeCmdPeriod; // Precharge Command Period (tRP)
  375. uint8_t SeftRefreshExitTime; // Self-Refresh Exit Time (tSREX)
  376. uint8_t DataOut2ActiveTime; // the last-data-out to active command time (tAPR)
  377. uint8_t DataIn2ActiveTime; // the data-in to active command time (tDAL, or tAPW)
  378. uint8_t WriteRecoveryTime; // the write recovery time (tWR, tDPL, tRWL, or tRDL)
  379. uint8_t Active2ActivePeriod; // the active to active command period (tRC)
  380. uint8_t AutoRefrehPeriod; // the auto-refresh period and auto-refresh to active command period (tRFC/tRC)
  381. uint8_t ExitSelfRefreshTime; // the exit self-refresh to active command time (tXSR)
  382. uint8_t ActiveBankLatency; // the active bank A to active bank B latency (tRRD)
  383. uint8_t LoadModeReg2Active; // the load mode register to active command time (tMRD)
  384. uint8_t Active2PreChargeTime; // Active to precharge command period (tRAS)
  385. uint8_t RASLatency; // RAS Delay
  386. uint8_t CASLatency; // CAS Delay
  387. } EMC_DYN_MEM_Config_Type;
  388. typedef struct
  389. {
  390. uint8_t CSn; // 0/1/2/3
  391. uint8_t DataWidth; // 8bit, 16bit, 32bit
  392. uint8_t PageMode; // 1: asynchronous page mode enabled
  393. uint8_t ByteLane; // 1: Read when active bits are low, 0: read when acrive bits are High
  394. uint8_t ExtendedWait; //1: enabled
  395. uint8_t AddressMirror; // 1: reset memory map, 0: normal memory map
  396. uint8_t WaitWEn; // Delay from the chip select to the write enable (CCLK cycles)
  397. uint8_t WaitOEn; // Delay from the chip select or address change to output enable (CCLK cycles)
  398. uint8_t WaitRd; // Delay from the chip select to the read access (CCLK cycles)
  399. uint8_t WaitPage; // Delay for asynchronous page mode sequential accesses (CCLK cycles)
  400. uint8_t WaitWr; // Delay from the chip select to the write access (CCLK cycles)
  401. uint8_t WaitTurn; // The number of bus turnaround cycles
  402. } EMC_STATIC_MEM_Config_Type;
  403. /**
  404. * @}
  405. */
  406. /* Public Functions ----------------------------------------------------------- */
  407. /** @defgroup EMC_Public_Functions EMC Public Functions
  408. * @{
  409. */
  410. uint32_t EMC_SDRAM_REFRESH(uint32_t time);
  411. uint32_t EMC_NS2CLK(uint32_t time);
  412. EMC_FUNC_CODE DynMem_Init(EMC_DYN_MEM_Config_Type* pConfig);
  413. EMC_FUNC_CODE StaticMem_Init(EMC_STATIC_MEM_Config_Type* pConfig);
  414. EMC_FUNC_CODE EMC_Init(void);
  415. EMC_FUNC_CODE EMC_ConfigEndianMode(uint32_t endian_mode);
  416. EMC_FUNC_CODE EMC_DynCtrlClockEnable(uint32_t clock_enable);
  417. EMC_FUNC_CODE EMC_DynCtrlClockControl(int32_t clock_control);
  418. EMC_FUNC_CODE EMC_DynCtrlSelfRefresh(uint32_t self_refresh_mode);
  419. EMC_FUNC_CODE EMC_DynCtrlMMC(uint32_t MMC_val);
  420. EMC_FUNC_CODE EMC_DynCtrlSDRAMInit(uint32_t SDRAM_command);
  421. EMC_FUNC_CODE EMC_DynCtrlPowerDownMode(uint32_t SDRAM_command);
  422. EMC_FUNC_CODE EMC_SetDynMemoryParameter(EMC_DYN_MEM_PAR par, uint32_t val);
  423. EMC_FUNC_CODE EMC_StaticExtendedWait(uint32_t Extended_wait_time_out);
  424. EMC_FUNC_CODE EMC_DynMemConfigMD(uint32_t index , uint32_t mem_dev);
  425. EMC_FUNC_CODE EMC_DynMemConfigAM(uint32_t index , uint8_t addr_bus_width, uint8_t addr_map,uint8_t data_bus_width,uint16_t chip_size);
  426. EMC_FUNC_CODE EMC_DynMemConfigB(uint32_t index , uint32_t buff_control);
  427. EMC_FUNC_CODE EMC_DynMemConfigP(uint32_t index , uint32_t permission);
  428. EMC_FUNC_CODE EMC_DynMemRAS(uint32_t index , uint32_t ras_val);
  429. EMC_FUNC_CODE EMC_DynMemCAS(uint32_t index , uint32_t cas_val);
  430. EMC_FUNC_CODE EMC_StaMemConfigMW(uint32_t index , uint32_t mem_width);
  431. EMC_FUNC_CODE EMC_StaMemConfigPM(uint32_t index , uint32_t page_mode);
  432. EMC_FUNC_CODE EMC_StaMemConfigPC(uint32_t index , uint32_t pol_val);
  433. EMC_FUNC_CODE EMC_StaMemConfigPB(uint32_t index , uint32_t pb_val);
  434. EMC_FUNC_CODE EMC_StaMemConfigEW(uint32_t index , uint32_t ex_wait);
  435. EMC_FUNC_CODE EMC_StaMemConfigB(uint32_t index , uint32_t buf_val);
  436. EMC_FUNC_CODE EMC_StaMemConfigpP(uint32_t index , uint32_t per_val);
  437. EMC_FUNC_CODE EMC_SetStaMemoryParameter(uint32_t index ,EMC_STA_MEM_PAR par, uint32_t val);
  438. /**
  439. * @}
  440. */
  441. #endif /* __LPC_EMC_H_ */
  442. /**
  443. * @}
  444. */