lpc177x_8x_emc.c 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757
  1. /**********************************************************************
  2. * $Id$ lpc177x_8x_emc.c 2011-06-02
  3. *//**
  4. * @file lpc177x_8x_emc.c
  5. * @brief Contains all functions support for EMC firmware library
  6. * 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. #include "lpc177x_8x_emc.h"
  27. #include "lpc177x_8x_clkpwr.h"
  28. #include "lpc177x_8x_pinsel.h"
  29. /*********************************************************************//**
  30. * @brief EMC initialize
  31. * @param[in] None
  32. * @return None
  33. **********************************************************************/
  34. void EMC_Init(void)
  35. {
  36. uint8_t i;
  37. /* Enable clock for EMC */
  38. // CLKPWR_ConfigPPWR(CLKPWR_PCONP_PCEMC, ENABLE);
  39. // LPC_EMC->Control = 0x00000001;
  40. // LPC_EMC->Config = 0x00000000;
  41. LPC_SC->PCONP |= 0x00000800;
  42. LPC_SC->EMCDLYCTL = 0x00001010;
  43. LPC_EMC->Control = 0x00000001;
  44. LPC_EMC->Config = 0x00000000;
  45. /* Pin configuration:
  46. * P2.14 - /EMC_CS2
  47. * P2.15 - /EMC_CS3
  48. *
  49. * P2.16 - /EMC_CAS
  50. * P2.17 - /EMC_RAS
  51. * P2.18 - EMC_CLK[0]
  52. * P2.19 - EMC_CLK[1]
  53. *
  54. * P2.20 - EMC_DYCS0
  55. * P2.22 - EMC_DYCS1
  56. * P2.22 - EMC_DYCS2
  57. * P2.23 - EMC_DYCS3
  58. *
  59. * P2.24 - EMC_CKE0
  60. * P2.25 - EMC_CKE1
  61. * P2.26 - EMC_CKE2
  62. * P2.27 - EMC_CKE3
  63. *
  64. * P2.28 - EMC_DQM0
  65. * P2.29 - EMC_DQM1
  66. * P2.30 - EMC_DQM2
  67. * P2.31 - EMC_DQM3
  68. *
  69. * P3.0-P3.31 - EMC_D[0-31]
  70. * P4.0-P4.23 - EMC_A[0-23]
  71. *
  72. * P4.24 - /EMC_OE
  73. * P4.25 - /EMC_WE
  74. *
  75. * P4.30 - /EMC_CS0
  76. * P4.31 - /EMC_CS1
  77. */
  78. PINSEL_ConfigPin(2,14,1);
  79. PINSEL_ConfigPin(2,15,1);
  80. PINSEL_ConfigPin(2,16,1);
  81. PINSEL_ConfigPin(2,17,1);
  82. PINSEL_ConfigPin(2,18,1);
  83. PINSEL_ConfigPin(2,19,1);
  84. PINSEL_ConfigPin(2,20,1);
  85. PINSEL_ConfigPin(2,21,1);
  86. PINSEL_ConfigPin(2,22,1);
  87. PINSEL_ConfigPin(2,23,1);
  88. PINSEL_ConfigPin(2,24,1);
  89. PINSEL_ConfigPin(2,25,1);
  90. PINSEL_ConfigPin(2,26,1);
  91. PINSEL_ConfigPin(2,27,1);
  92. PINSEL_ConfigPin(2,28,1);
  93. PINSEL_ConfigPin(2,29,1);
  94. PINSEL_ConfigPin(2,30,1);
  95. PINSEL_ConfigPin(2,31,1);
  96. PINSEL_ConfigPin(5,0,1);
  97. PINSEL_ConfigPin(5,1,1);
  98. for(i = 0; i < 32; i++)
  99. {
  100. PINSEL_ConfigPin(3,i,1);
  101. PINSEL_ConfigPin(4,i,1);
  102. }
  103. }
  104. /*********************************************************************//**
  105. * @brief Configure Little Endian/Big Endian mode for EMC
  106. * @param[in] endia_mode Endian mode, should be:
  107. * - EMC_LITTLE_ENDIAN_MODE: Little-endian mode
  108. * - EMC_BIG_ENDIAN_MODE : Big-endian mode
  109. * @return None
  110. **********************************************************************/
  111. void EMC_ConfigEndianMode(uint32_t endian_mode)
  112. {
  113. LPC_EMC->Config = ((LPC_EMC->Config & 0x01)|endian_mode) & EMC_Config_MASK;
  114. }
  115. /****************** Group of Dynamic control functions************************/
  116. /*********************************************************************//**
  117. * @brief Set the value for dynamic clock enable bit
  118. * @param[in] clock_enable clock enable mode, should be:
  119. * - 0: Clock enable of idle devices are deasserted to
  120. * save power
  121. * - 1: All clock enables are driven HIGH continuously
  122. * @return None
  123. **********************************************************************/
  124. void EMC_DynCtrlClockEnable(uint32_t clock_enable)
  125. {
  126. LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl) |clock_enable);
  127. }
  128. /*********************************************************************//**
  129. * @brief Set the value for dynamic memory clock control:
  130. * stops or runs continuously
  131. * @param[in] clock_control clock control mode, should be:
  132. * - 0: CLKOUT stops when all SDRAMs are idle and
  133. * during self-refresh mode
  134. * - 1: CLKOUT runs continuously
  135. * @return None
  136. **********************************************************************/
  137. void EMC_DynCtrlClockControl(int32_t clock_control)
  138. {
  139. uint32_t mask = ~(uint32_t)(2);
  140. LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl & mask) |clock_control);
  141. }
  142. /*********************************************************************//**
  143. * @brief Switch the Self-refresh mode between normal and self-refresh mode
  144. * @param[in] self_refresh_mode self refresh mode, should be:
  145. * - 0: Normal mode
  146. * - 1: Enter self-refresh mode
  147. * @return None
  148. **********************************************************************/
  149. void EMC_DynCtrlSelfRefresh(uint32_t self_refresh_mode)
  150. {
  151. uint32_t mask = ~(uint32_t)(4);
  152. LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl & mask) |self_refresh_mode);
  153. }
  154. /*********************************************************************//**
  155. * @brief Enable/disable CLKOUT
  156. * @param[in] MMC_val Memory clock control mode, should be:
  157. * - 0: CLKOUT enabled
  158. * - 1: CLKOUT disabled
  159. * @return None
  160. **********************************************************************/
  161. void EMC_DynCtrlMMC(uint32_t MMC_val)
  162. {
  163. uint32_t mask = ~(uint32_t)(_BIT(5));
  164. LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl & mask) |MMC_val);
  165. }
  166. /*********************************************************************//**
  167. * @brief Issue SDRAM command
  168. * @param[in] SDRAM_command Command mode, should be:
  169. * - 0x00: Issue SDRAM NORMAL operation command
  170. * - 0x01: Issue SDRAM MODE command
  171. * - 0x02: Issue SDRAM PALL (precharge all) command
  172. * - 0x03: Issue SRAM NOP (no operation) command
  173. * @return None
  174. **********************************************************************/
  175. void EMC_DynCtrlSDRAMInit(uint32_t SDRAM_command)
  176. {
  177. uint32_t mask = ~(uint32_t)(_SBF(7,0x03));
  178. LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl & mask)|SDRAM_command);
  179. }
  180. /*********************************************************************//**
  181. * @brief Switch between Normal operation and deep sleep power mode
  182. * @param[in] Power_command Low-power SDRAM deep-sleep mode, should be:
  183. * - 0: Normal operation
  184. * - 1: Enter deep-sleep mode
  185. * @return None
  186. **********************************************************************/
  187. void EMC_DynCtrlPowerDownMode(uint32_t Power_command)
  188. {
  189. uint32_t mask = ~(uint32_t)(_BIT(13));
  190. LPC_EMC->DynamicControl = ((LPC_EMC->DynamicControl & mask)|Power_command);
  191. }
  192. /*********************************************************************//**
  193. * @brief Set the value of EMC dynamic memory registers
  194. * @param[in] par EMC register that will set value, should be:
  195. * - EMC_DYN_MEM_REFRESH_TIMER: Dynamic Refresh register
  196. * - EMC_DYN_MEM_READ_CONFIG: Dynamic Read Config register
  197. * - EMC_DYN_MEM_TRP: Dynamic RP register
  198. * - EMC_DYN_MEM_TRAS: Dynamic RAS register
  199. * - EMC_DYN_MEM_TSREX: Dynamic SREX register
  200. * - EMC_DYN_MEM_TAPR: Dynamic APR register
  201. * - EMC_DYN_MEM_TDAL: Dynamic DAL register
  202. * - EMC_DYN_MEM_TWR: Dynamic WR register
  203. * - EMC_DYN_MEM_TRC: Dynamic RC register
  204. * - EMC_DYN_MEM_TRFC: Dynamic RFC register
  205. * - EMC_DYN_MEM_TXSR: Dynamic XSR register
  206. * - EMC_DYN_MEM_TRRD: Dynamic RRD register
  207. * - EMC_DYN_MEM_TMRD: Dynamic MRD register
  208. * @return None
  209. **********************************************************************/
  210. void EMC_SetDynMemoryParameter(EMC_DYN_MEM_PAR par, uint32_t val)
  211. {
  212. switch ( par)
  213. {
  214. case EMC_DYN_MEM_REFRESH_TIMER:
  215. LPC_EMC->DynamicRefresh = val;
  216. break;
  217. case EMC_DYN_MEM_READ_CONFIG:
  218. LPC_EMC->DynamicReadConfig = val;
  219. break;
  220. case EMC_DYN_MEM_TRP:
  221. LPC_EMC->DynamicRP = val;
  222. break;
  223. case EMC_DYN_MEM_TRAS:
  224. LPC_EMC->DynamicRAS = val;
  225. break;
  226. case EMC_DYN_MEM_TSREX:
  227. LPC_EMC->DynamicSREX = val;
  228. break;
  229. case EMC_DYN_MEM_TAPR:
  230. LPC_EMC->DynamicAPR = val;
  231. break;
  232. case EMC_DYN_MEM_TDAL:
  233. LPC_EMC->DynamicDAL = val;
  234. break;
  235. case EMC_DYN_MEM_TWR:
  236. LPC_EMC->DynamicWR = val;
  237. break;
  238. case EMC_DYN_MEM_TRC:
  239. LPC_EMC->DynamicRC = val;
  240. break;
  241. case EMC_DYN_MEM_TRFC:
  242. LPC_EMC->DynamicRFC = val;
  243. break;
  244. case EMC_DYN_MEM_TXSR:
  245. LPC_EMC->DynamicXSR = val;
  246. break;
  247. case EMC_DYN_MEM_TRRD:
  248. LPC_EMC->DynamicRRD = val;
  249. break;
  250. case EMC_DYN_MEM_TMRD:
  251. LPC_EMC->DynamicMRD = val;
  252. break;
  253. }
  254. }
  255. /*********************************************************************//**
  256. * @brief Set extended wait time out for accessing static memory
  257. * @param[in] Extended_wait_time_out timeout value that will be set
  258. * @return None
  259. **********************************************************************/
  260. void EMC_StaticExtendedWait(uint32_t Extended_wait_time_out)
  261. {
  262. LPC_EMC->StaticExtendedWait = Extended_wait_time_out;
  263. }
  264. /*********************************************************************//**
  265. * @brief Configure the memory device
  266. * @param[in] index index number, should be from 0 to 3
  267. * @param[in] mem_dev Memory device, should be:
  268. * - 0x00: SDRAM
  269. * - 0x01: Low-power SDRAM
  270. * - 0x02: Micron Syncflash
  271. * @return None
  272. **********************************************************************/
  273. void EMC_DynMemConfigMD(uint32_t index , uint32_t mem_dev)
  274. {
  275. uint32_t mask = ~(uint32_t)(_SBF(3, 0x03));
  276. switch ( index)
  277. {
  278. case 0:
  279. LPC_EMC->DynamicConfig0 = (LPC_EMC->DynamicConfig0 & mask) | mem_dev;
  280. break;
  281. case 1:
  282. LPC_EMC->DynamicConfig1 = (LPC_EMC->DynamicConfig1 & mask) | mem_dev;
  283. break;
  284. case 2:
  285. LPC_EMC->DynamicConfig2 =(LPC_EMC->DynamicConfig2 & mask) | mem_dev;
  286. break;
  287. case 3:
  288. LPC_EMC->DynamicConfig3 = (LPC_EMC->DynamicConfig3 & mask) | mem_dev;
  289. break;
  290. }
  291. }
  292. /*********************************************************************//**
  293. * @brief Map the address for the memory device
  294. * @param[in] index index number, should be from 0 to 3
  295. * @param[in] add_mapped address where the memory will be mapped
  296. * @return None
  297. **********************************************************************/
  298. void EMC_DynMemConfigAM(uint32_t index , uint32_t add_mapped)
  299. {
  300. uint32_t mask = ~(uint32_t)(_SBF(7, 0x3f)) | ~(uint32_t)(_BIT(14)) ;
  301. switch ( index)
  302. {
  303. case 0:
  304. LPC_EMC->DynamicConfig0 = ( LPC_EMC->DynamicConfig0 & mask) | add_mapped;
  305. break;
  306. case 1:
  307. LPC_EMC->DynamicConfig1 = (LPC_EMC->DynamicConfig1 & mask) | add_mapped;
  308. break;
  309. case 2:
  310. LPC_EMC->DynamicConfig2 = (LPC_EMC->DynamicConfig2 & mask) | add_mapped;
  311. break;
  312. case 3:
  313. LPC_EMC->DynamicConfig3 = (LPC_EMC->DynamicConfig3 & mask) | add_mapped;
  314. break;
  315. }
  316. }
  317. /*********************************************************************//**
  318. * @brief Enable/disable the buffer
  319. * @param[in] index index number, should be from 0 to 3
  320. * @param[in] buff_control buffer control mode, should be:
  321. * - ENABLE
  322. * - DISABLE
  323. * @return None
  324. **********************************************************************/
  325. void EMC_DynMemConfigB(uint32_t index , uint32_t buff_control)
  326. {
  327. uint32_t mask = ~(uint32_t)(_BIT(19)) ;
  328. switch ( index)
  329. {
  330. case 0:
  331. LPC_EMC->DynamicConfig0 = (LPC_EMC->DynamicConfig0 & mask) | buff_control;
  332. break;
  333. case 1:
  334. LPC_EMC->DynamicConfig1 = ( LPC_EMC->DynamicConfig1 & mask) | buff_control;
  335. break;
  336. case 2:
  337. LPC_EMC->DynamicConfig2 = (LPC_EMC->DynamicConfig2 & mask)| buff_control;
  338. break;
  339. case 3:
  340. LPC_EMC->DynamicConfig3 = (LPC_EMC->DynamicConfig3 & mask) | buff_control;
  341. break;
  342. }
  343. }
  344. /*********************************************************************//**
  345. * @brief Configure write permission: protect or not
  346. * @param[in] index index number, should be from 0 to 3
  347. * @param[in] permission permission mode, should be:
  348. * - ENABLE: protect
  349. * - DISABLE: not protect
  350. * @return None
  351. **********************************************************************/
  352. void EMC_DynMemConfigP(uint32_t index , uint32_t permission)
  353. {
  354. uint32_t mask = ~(uint32_t)(_BIT(20)) ;
  355. switch ( index)
  356. {
  357. case 0:
  358. LPC_EMC->DynamicConfig0 = (LPC_EMC->DynamicConfig0 & mask) | permission;
  359. break;
  360. case 1:
  361. LPC_EMC->DynamicConfig1 = (LPC_EMC->DynamicConfig1 & mask) | permission;
  362. break;
  363. case 2:
  364. LPC_EMC->DynamicConfig2 = ( LPC_EMC->DynamicConfig2 & mask) | permission;
  365. break;
  366. case 3:
  367. LPC_EMC->DynamicConfig3 = (LPC_EMC->DynamicConfig3 & mask) | permission;
  368. break;
  369. }
  370. }
  371. /*********************************************************************//**
  372. * @brief Set value for RAS latency
  373. * @param[in] index index number, should be from 0 to 3
  374. * @param[in] ras_val RAS value should be in range: 0..3
  375. * @return None
  376. **********************************************************************/
  377. void EMC_DynMemRAS(uint32_t index , uint32_t ras_val)
  378. {
  379. uint32_t mask = ~(uint32_t)(0x03) ;
  380. switch ( index)
  381. {
  382. case 0:
  383. LPC_EMC->DynamicRasCas0 = (LPC_EMC->DynamicRasCas0 & mask) | ras_val;
  384. break;
  385. case 1:
  386. LPC_EMC->DynamicRasCas1 = (LPC_EMC->DynamicRasCas1 & mask) | ras_val;
  387. break;
  388. case 2:
  389. LPC_EMC->DynamicRasCas2 = (LPC_EMC->DynamicRasCas2 & mask) | ras_val;
  390. break;
  391. case 3:
  392. LPC_EMC->DynamicRasCas3 = (LPC_EMC->DynamicRasCas3 & mask) | ras_val;
  393. break;
  394. }
  395. }
  396. /*********************************************************************//**
  397. * @brief Set value for CAS latency
  398. * @param[in] index index number, should be from 0 to 3
  399. * @param[in] ras_val CAS value should be in range: 0..3
  400. * @return None
  401. **********************************************************************/
  402. void EMC_DynMemCAS(uint32_t index , uint32_t cas_val)
  403. {
  404. uint32_t mask = ~(uint32_t)(_SBF(8, 0x03)) ;
  405. switch ( index)
  406. {
  407. case 0:
  408. LPC_EMC->DynamicRasCas0 = (LPC_EMC->DynamicRasCas0 & mask) | cas_val;
  409. break;
  410. case 1:
  411. LPC_EMC->DynamicRasCas1 = (LPC_EMC->DynamicRasCas1 & mask) | cas_val;
  412. break;
  413. case 2:
  414. LPC_EMC->DynamicRasCas2 = (LPC_EMC->DynamicRasCas2 & mask )| cas_val;
  415. break;
  416. case 3:
  417. LPC_EMC->DynamicRasCas3 = ( LPC_EMC->DynamicRasCas3 & mask) | cas_val;
  418. break;
  419. }
  420. }
  421. /*********************************************************************//**
  422. * @brief Configure the memory width
  423. * @param[in] index index number, should be from 0 to 3
  424. * @param[in] mem_width memory width, should be:
  425. * - 0x00: 8-bits
  426. * - 0x01: 16-bits
  427. * - 0x02: 32-bits
  428. * @return None
  429. **********************************************************************/
  430. void EMC_StaMemConfigMW(uint32_t index , uint32_t mem_width)
  431. {
  432. uint32_t mask = ~(uint32_t)(0x03) ;
  433. switch ( index)
  434. {
  435. case 0:
  436. LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | mem_width;
  437. break;
  438. case 1:
  439. LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask) | mem_width;
  440. break;
  441. case 2:
  442. LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask)| mem_width;
  443. break;
  444. case 3:
  445. LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask) | mem_width;
  446. break;
  447. }
  448. }
  449. /*********************************************************************//**
  450. * @brief Configure the page mode
  451. * @param[in] index index number, should be from 0 to 3
  452. * @param[in] page_mode page mode, should be:
  453. * - 0: disable
  454. * - 1: asynchronous page mode enable
  455. * @return None
  456. **********************************************************************/
  457. void EMC_StaMemConfigPM(uint32_t index , uint32_t page_mode)
  458. {
  459. uint32_t mask = ~(uint32_t)(_BIT(3)) ;
  460. switch ( index)
  461. {
  462. case 0:
  463. LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | page_mode;
  464. break;
  465. case 1:
  466. LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask) | page_mode;
  467. break;
  468. case 2:
  469. LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask)| page_mode;
  470. break;
  471. case 3:
  472. LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask)| page_mode;
  473. break;
  474. }
  475. }
  476. /*********************************************************************//**
  477. * @brief Configure the chip select polarity
  478. * @param[in] index index number, should be from 0 to 3
  479. * @param[in] pagepol_val_mode page mode, should be:
  480. * - 0: Active LOW ship select
  481. * - 1: Active HIGH chip select
  482. * @return None
  483. **********************************************************************/
  484. void EMC_StaMemConfigPC(uint32_t index , uint32_t pol_val)
  485. {
  486. uint32_t mask = ~(uint32_t)(_BIT(6)) ;
  487. switch ( index)
  488. {
  489. case 0:
  490. LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | pol_val;
  491. break;
  492. case 1:
  493. LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask)| pol_val;
  494. break;
  495. case 2:
  496. LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask) | pol_val;
  497. break;
  498. case 3:
  499. LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask) | pol_val;
  500. break;
  501. }
  502. }
  503. /*********************************************************************//**
  504. * @brief Configure the byte lane state
  505. * @param[in] index index number, should be from 0 to 3
  506. * @param[in] pb_val Byte lane state, should be:
  507. * - 0: For reads all bits in BLSn[3:0] are HIGH.
  508. * - 1: For reads all bits in BLSn[3:0] are LOW.
  509. * @return None
  510. **********************************************************************/
  511. void EMC_StaMemConfigPB(uint32_t index , uint32_t pb_val)
  512. {
  513. uint32_t mask = ~(uint32_t)(_BIT(7)) ;
  514. switch ( index)
  515. {
  516. case 0:
  517. LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask)| pb_val;
  518. break;
  519. case 1:
  520. LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask)| pb_val;
  521. break;
  522. case 2:
  523. LPC_EMC->StaticConfig2 =( LPC_EMC->StaticConfig2 & mask)| pb_val;
  524. break;
  525. case 3:
  526. LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask)| pb_val;
  527. break;
  528. }
  529. }
  530. /*********************************************************************//**
  531. * @brief Configure the extended wait value
  532. * @param[in] index index number, should be from 0 to 3
  533. * @param[in] ex_wait Extended wait mode, should be:
  534. * - 0: Extended wait disabled.
  535. * - 1: Extended wait enabled.
  536. * @return None
  537. **********************************************************************/
  538. void EMC_StaMemConfigEW(uint32_t index , uint32_t ex_wait)
  539. {
  540. uint32_t mask = ~(uint32_t)(_BIT(8)) ;
  541. switch ( index)
  542. {
  543. case 0:
  544. LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | ex_wait;
  545. break;
  546. case 1:
  547. LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask) | ex_wait;
  548. break;
  549. case 2:
  550. LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask) | ex_wait;
  551. break;
  552. case 3:
  553. LPC_EMC->StaticConfig3 =( LPC_EMC->StaticConfig3 & mask) | ex_wait;
  554. break;
  555. }
  556. }
  557. /*********************************************************************//**
  558. * @brief Configure the buffer enable value
  559. * @param[in] index index number, should be from 0 to 3
  560. * @param[in] buf_val Buffer mode, should be:
  561. * - 0: Buffer disabled.
  562. * - 1: Buffer enabled.
  563. * @return None
  564. **********************************************************************/
  565. void EMC_StaMemConfigB(uint32_t index , uint32_t buf_val)
  566. {
  567. uint32_t mask = ~(uint32_t)(_BIT(19)) ;
  568. switch ( index)
  569. {
  570. case 0:
  571. LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | buf_val;
  572. break;
  573. case 1:
  574. LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask) | buf_val;
  575. break;
  576. case 2:
  577. LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask) | buf_val;
  578. break;
  579. case 3:
  580. LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask) | buf_val;
  581. break;
  582. }
  583. }
  584. /*********************************************************************//**
  585. * @brief Configure the write permission
  586. * @param[in] index index number, should be from 0 to 3
  587. * @param[in] per_val Permission mode, should be:
  588. * - 0: Write not protected.
  589. * - 1: Write protected.
  590. * @return None
  591. **********************************************************************/
  592. void EMC_StaMemConfigpP(uint32_t index , uint32_t per_val)
  593. {
  594. uint32_t mask = ~(uint32_t)(_BIT(20)) ;
  595. switch ( index)
  596. {
  597. case 0:
  598. LPC_EMC->StaticConfig0 = (LPC_EMC->StaticConfig0 & mask) | per_val;
  599. break;
  600. case 1:
  601. LPC_EMC->StaticConfig1 = (LPC_EMC->StaticConfig1 & mask) | per_val;
  602. break;
  603. case 2:
  604. LPC_EMC->StaticConfig2 = (LPC_EMC->StaticConfig2 & mask) | per_val;
  605. break;
  606. case 3:
  607. LPC_EMC->StaticConfig3 = (LPC_EMC->StaticConfig3 & mask) | per_val;
  608. break;
  609. }
  610. }
  611. /*********************************************************************//**
  612. * @brief Set the value of LPC_EMC static memory registers
  613. * @param[in] index index number, should be from 0 to 3
  614. * @param[in] EMC_STA_MEM_PAR Static register, should be:
  615. * - EMC_STA_MEM_WAITWEN: StaticWaitWen0 register
  616. * - EMC_STA_MEM_WAITOEN: StaticWaitOen0 register
  617. * - EMC_STA_MEM_WAITRD: StaticWaitRd0 register
  618. * - EMC_STA_MEM_WAITPAGE: StaticWaitPage0 register
  619. * - EMC_STA_MEM_WAITWR: StaticWaitWr0 register
  620. * - EMC_STA_MEM_WAITTURN: StaticWaitTurn0 register
  621. * @return None
  622. **********************************************************************/
  623. void EMC_SetStaMemoryParameter(uint32_t index ,EMC_STA_MEM_PAR par, uint32_t val)
  624. {
  625. switch (index)
  626. {
  627. case 0:
  628. switch ( par)
  629. {
  630. case EMC_STA_MEM_WAITWEN:
  631. LPC_EMC->StaticWaitWen0 = val;
  632. break;
  633. case EMC_STA_MEM_WAITOEN:
  634. LPC_EMC->StaticWaitOen0 = val;
  635. break;
  636. case EMC_STA_MEM_WAITRD:
  637. LPC_EMC->StaticWaitRd0 = val;
  638. break;
  639. case EMC_STA_MEM_WAITPAGE:
  640. LPC_EMC->StaticWaitPage0 = val;
  641. break;
  642. case EMC_STA_MEM_WAITWR:
  643. LPC_EMC->StaticWaitWr0 = val;
  644. break;
  645. case EMC_STA_MEM_WAITTURN:
  646. LPC_EMC->StaticWaitTurn0 = val;
  647. break;
  648. }
  649. break;
  650. case 1:
  651. switch ( par)
  652. {
  653. case EMC_STA_MEM_WAITWEN:
  654. LPC_EMC->StaticWaitWen1 = val;
  655. break;
  656. case EMC_STA_MEM_WAITOEN:
  657. LPC_EMC->StaticWaitOen1 = val;
  658. break;
  659. case EMC_STA_MEM_WAITRD:
  660. LPC_EMC->StaticWaitRd1 = val;
  661. break;
  662. case EMC_STA_MEM_WAITPAGE:
  663. LPC_EMC->StaticWaitPage1 = val;
  664. break;
  665. case EMC_STA_MEM_WAITWR:
  666. LPC_EMC->StaticWaitWr1 = val;
  667. break;
  668. case EMC_STA_MEM_WAITTURN:
  669. LPC_EMC->StaticWaitTurn1 = val;
  670. break;
  671. }
  672. break;
  673. case 2:
  674. switch ( par)
  675. {
  676. case EMC_STA_MEM_WAITWEN:
  677. LPC_EMC->StaticWaitWen2 = val;
  678. break;
  679. case EMC_STA_MEM_WAITOEN:
  680. LPC_EMC->StaticWaitOen2 = val;
  681. break;
  682. case EMC_STA_MEM_WAITRD:
  683. LPC_EMC->StaticWaitRd2 = val;
  684. break;
  685. case EMC_STA_MEM_WAITPAGE:
  686. LPC_EMC->StaticWaitPage2 = val;
  687. break;
  688. case EMC_STA_MEM_WAITWR:
  689. LPC_EMC->StaticWaitWr2 = val;
  690. break;
  691. case EMC_STA_MEM_WAITTURN:
  692. LPC_EMC->StaticWaitTurn2 = val;
  693. break;
  694. }
  695. break;
  696. case 3:
  697. switch ( par)
  698. {
  699. case EMC_STA_MEM_WAITWEN:
  700. LPC_EMC->StaticWaitWen3 = val;
  701. break;
  702. case EMC_STA_MEM_WAITOEN:
  703. LPC_EMC->StaticWaitOen3 = val;
  704. break;
  705. case EMC_STA_MEM_WAITRD:
  706. LPC_EMC->StaticWaitRd3 = val;
  707. break;
  708. case EMC_STA_MEM_WAITPAGE:
  709. LPC_EMC->StaticWaitPage3 = val;
  710. break;
  711. case EMC_STA_MEM_WAITWR:
  712. LPC_EMC->StaticWaitWr3 = val;
  713. break;
  714. case EMC_STA_MEM_WAITTURN:
  715. LPC_EMC->StaticWaitTurn3 = val;
  716. break;
  717. }
  718. break;
  719. }
  720. }