00001 #ifndef _LPC177X_8X_EMC_H_ 00002 #define _LPC177X_8X_EMC_H_ 00003 00004 /* 00005 * Copyright (C) 2012 by Ole Reinhardt (ole.reinhardt@embedded-it.de) 00006 * 00007 * All rights reserved. 00008 * 00009 * Redistribution and use in source and binary forms, with or without 00010 * modification, are permitted provided that the following conditions 00011 * are met: 00012 * 00013 * 1. Redistributions of source code must retain the above copyright 00014 * notice, this list of conditions and the following disclaimer. 00015 * 2. Redistributions in binary form must reproduce the above copyright 00016 * notice, this list of conditions and the following disclaimer in the 00017 * documentation and/or other materials provided with the distribution. 00018 * 3. Neither the name of the copyright holders nor the names of 00019 * contributors may be used to endorse or promote products derived 00020 * from this software without specific prior written permission. 00021 * 00022 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 00023 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00024 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00025 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 00026 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00027 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00028 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00029 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00030 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00032 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00033 * SUCH DAMAGE. 00034 * 00035 * For additional information see http://www.ethernut.de/ 00036 * 00037 * 00038 * Parts taken from lpc177x_8x_emc.h 2011-06-02 00039 * 00040 * file lpc177x_8x_emc.h 00041 * brief Contains all macro definitions and function prototypes 00042 * support for EMC firmware library on LPC177x_8x 00043 * version 1.0 00044 * date 02. June. 2011 00045 * author NXP MCU SW Application Team 00046 * 00047 * Copyright(C) 2011, NXP Semiconductor 00048 * All rights reserved. 00049 * 00050 *********************************************************************** 00051 * Software that is described herein is for illustrative purposes only 00052 * which provides customers with programming information regarding the 00053 * products. This software is supplied "AS IS" without any warranties. 00054 * NXP Semiconductors assumes no responsibility or liability for the 00055 * use of the software, conveys no license or title under any patent, 00056 * copyright, or mask work right to the product. NXP Semiconductors 00057 * reserves the right to make changes in the software without 00058 * notification. NXP Semiconductors also make no representation or 00059 * warranty that such application will be suitable for the specified 00060 * use without further testing or modification. 00061 **********************************************************************/ 00062 00063 #include <inttypes.h> 00064 #include <dev/sdram.h> 00065 00066 /*----------------------------------------------------------------------------* 00067 External memory controller settings and functions 00068 *----------------------------------------------------------------------------*/ 00069 00070 00071 00072 /*----------------------------------------------------------------------------* 00073 EMC Control Register (EMCControl) 00074 *----------------------------------------------------------------------------*/ 00075 00076 #define EMC_Control_MASK ((uint32_t) 0x07) /* Control register mask */ 00077 #define EMC_Control_E ((uint32_t)(1<<0)) /* Control register EMC: Enable control. */ 00078 #define EMC_Control_M ((uint32_t)(1<<1)) /* Control register EMC: Address mirror control. */ 00079 #define EMC_Control_L ((uint32_t)(1<<2)) /* Control register EMC: Low-power mode control. */ 00080 00081 00082 /*----------------------------------------------------------------------------* 00083 EMC Status Register (EMCStatus) 00084 *----------------------------------------------------------------------------*/ 00085 00086 #define EMC_Status_MASK ((uint32_t) 0x07) /* Status register mask */ 00087 #define EMC_Status_B ((uint32_t)(1<<0)) /* Status register EMC: Busy. */ 00088 #define EMC_Status_S ((uint32_t)(1<<1)) /* Status register EMC: Write buffer status. */ 00089 #define EMC_Status_SA ((uint32_t)(1<<2)) /* Status register EMC: Self-refresh acknowledge.. */ 00090 00091 00092 /*----------------------------------------------------------------------------* 00093 EMC Configuration register (EMCConfig) 00094 *----------------------------------------------------------------------------*/ 00095 00096 #define EMC_Config_Endian_Mode ((uint32_t)(1<<0)) /* EMC Configuration register : Enable control. */ 00097 #define EMC_Config_CCLK ((uint32_t)(1<<8)) /* EMC Configuration register: CCLK. */ 00098 #define EMC_Config_MASK ((uint32_t)(0x101)) /* EMC Configuration register mask */ 00099 00100 00101 /*----------------------------------------------------------------------------* 00102 Dynamic Memory Control register (EMCDynamicControl) 00103 *----------------------------------------------------------------------------*/ 00104 00105 #define EMC_DynamicControl_CE ((uint32_t)(1<<0)) /* Dynamic Memory Control register EMC: Dynamic memory clock enable. */ 00106 #define EMC_DynamicControl_CS ((uint32_t)(1<<1)) /* Dynamic Memory Control register EMC: Dynamic memory clock control */ 00107 #define EMC_DynamicControl_SR ((uint32_t)(1<<2)) /* Dynamic Memory Control register EMC: Self-refresh request, EMCSREFREQ*/ 00108 #define EMC_DynamicControl_MMC ((uint32_t)(1<<5)) /* Dynamic Memory Control register EMC: Memory clock control (MMC)*/ 00109 #define EMC_DynamicControl_I(n) ((uint32_t)(n<<7)) /* Dynamic Memory Control register EMC: SDRAM initialization*/ 00110 #define EMC_DynamicControl_DP ((uint32_t)(1<<13)) /* Dynamic Memory Control register EMC: Low-power SDRAM deep-sleep mode (DP)*/ 00111 00112 00113 /*----------------------------------------------------------------------------* 00114 Dynamic Memory Refresh Timer register (EMCDynamicRefresh) 00115 *----------------------------------------------------------------------------*/ 00116 00117 #define EMC_DynamicRefresh_REFRESH(n) ((uint32_t ) (n & 0x3ff)) /* Dynamic Memory Refresh Timer register EMC: Refresh timer (REFRESH) */ 00118 00119 00120 /*----------------------------------------------------------------------------* 00121 Dynamic Memory Read Configuration register (EMCDynamicReadConfig) 00122 *----------------------------------------------------------------------------*/ 00123 00124 #define EMC_DynamicReadConfig_RD(n) ((uint32_t )(n & 0x03)) /* EMCDynamicReadConfig register EMC:Read data strategy (RD) */ 00125 00126 00127 /*----------------------------------------------------------------------------* 00128 Dynamic Memory Percentage Command Period register (EMCDynamictRP) 00129 *----------------------------------------------------------------------------*/ 00130 00131 #define EMC_DynamictRP_tRP(n) ((uint32_t )(n & 0x0f)) /* EMCDynamictRP register EMC: Precharge command period (tRP). */ 00132 00133 00134 /*----------------------------------------------------------------------------* 00135 Dynamic Memory Active to Precharge Command Period register (EMCDynamictRAS) 00136 *----------------------------------------------------------------------------*/ 00137 00138 #define EMC_DynamictRP_tRAS(n) ((uint32_t )(n & 0x0f)) /* EMCDynamictRAS register EMC: Active to precharge command period (tRAS) */ 00139 00140 00141 /*----------------------------------------------------------------------------* 00142 Dynamic Memory Last Data Out to Active Time register (EMCDynamictAPR) 00143 *----------------------------------------------------------------------------*/ 00144 00145 #define EMC_DynamictAPR_tAPR(n) ((uint32_t )(n & 0x0f)) /* EMCDynamictAPR register EMC: Last-data-out to active command time (tAPR) */ 00146 00147 00148 /*----------------------------------------------------------------------------* 00149 Dynamic Memory Data-in to Active Command Time register (EMCDynamictDAL) 00150 *----------------------------------------------------------------------------*/ 00151 00152 #define EMC_DynamictDAL_tDAL(n) ((uint32_t )(n & 0x0f)) /* EMCDynamictDAL register EMC: Data-in to active command (tDAL)*/ 00153 00154 00155 /*----------------------------------------------------------------------------* 00156 Dynamic Memory Write Recovery Time register (EMCDynamictWR) 00157 *----------------------------------------------------------------------------*/ 00158 00159 #define EMC_DynamictWR_tWR(n) ((uint32_t )(n & 0x0f)) /* EMCDynamictWR register EMC: Write recovery time (tWR)*/ 00160 00161 00162 /*----------------------------------------------------------------------------* 00163 Dynamic Memory Active to Active Command Period register (EMCDynamictRC) 00164 *----------------------------------------------------------------------------*/ 00165 00166 #define EMC_DynamictRC_tRC(n) ((uint32_t )(n & 0x1f)) /* EMCDynamictRC register EMC: Active to active command period (tRC)*/ 00167 00168 00169 /*----------------------------------------------------------------------------* 00170 Dynamic Memory Auto-refresh Period register (EMCDynamictRFC) 00171 *----------------------------------------------------------------------------*/ 00172 00173 #define EMC_DynamictRFC_tRFC(n) ((uint32_t )(n & 0x1f)) /* EMCDynamictRFC register EMC: Auto-refresh period and auto-refresh to active command period (tRFC)*/ 00174 00175 00176 /*----------------------------------------------------------------------------* 00177 Dynamic Memory Exit Self-refresh register (EMCDynamictXSR) 00178 *----------------------------------------------------------------------------*/ 00179 00180 #define EMC_DynamictXSR_tXSR(n) ((uint32_t )(n & 0x1f)) /* EMCDynamictXSR register EMC: Exit self-refresh to active command time (tXSR)*/ 00181 00182 00183 /*----------------------------------------------------------------------------* 00184 Dynamic Memory Active Bank A to Active Bank B Time register (EMCDynamictRRD) 00185 *----------------------------------------------------------------------------*/ 00186 00187 #define EMC_DynamictRRD_tRRD(n) ((uint32_t )(n & 0x0f)) /* EMCDynamictRRD register EMC: Active bank A to active bank B latency (tRRD )*/ 00188 00189 00190 /*----------------------------------------------------------------------------* 00191 Dynamic Memory Load Mode register to Active Command Time (EMCDynamictMRD) 00192 *----------------------------------------------------------------------------*/ 00193 00194 #define EMC_DynamictMRD_tMRD(n) ((uint32_t )(n & 0x1f)) /* EMCDynamictMRD register EMC: Load mode register to active command time (tMRD)*/ 00195 00196 00197 /*----------------------------------------------------------------------------* 00198 Static Memory Extended Wait Register (EMCStaticExtendedWait) 00199 *----------------------------------------------------------------------------*/ 00200 00201 #define EMC_StaticExtendedWait_EXTENDEDWAIT(n) ((uint32_t )(n & 0x3ff)) /* StaticExtendedWait register EMC: External wait time out. */ 00202 00203 00204 /*----------------------------------------------------------------------------* 00205 Dynamic Memory Configuration registers (EMCDynamicConfig0-3) 00206 *----------------------------------------------------------------------------*/ 00207 00208 #define EMC_DynamicConfig_MD(n) ((uint32_t )(n << 3)) /* DynamicConfig register EMC: Memory device (MD). */ 00209 #define EMC_DynamicConfig_AM1(n) ((uint32_t )(n << 7)) /* DynamicConfig register EMC: Address mapping (AM) */ 00210 #define EMC_DynamicConfig_AM2(n) ((uint32_t )(1 << 14)) /* DynamicConfig register EMC: Address mapping (AM) */ 00211 #define EMC_DynamicConfig_B ((uint32_t )(1 << 19)) /* DynamicConfig register EMC: Buffer enable */ 00212 #define EMC_DynamicConfig_P ((uint32_t )(1 << 20)) /* DynamicConfig register EMC: Write protect (P) */ 00213 00214 00215 /*----------------------------------------------------------------------------* 00216 Dynamic Memory RAS & CAS Delay registers (EMCDynamicRASCAS0-3) 00217 *----------------------------------------------------------------------------*/ 00218 00219 #define EMC_DynamicConfig_RAS(n) ((uint32_t )(n & 0x03)) /* DynamicRASCAS register EMC: RAS latency (active to read/write delay) (RAS). */ 00220 #define EMC_DynamicConfig_CAS(n) ((uint32_t )(n << 8)) /* DynamicRASCAS register EMC: CAS latency (CAS)*/ 00221 00222 00223 /*----------------------------------------------------------------------------* 00224 Static Memory Configuration registers (EMCStaticConfig0-3) 00225 *----------------------------------------------------------------------------*/ 00226 00227 #define EMC_StaticConfig_MW(n) ((uint32_t )(n & 0x03)) /* StaticConfig register EMC: Memory width (MW). */ 00228 #define EMC_StaticConfig_MW_8BITS (EMC_StaticConfig_MW(0)) /* StaticConfig register EMC: Memory width 8bit . */ 00229 #define EMC_StaticConfig_MW_16BITS (EMC_StaticConfig_MW(1)) /* StaticConfig register EMC: Memory width 16bit . */ 00230 #define EMC_StaticConfig_MW_32BITS (EMC_StaticConfig_MW(2)) /* StaticConfig register EMC: Memory width 32bit . */ 00231 #define EMC_StaticConfig_PM ((uint32_t )(1 << 3)) /* StaticConfig register EMC: Page mode (PM) */ 00232 #define EMC_StaticConfig_PC ((uint32_t )(1 << 6)) /* StaticConfig register EMC: Chip select polarity (PC) */ 00233 #define EMC_StaticConfig_PB ((uint32_t )(1 << 7)) /* StaticConfig register EMC: Byte lane state (PB) */ 00234 #define EMC_StaticConfig_EW ((uint32_t )(1 << 8)) /* StaticConfig register EMC: Extended wait (EW) */ 00235 #define EMC_StaticConfig_B ((uint32_t )(1 << 19)) /* StaticConfig register EMC: Buffer enable (B) */ 00236 #define EMC_StaticConfig_P ((uint32_t )(1 << 20)) /* StaticConfig register EMC: Write protect (P) */ 00237 00238 00239 /*----------------------------------------------------------------------------* 00240 Static Memory Write Enable Delay registers (EMCStaticWaitWen0-3) 00241 *----------------------------------------------------------------------------*/ 00242 00243 #define EMC_StaticWaitWen_WAITWEN(n) ((uint32_t )(n & 0x0f)) /* StaticWaitWen register EMC: Wait write enable (WAITWEN). */ 00244 00245 00246 /*----------------------------------------------------------------------------* 00247 Static Memory Output Enable Delay registers (EMCStaticWaitOen0-3) 00248 *----------------------------------------------------------------------------*/ 00249 00250 #define EMC_StaticWaitOen_WAITOEN(n) ((uint32_t )(n & 0x0f)) /* StaticWaitOen register EMC: Wait output enable (WAITOEN). */ 00251 00252 00253 /*----------------------------------------------------------------------------* 00254 Static Memory Read Delay registers (EMCStaticWaitRd0-3) 00255 *----------------------------------------------------------------------------*/ 00256 00257 #define EMC_StaticWaitRd_WAITRD(n) ((uint32_t )(n & 0x1f)) /* StaticWaitRd register EMC: Non-page mode read wait 00258 states or asynchronous page mode read first access 00259 wait state (WAITRD) */ 00260 00261 00262 00263 /*----------------------------------------------------------------------------* 00264 Static Memory Page Mode Read Delay registers (EMCStaticwaitPage0-3) 00265 *----------------------------------------------------------------------------*/ 00266 00267 #define EMC_StaticwaitPage_WAITPAGE(n) ((uint32_t )(n & 0x1f)) /* StaticwaitPage register EMC: Asynchronous page mode 00268 read after the first read wait states (WAITPAGE). */ 00269 00270 00271 /*----------------------------------------------------------------------------* 00272 Static Memory Write Delay registers (EMCStaticWaitwr0-3) 00273 *----------------------------------------------------------------------------*/ 00274 00275 #define EMC_StaticWaitwr_WAITWR(n) ((uint32_t )(n & 0x1f)) /* StaticWaitwr register EMC: Write wait states (WAITWR). */ 00276 00277 00278 /*----------------------------------------------------------------------------* 00279 Static Memory Turn Round Delay registers (EMCStaticWaitTurn0-3) 00280 *----------------------------------------------------------------------------*/ 00281 00282 #define EMC_StaticWaitTurn_WAITTURN(n) ((uint32_t )(n & 0x0f)) /* StaticWaitTurn register EMC: Bus turnaround cycles (WAITTURN). */ 00283 00284 00285 /*----------------------------------------------------------------------------* 00286 Delay Control register (EMCDLYCTL) 00287 *----------------------------------------------------------------------------*/ 00288 00289 #define EMC_DLYCTL_CMDDLY(n) ((uint32_t)(n&0x1F)) 00290 #define EMC_DLYCTL_FBCLKDLY(n) ((uint32_t)((n&0x1F)<<8)) 00291 #define EMC_DLYCTL_CLKOUT0DLY(n) ((uint32_t)((n&0x1F)<<16)) 00292 #define EMC_DLYCTL_CLKOUT1DLY(n) ((uint32_t)((n&0x1F)<<24)) 00293 00294 00295 /*----------------------------------------------------------------------------* 00296 EMC Calibration register (EMCCAL) 00297 *----------------------------------------------------------------------------*/ 00298 00299 #define EMC_CAL_CALVALUE(n) ((uint32_t)(n&0xFF)) 00300 #define EMC_CAL_START ((uint32_t)(1<<14)) 00301 #define EMC_CAL_DONE ((uint32_t)(1<<15)) 00302 00303 00304 /*----------------------------------------------------------------------------* 00305 EMC endianess modes 00306 *----------------------------------------------------------------------------*/ 00307 00308 #define EMC_LITTLE_ENDIAN_MODE ((uint32_t)(0)) 00309 #define EMC_BIG_ENDIAN_MODE ((uint32_t)(1)) 00310 00311 00312 /*----------------------------------------------------------------------------* 00313 EMC dynamic memory registers enum 00314 *----------------------------------------------------------------------------*/ 00315 00316 typedef enum 00317 { 00318 EMC_DYN_MEM_REFRESH_TIMER, 00319 EMC_DYN_MEM_READ_CONFIG, 00320 EMC_DYN_MEM_TRP, 00321 EMC_DYN_MEM_TRAS, 00322 EMC_DYN_MEM_TSREX, 00323 EMC_DYN_MEM_TAPR, 00324 EMC_DYN_MEM_TDAL, 00325 EMC_DYN_MEM_TWR, 00326 EMC_DYN_MEM_TRC, 00327 EMC_DYN_MEM_TRFC, 00328 EMC_DYN_MEM_TXSR, 00329 EMC_DYN_MEM_TRRD, 00330 EMC_DYN_MEM_TMRD 00331 } EMC_DYN_MEM_PAR; 00332 00333 00334 /*----------------------------------------------------------------------------* 00335 EMC static memory registers enum 00336 *----------------------------------------------------------------------------*/ 00337 00338 typedef enum 00339 { 00340 EMC_STA_MEM_WAITWEN, 00341 EMC_STA_MEM_WAITOEN, 00342 EMC_STA_MEM_WAITRD, 00343 EMC_STA_MEM_WAITPAGE, 00344 EMC_STA_MEM_WAITWR, 00345 EMC_STA_MEM_WAITTURN, 00346 } EMC_STA_MEM_PAR; 00347 00348 00349 /*----------------------------------------------------------------------------* 00350 Public functions 00351 *----------------------------------------------------------------------------*/ 00352 00353 extern void Lpc177x_8x_EmcInit(void); 00354 extern void Lpc177x_8x_EmcSDRAMAdjustTiming(void); 00355 extern int Lpc177x_8x_EmcSDRAMCheck(SDRAM sdram, uint32_t offset); 00356 extern void Lpc177x_8x_EmcSDRAMInit(SDRAM sdram, uint32_t dynamic_config); 00357 extern void Lpc177x_8x_EmcConfigEndianMode(uint32_t endian_mode); 00358 extern void Lpc177x_8x_EmcDynCtrlClockEnable(uint32_t clock_enable); 00359 extern void Lpc177x_8x_EmcDynCtrlClockControl(uint32_t clock_control); 00360 extern void Lpc177x_8x_EmcDynCtrlSelfRefresh(uint32_t self_refresh_mode); 00361 extern void Lpc177x_8x_EmcDynCtrlMMC(uint32_t mmc_val); 00362 extern void Lpc177x_8x_EmcDynCtrlSDRAMCmd(uint32_t sdram_command); 00363 extern void Lpc177x_8x_EmcDynCtrlPowerDownMode(uint32_t power_command); 00364 extern void Lpc177x_8x_EmcSetDynMemoryParameter(EMC_DYN_MEM_PAR par, uint32_t val); 00365 extern void Lpc177x_8x_EmcStaticExtendedWait(uint32_t Extended_wait_time_out); 00366 extern void Lpc177x_8x_EmcDynMemConfigMD(uint32_t cs, uint32_t mem_dev); 00367 extern void Lpc177x_8x_EmcDynMemConfigAM(uint32_t cs, uint32_t addr_mapped); 00368 extern void Lpc177x_8x_EmcDynMemConfigB(uint32_t cs, uint32_t buff_control); 00369 extern void Lpc177x_8x_EmcDynMemConfigP(uint32_t cs, uint32_t permission); 00370 extern void Lpc177x_8x_EmcDynMemRAS(uint32_t cs, uint32_t ras_val); 00371 extern void Lpc177x_8x_EmcDynMemCAS(uint32_t cs, uint32_t cas_val); 00372 extern void Lpc177x_8x_EmcStaticMemConfigMW(uint32_t cs, uint32_t mem_width); 00373 extern void Lpc177x_8x_EmcStaticMemConfigPM(uint32_t cs, uint32_t page_mode); 00374 extern void Lpc177x_8x_EmcStaticMemConfigPC(uint32_t cs, uint32_t polarity); 00375 extern void Lpc177x_8x_EmcStaticMemConfigPB(uint32_t cs, uint32_t pb_val); 00376 extern void Lpc177x_8x_EmcStaticMemConfigEW(uint32_t cs, uint32_t ex_wait); 00377 extern void Lpc177x_8x_EmcStaticMemConfigB(uint32_t cs, uint32_t buf_val); 00378 extern void Lpc177x_8x_EmcStaticMemConfigP(uint32_t cs, uint32_t permission); 00379 extern void Lpc177x_8x_EmcSetStaticMemoryParameter(uint32_t cs, EMC_STA_MEM_PAR par, uint32_t val); 00380 00381 #endif /* _LPC177X_8X_EMC_H_ */ 00382 00383 00384 00385