lpc177x_8x_emc.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361
  1. /**********************************************************************
  2. * $Id$ lpc177x_8x_emc.h 2011-06-02
  3. *//**
  4. * @file lpc177x_8x_emc.h
  5. * @brief Contains all macro definitions and function prototypes
  6. * support for EMC firmware library on LPC177x_8x
  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. **********************************************************************/
  26. /* Peripheral group ----------------------------------------------------------- */
  27. /** @defgroup EMC EMC (External Memory Controller)
  28. * @ingroup LPC177x_8xCMSIS_FwLib_Drivers
  29. * @{
  30. */
  31. #ifndef __LPC177X_8X_EMC_H_
  32. #define __LPC177X_8X_EMC_H_
  33. #include "lpc_types.h"
  34. #include "LPC177x_8x.h"
  35. /** @defgroup EMC_Private_Macros EMC Private Macros
  36. * @{
  37. */
  38. /***********************************************************************
  39. * EMC Control Register (EMCControl)
  40. **********************************************************************/
  41. /* Control register mask */
  42. #define EMC_Control_MASK ((uint32_t )0x07)
  43. /* Control register EMC: Enable control. */
  44. #define EMC_Control_E ((uint32_t )(1<<0))
  45. /* Control register EMC: Address mirror control. */
  46. #define EMC_Control_M ((uint32_t )(1<<1))
  47. /* Control register EMC: Low-power mode control. */
  48. #define EMC_Control_L ((uint32_t )(1<<2))
  49. /***********************************************************************
  50. * EMC Status Register (EMCStatus)
  51. **********************************************************************/
  52. /* Status register mask */
  53. #define EMC_Status_MASK ((uint32_t )0x07)
  54. /* Status register EMC: Busy. */
  55. #define EMC_Status_B ((uint32_t )(1<<0))
  56. /* Status register EMC: Write buffer status. */
  57. #define EMC_Status_S ((uint32_t )(1<<1))
  58. /* Status register EMC: Self-refresh acknowledge.. */
  59. #define EMC_Status_SA ((uint32_t )(1<<2))
  60. /***********************************************************************
  61. * EMC Configuration register (EMCConfig)
  62. **********************************************************************/
  63. /* EMC Configuration register : Enable control. */
  64. #define EMC_Config_Endian_Mode ((uint32_t )(1<<0))
  65. /* EMC Configuration register: CCLK. */
  66. #define EMC_Config_CCLK ((uinr32_t)(1<<8))
  67. /* EMC Configuration register mask */
  68. #define EMC_Config_MASK ((uint32_t)(0x101))
  69. /***********************************************************************
  70. * Dynamic Memory Control register (EMCDynamicControl)
  71. **********************************************************************/
  72. /* Dynamic Memory Control register EMC: Dynamic memory clock enable. */
  73. #define EMC_DynamicControl_CE ((uint32_t )(1<<0))
  74. /* Dynamic Memory Control register EMC: Dynamic memory clock control */
  75. #define EMC_DynamicControl_CS ((uint32_t )(1<<1))
  76. /* Dynamic Memory Control register EMC: Self-refresh request, EMCSREFREQ*/
  77. #define EMC_DynamicControl_SR ((uint32_t )(1<<2))
  78. /* Dynamic Memory Control register EMC: Memory clock control (MMC)*/
  79. #define EMC_DynamicControl_MMC ((uint32_t )(1<<5))
  80. /* Dynamic Memory Control register EMC: SDRAM initialization*/
  81. #define EMC_DynamicControl_I(n) ((uint32_t )(n<<7))
  82. /* Dynamic Memory Control register EMC: Low-power SDRAM deep-sleep mode (DP)*/
  83. #define EMC_DynamicControl_DP ((uint32_t ) (1<<13))
  84. /***********************************************************************
  85. * Dynamic Memory Refresh Timer register (EMCDynamicRefresh)
  86. **********************************************************************/
  87. /* Dynamic Memory Refresh Timer register EMC: Refresh timer (REFRESH) */
  88. #define EMC_DynamicRefresh_REFRESH(n) ((uint32_t ) (n & 0x3ff))
  89. /***********************************************************************
  90. * Dynamic Memory Read Configuration register (EMCDynamicReadConfig)
  91. **********************************************************************/
  92. /* EMCDynamicReadConfig register EMC:Read data strategy (RD) */
  93. #define EMC_DynamicReadConfig_RD(n) ((uint32_t )(n & 0x03))
  94. /***********************************************************************
  95. * Dynamic Memory Percentage Command Period register (EMCDynamictRP)
  96. **********************************************************************/
  97. /* EMCDynamictRP register EMC: Precharge command period (tRP). */
  98. #define EMC_DynamictRP_tRP(n) ((uint32_t )(n & 0x0f))
  99. /***********************************************************************
  100. * Dynamic Memory Active to Precharge Command Period register (EMCDynamictRAS)
  101. **********************************************************************/
  102. /* EMCDynamictRAS register EMC: Active to precharge command period (tRAS) */
  103. #define EMC_DynamictRP_tRAS(n) ((uint32_t )(n & 0x0f))
  104. /***********************************************************************
  105. * Dynamic Memory Last Data Out to Active Time register (EMCDynamictAPR)
  106. **********************************************************************/
  107. /* EMCDynamictAPR register EMC: Last-data-out to active command time (tAPR) */
  108. #define EMC_DynamictAPR_tAPR(n) ((uint32_t )(n & 0x0f))
  109. /***********************************************************************
  110. * Dynamic Memory Data-in to Active Command Time register (EMCDynamictDAL)
  111. **********************************************************************/
  112. /* EMCDynamictDAL register EMC: Data-in to active command (tDAL)*/
  113. #define EMC_DynamictDAL_tDAL(n) ((uint32_t )(n & 0x0f))
  114. /***********************************************************************
  115. * Dynamic Memory Write Recovery Time register (EMCDynamictWR)
  116. **********************************************************************/
  117. /* EMCDynamictWR register EMC: Write recovery time (tWR)*/
  118. #define EMC_DynamictWR_tWR(n) (uint32_t )(n & 0x0f)
  119. /***********************************************************************
  120. * Dynamic Memory Active to Active Command Period register (EMCDynamictRC)
  121. **********************************************************************/
  122. /* EMCDynamictRC register EMC: Active to active command period (tRC)*/
  123. #define EMC_DynamictRC_tRC(n) (uint32_t )(n & 0x1f)
  124. /***********************************************************************
  125. * Dynamic Memory Auto-refresh Period register (EMCDynamictRFC)
  126. **********************************************************************/
  127. /* EMCDynamictRFC register EMC: Auto-refresh period and auto-refresh to active command period (tRFC)*/
  128. #define EMC_DynamictRFC_tRFC(n) ((uint32_t )(n & 0x1f))
  129. /***********************************************************************
  130. * Dynamic Memory Exit Self-refresh register (EMCDynamictXSR)
  131. **********************************************************************/
  132. /* EMCDynamictXSR register EMC: Exit self-refresh to active command time (tXSR)*/
  133. #define EMC_DynamictXSR_tXSR(n) ((uint32_t )(n & 0x1f))
  134. /***********************************************************************
  135. * Dynamic Memory Active Bank A to Active Bank B Time register (EMCDynamictRRD)
  136. **********************************************************************/
  137. /* EMCDynamictRRD register EMC: Active bank A to active bank B latency (tRRD )*/
  138. #define EMC_DynamictRRD_tRRD(n) ((uint32_t )(n & 0x0f))
  139. /***********************************************************************
  140. Dynamic Memory Load Mode register to Active Command Time (EMCDynamictMRD)
  141. **********************************************************************/
  142. /* EMCDynamictMRD register EMC: Load mode register to active command time (tMRD)*/
  143. #define EMC_DynamictMRD_tMRD(n) ((uint32_t )(n & 0x1f))
  144. /***********************************************************************
  145. * Static Memory Extended Wait Register (EMCStaticExtendedWait)
  146. **********************************************************************/
  147. /* StaticExtendedWait register EMC: External wait time out. */
  148. #define EMC_StaticExtendedWait_EXTENDEDWAIT(n) ((uint32_t )(n & 0x3ff))
  149. /***********************************************************************
  150. * Dynamic Memory Configuration registers (EMCDynamicConfig0-3)
  151. **********************************************************************/
  152. /* DynamicConfig register EMC: Memory device (MD). */
  153. #define EMC_DynamicConfig_MD(n) ((uint32_t )(n << 3))
  154. /* DynamicConfig register EMC: Address mapping (AM) */
  155. #define EMC_DynamicConfig_AM1(n) ((uint32_t )(n << 7))
  156. /* DynamicConfig register EMC: Address mapping (AM) */
  157. #define EMC_DynamicConfig_AM2(n) ((uint32_t )(1 << 14))
  158. /* DynamicConfig register EMC: Buffer enable */
  159. #define EMC_DynamicConfig_B ((uint32_t )(1 << 19))
  160. /* DynamicConfig register EMC: Write protect (P) */
  161. #define EMC_DynamicConfig_P ((uint32_t )(1 << 20))
  162. /***********************************************************************
  163. * Dynamic Memory RAS & CAS Delay registers (EMCDynamicRASCAS0-3)
  164. **********************************************************************/
  165. /* DynamicRASCAS register EMC: RAS latency (active to read/write delay) (RAS). */
  166. #define EMC_DynamicConfig_RAS(n) ((uint32_t )(n & 0x03))
  167. /* DynamicRASCAS register EMC: CAS latency (CAS)*/
  168. #define EMC_DynamicConfig_CAS(n) ((uint32_t )(n << 8))
  169. /***********************************************************************
  170. * Static Memory Configuration registers (EMCStaticConfig0-3)
  171. **********************************************************************/
  172. /* StaticConfig register EMC: Memory width (MW). */
  173. #define EMC_StaticConfig_MW(n) ((uint32_t )(n & 0x03))
  174. /* StaticConfig register EMC: Memory width 8bit . */
  175. #define EMC_StaticConfig_MW_8BITS (EMC_StaticConfig_MW(0))
  176. /* StaticConfig register EMC: Memory width 16bit . */
  177. #define EMC_StaticConfig_MW_16BITS (EMC_StaticConfig_MW(1))
  178. /* StaticConfig register EMC: Memory width 32bit . */
  179. #define EMC_StaticConfig_MW_32BITS (EMC_StaticConfig_MW(2))
  180. /* StaticConfig register EMC: Page mode (PM) */
  181. #define EMC_StaticConfig_PM ((uint32_t )(1 << 3))
  182. /* StaticConfig register EMC: Chip select polarity (PC) */
  183. #define EMC_StaticConfig_PC ((uint32_t )(1 << 6))
  184. /* StaticConfig register EMC: Byte lane state (PB) */
  185. #define EMC_StaticConfig_PB ((uint32_t )(1 << 7))
  186. /* StaticConfig register EMC: Extended wait (EW) */
  187. #define EMC_StaticConfig_EW ((uint32_t )(1 << 8))
  188. /* StaticConfig register EMC: Buffer enable (B) */
  189. #define EMC_StaticConfig_B ((uint32_t )(1 << 19))
  190. /* StaticConfig register EMC: Write protect (P) */
  191. #define EMC_StaticConfig_P ((uint32_t )(1 << 20))
  192. /***********************************************************************
  193. * Static Memory Write Enable Delay registers (EMCStaticWaitWen0-3)
  194. **********************************************************************/
  195. /* StaticWaitWen register EMC: Wait write enable (WAITWEN). */
  196. #define EMC_StaticWaitWen_WAITWEN(n) ((uint32_t )(n & 0x0f))
  197. /***********************************************************************
  198. * Static Memory Output Enable Delay registers (EMCStaticWaitOen0-3)
  199. **********************************************************************/
  200. /* StaticWaitOen register EMC: Wait output enable (WAITOEN). */
  201. #define EMC_StaticWaitOen_WAITOEN(n) ((uint32_t )(n & 0x0f))
  202. /***********************************************************************
  203. * Static Memory Read Delay registers (EMCStaticWaitRd0-3)
  204. **********************************************************************/
  205. /* StaticWaitRd register EMC: Non-page mode read wait states or asynchronous page mode
  206. read first access wait state (WAITRD) */
  207. #define EMC_StaticWaitRd_WAITRD(n) ((uint32_t )(n & 0x1f))
  208. /***********************************************************************
  209. * Static Memory Page Mode Read Delay registers (EMCStaticwaitPage0-3)
  210. **********************************************************************/
  211. /* StaticwaitPage register EMC: Asynchronous page mode read after the first
  212. read wait states (WAITPAGE). */
  213. #define EMC_StaticwaitPage_WAITPAGE(n) ((uint32_t )(n & 0x1f))
  214. /***********************************************************************
  215. * Static Memory Write Delay registers (EMCStaticWaitwr0-3)
  216. **********************************************************************/
  217. /* StaticWaitwr register EMC: Write wait states (WAITWR). */
  218. #define EMC_StaticWaitwr_WAITWR(n) ((uint32_t )(n & 0x1f))
  219. /***********************************************************************
  220. * Static Memory Turn Round Delay registers (EMCStaticWaitTurn0-3)
  221. **********************************************************************/
  222. /* StaticWaitTurn register EMC: Bus turnaround cycles (WAITTURN). */
  223. #define EMC_StaticWaitTurn_WAITTURN(n) ((uint32_t )(n & 0x0f))
  224. /***********************************************************************
  225. * Delay Control register (EMCDLYCTL)
  226. **********************************************************************/
  227. #define EMC_DLYCTL_CMDDLY(n) ((uint32_t)(n&0x1F))
  228. #define EMC_DLYCTL_FBCLKDLY(n) ((uint32_t)((n&0x1F)<<8))
  229. #define EMC_DLYCTL_CLKOUT0DLY(n) ((uint32_t)((n&0x1F)<<16))
  230. #define EMC_DLYCTL_CLKOUT1DLY(n) ((uint32_t)((n&0x1F)<<24))
  231. /***********************************************************************
  232. * EMC Calibration register (EMCCAL)
  233. **********************************************************************/
  234. #define EMC_CAL_CALVALUE(n) ((uint32_t)(n&0xFF))
  235. #define EMC_CAL_START ((uint32_t)(1<<14))
  236. #define EMC_CAL_DONE ((uint32_t)(1<<15))
  237. #define EMC_LITTLE_ENDIAN_MODE ((uint32_t)(0))
  238. #define EMC_BIG_ENDIAN_MODE ((uint32_t)(1))
  239. /**
  240. * @}
  241. */
  242. /* Public Types --------------------------------------------------------------- */
  243. /** @defgroup EMC_Public_Types EMC Public Types
  244. * @{
  245. */
  246. /*EMC dynamic memory registers enum*/
  247. typedef enum
  248. {
  249. EMC_DYN_MEM_REFRESH_TIMER,
  250. EMC_DYN_MEM_READ_CONFIG,
  251. EMC_DYN_MEM_TRP,
  252. EMC_DYN_MEM_TRAS,
  253. EMC_DYN_MEM_TSREX,
  254. EMC_DYN_MEM_TAPR,
  255. EMC_DYN_MEM_TDAL,
  256. EMC_DYN_MEM_TWR,
  257. EMC_DYN_MEM_TRC,
  258. EMC_DYN_MEM_TRFC,
  259. EMC_DYN_MEM_TXSR,
  260. EMC_DYN_MEM_TRRD,
  261. EMC_DYN_MEM_TMRD
  262. } EMC_DYN_MEM_PAR;
  263. /*EMC static memory registers enum*/
  264. typedef enum
  265. {
  266. EMC_STA_MEM_WAITWEN,
  267. EMC_STA_MEM_WAITOEN,
  268. EMC_STA_MEM_WAITRD,
  269. EMC_STA_MEM_WAITPAGE,
  270. EMC_STA_MEM_WAITWR,
  271. EMC_STA_MEM_WAITTURN,
  272. } EMC_STA_MEM_PAR;
  273. /**
  274. * @}
  275. */
  276. /* Public Functions ----------------------------------------------------------- */
  277. /** @defgroup EMC_Public_Functions EMC Public Functions
  278. * @{
  279. */
  280. extern void EMC_Init(void);
  281. extern void EMC_ConfigEndianMode(uint32_t endian_mode);
  282. extern void EMC_DynCtrlClockEnable(uint32_t clock_enable);
  283. extern void EMC_DynCtrlClockControl(int32_t clock_control);
  284. extern void EMC_DynCtrlSelfRefresh(uint32_t self_refresh_mode);
  285. extern void EMC_DynCtrlMMC(uint32_t MMC_val);
  286. extern void EMC_DynCtrlSDRAMInit(uint32_t SDRAM_command);
  287. extern void EMC_DynCtrlPowerDownMode(uint32_t SDRAM_command);
  288. extern void EMC_SetDynMemoryParameter(EMC_DYN_MEM_PAR par, uint32_t val);
  289. extern void EMC_StaticExtendedWait(uint32_t Extended_wait_time_out);
  290. extern void EMC_DynMemConfigMD(uint32_t index , uint32_t mem_dev);
  291. extern void EMC_DynMemConfigAM(uint32_t index , uint32_t add_mapped);
  292. extern void EMC_DynMemConfigB(uint32_t index , uint32_t buff_control);
  293. extern void EMC_DynMemConfigP(uint32_t index , uint32_t permission);
  294. extern void EMC_DynMemRAS(uint32_t index , uint32_t ras_val);
  295. extern void EMC_DynMemCAS(uint32_t index , uint32_t cas_val);
  296. extern void EMC_StaMemConfigMW(uint32_t index , uint32_t mem_width);
  297. extern void EMC_StaMemConfigPM(uint32_t index , uint32_t page_mode);
  298. extern void EMC_StaMemConfigPC(uint32_t index , uint32_t pol_val);
  299. extern void EMC_StaMemConfigPB(uint32_t index , uint32_t pb_val);
  300. extern void EMC_StaMemConfigEW(uint32_t index , uint32_t ex_wait);
  301. extern void EMC_StaMemConfigB(uint32_t index , uint32_t buf_val);
  302. extern void EMC_StaMemConfigpP(uint32_t index , uint32_t per_val);
  303. extern void EMC_SetStaMemoryParameter(uint32_t index ,EMC_STA_MEM_PAR par, uint32_t val);
  304. /**
  305. * @}
  306. */
  307. #endif /* __LPC177X_8X_EMC_H_ */
  308. /**
  309. * @}
  310. */