F2837xD_Emif.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. //###########################################################################
  2. //
  3. // FILE: F2837xD_Emif.c
  4. //
  5. // TITLE: F2837xD EMIF Initialization & Support Functions.
  6. //
  7. //###########################################################################
  8. // $TI Release: F2837xD Support Library v3.05.00.00 $
  9. // $Release Date: Tue Jun 26 03:15:23 CDT 2018 $
  10. // $Copyright:
  11. // Copyright (C) 2013-2018 Texas Instruments Incorporated - http://www.ti.com/
  12. //
  13. // Redistribution and use in source and binary forms, with or without
  14. // modification, are permitted provided that the following conditions
  15. // are met:
  16. //
  17. // Redistributions of source code must retain the above copyright
  18. // notice, this list of conditions and the following disclaimer.
  19. //
  20. // Redistributions in binary form must reproduce the above copyright
  21. // notice, this list of conditions and the following disclaimer in the
  22. // documentation and/or other materials provided with the
  23. // distribution.
  24. //
  25. // Neither the name of Texas Instruments Incorporated nor the names of
  26. // its contributors may be used to endorse or promote products derived
  27. // from this software without specific prior written permission.
  28. //
  29. // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. // $
  41. //###########################################################################
  42. //
  43. // Included Files
  44. //
  45. #include "F2837xD_device.h"
  46. #include "F2837xD_Examples.h"
  47. //
  48. // Emif1Initialize - This function initializes the EMIF1 to a known state.
  49. //
  50. void Emif1Initialize(void)
  51. {
  52. EALLOW;
  53. //
  54. // Perform a Module soft reset on EMIF
  55. //
  56. #ifdef CPU1
  57. DevCfgRegs.SOFTPRES1.all = 0x1;
  58. __asm (" nop");
  59. DevCfgRegs.SOFTPRES1.all = 0x0;
  60. #endif
  61. EDIS;
  62. }
  63. //
  64. // Emif2Initialize - This function initializes the EMIF2 to a known state.
  65. //
  66. void Emif2Initialize(void)
  67. {
  68. EALLOW;
  69. //
  70. // Perform a Module soft reset on EMIF
  71. //
  72. #ifdef CPU1
  73. DevCfgRegs.SOFTPRES1.all = 0x2;
  74. __asm (" nop");
  75. DevCfgRegs.SOFTPRES1.all = 0x0;
  76. #endif
  77. EDIS;
  78. }
  79. //
  80. // ASync_wait_config - Async wait configuration function
  81. //
  82. void ASync_wait_config(Uint16 inst, Uint16 wait_count, Uint16 wait_polarity)
  83. {
  84. if (inst == 0)
  85. {
  86. //
  87. // 7:0 Maximum Extended Wait cycles.
  88. //
  89. Emif1Regs.ASYNC_WCCR.bit.MAX_EXT_WAIT = wait_count;
  90. //
  91. // 28 Wait Polarity for pad_wait_i[0].
  92. //
  93. Emif1Regs.ASYNC_WCCR.bit.WP0 = wait_polarity;
  94. }
  95. else
  96. {
  97. //
  98. // 7:0 Maximum Extended Wait cycles.
  99. //
  100. Emif2Regs.ASYNC_WCCR.bit.MAX_EXT_WAIT = wait_count;
  101. //
  102. // 28 Wait Polarity for pad_wait_i[0].
  103. //
  104. Emif2Regs.ASYNC_WCCR.bit.WP0 = wait_polarity;
  105. }
  106. }
  107. //
  108. // ASync_cs2_config - Async CS2 Configuration
  109. //
  110. void ASync_cs2_config(Uint16 inst, Uint16 async_mem_data_width,
  111. Uint16 turn_around_time, Uint16 r_hold_time,
  112. Uint16 r_strobe_time, Uint16 r_setup, Uint16 w_hold,
  113. Uint16 w_strobe, Uint16 w_setup, Uint16 extend_wait,
  114. Uint16 strobe_sel)
  115. {
  116. if (inst == 0)
  117. {
  118. //
  119. // 1:0 Asynchronous Memory Size.
  120. // 3:2 Turn Around cycles.
  121. // 6:4 Read Strobe Hold cycles.
  122. // 12:7 Read Strobe Duration cycles.
  123. // 16:13 Read Strobe Setup cycles.
  124. // 19:17 Write Strobe Hold cycles.
  125. // 25:20 Write Strobe Duration cycles.
  126. // 29:26 Write Strobe Setup cycles.
  127. // 30 Extend Wait mode.
  128. // 31 Select Strobe mode.
  129. //
  130. Emif1Regs.ASYNC_CS2_CR.bit.ASIZE = async_mem_data_width;
  131. Emif1Regs.ASYNC_CS2_CR.bit.TA= turn_around_time;
  132. Emif1Regs.ASYNC_CS2_CR.bit.R_HOLD= r_hold_time;
  133. Emif1Regs.ASYNC_CS2_CR.bit.R_STROBE = r_strobe_time;
  134. Emif1Regs.ASYNC_CS2_CR.bit.R_SETUP = r_setup;
  135. Emif1Regs.ASYNC_CS2_CR.bit.W_HOLD = w_hold;
  136. Emif1Regs.ASYNC_CS2_CR.bit.W_STROBE = w_strobe;
  137. Emif1Regs.ASYNC_CS2_CR.bit.W_SETUP = w_setup;
  138. Emif1Regs.ASYNC_CS2_CR.bit.EW = extend_wait;
  139. Emif1Regs.ASYNC_CS2_CR.bit.SS = strobe_sel;
  140. }
  141. else
  142. {
  143. //
  144. // 1:0 Asynchronous Memory Size.
  145. // 3:2 Turn Around cycles.
  146. // 6:4 Read Strobe Hold cycles.
  147. // 12:7 Read Strobe Duration cycles.
  148. // 16:13 Read Strobe Setup cycles.
  149. // 19:17 Write Strobe Hold cycles.
  150. // 25:20 Write Strobe Duration cycles.
  151. // 29:26 Write Strobe Setup cycles.
  152. // 30 Extend Wait mode.
  153. // 31 Select Strobe mode.
  154. //
  155. Emif2Regs.ASYNC_CS2_CR.bit.ASIZE = async_mem_data_width;
  156. Emif2Regs.ASYNC_CS2_CR.bit.TA= turn_around_time;
  157. Emif2Regs.ASYNC_CS2_CR.bit.R_HOLD= r_hold_time;
  158. Emif2Regs.ASYNC_CS2_CR.bit.R_STROBE = r_strobe_time;
  159. Emif2Regs.ASYNC_CS2_CR.bit.R_SETUP = r_setup;
  160. Emif2Regs.ASYNC_CS2_CR.bit.W_HOLD = w_hold;
  161. Emif2Regs.ASYNC_CS2_CR.bit.W_STROBE = w_strobe;
  162. Emif2Regs.ASYNC_CS2_CR.bit.W_SETUP = w_setup;
  163. Emif2Regs.ASYNC_CS2_CR.bit.EW = extend_wait;
  164. Emif2Regs.ASYNC_CS2_CR.bit.SS = strobe_sel;
  165. }
  166. }
  167. //
  168. // ASync_cs3_config - Async CS3 Configuration
  169. //
  170. void ASync_cs3_config(Uint16 inst, Uint16 async_mem_data_width,
  171. Uint16 turn_around_time, Uint16 r_hold_time,
  172. Uint16 r_strobe_time, Uint16 r_setup, Uint16 w_hold,
  173. Uint16 w_strobe, Uint16 w_setup, Uint16 extend_wait,
  174. Uint16 strobe_sel)
  175. {
  176. //
  177. // 1:0 Asynchronous Memory Size.
  178. // 3:2 Turn Around cycles.
  179. // 6:4 Read Strobe Hold cycles.
  180. // 12:7 Read Strobe Duration cycles.
  181. // 16:13 Read Strobe Setup cycles.
  182. // 19:17 Write Strobe Hold cycles.
  183. // 25:20 Write Strobe Duration cycles.
  184. // 29:26 Write Strobe Setup cycles.
  185. // 30 Extend Wait mode.
  186. // 31 Select Strobe mode.
  187. //
  188. Emif1Regs.ASYNC_CS3_CR.bit.ASIZE = async_mem_data_width;
  189. Emif1Regs.ASYNC_CS3_CR.bit.TA= turn_around_time;
  190. Emif1Regs.ASYNC_CS3_CR.bit.R_HOLD= r_hold_time;
  191. Emif1Regs.ASYNC_CS3_CR.bit.R_STROBE = r_strobe_time;
  192. Emif1Regs.ASYNC_CS3_CR.bit.R_SETUP = r_setup;
  193. Emif1Regs.ASYNC_CS3_CR.bit.W_HOLD = w_hold;
  194. Emif1Regs.ASYNC_CS3_CR.bit.W_STROBE = w_strobe;
  195. Emif1Regs.ASYNC_CS3_CR.bit.W_SETUP = w_setup;
  196. Emif1Regs.ASYNC_CS3_CR.bit.EW = extend_wait;
  197. Emif1Regs.ASYNC_CS3_CR.bit.SS = strobe_sel;
  198. }
  199. //
  200. // ASync_cs4_config - Async CS4 Configuration
  201. //
  202. void ASync_cs4_config(Uint16 inst, Uint16 async_mem_data_width,
  203. Uint16 turn_around_time, Uint16 r_hold_time,
  204. Uint16 r_strobe_time, Uint16 r_setup, Uint16 w_hold,
  205. Uint16 w_strobe, Uint16 w_setup, Uint16 extend_wait,
  206. Uint16 strobe_sel)
  207. {
  208. //
  209. // 1:0 Asynchronous Memory Size.
  210. // 3:2 Turn Around cycles.
  211. // 6:4 Read Strobe Hold cycles.
  212. // 12:7 Read Strobe Duration cycles.
  213. // 16:13 Read Strobe Setup cycles.
  214. // 19:17 Write Strobe Hold cycles.
  215. // 25:20 Write Strobe Duration cycles.
  216. // 29:26 Write Strobe Setup cycles.
  217. // 30 Extend Wait mode.
  218. // 31 Select Strobe mode.
  219. //
  220. Emif1Regs.ASYNC_CS4_CR.bit.ASIZE = async_mem_data_width;
  221. Emif1Regs.ASYNC_CS4_CR.bit.TA= turn_around_time;
  222. Emif1Regs.ASYNC_CS4_CR.bit.R_HOLD= r_hold_time;
  223. Emif1Regs.ASYNC_CS4_CR.bit.R_STROBE = r_strobe_time;
  224. Emif1Regs.ASYNC_CS4_CR.bit.R_SETUP = r_setup;
  225. Emif1Regs.ASYNC_CS4_CR.bit.W_HOLD = w_hold;
  226. Emif1Regs.ASYNC_CS4_CR.bit.W_STROBE = w_strobe;
  227. Emif1Regs.ASYNC_CS4_CR.bit.W_SETUP = w_setup;
  228. Emif1Regs.ASYNC_CS4_CR.bit.EW = extend_wait;
  229. Emif1Regs.ASYNC_CS4_CR.bit.SS = strobe_sel;
  230. }
  231. #ifdef CPU1
  232. //
  233. // setup_emif1_pinmux_async_16bit - function for EMIF1 GPIO pin setup
  234. //
  235. void setup_emif1_pinmux_async_16bit(Uint16 cpu_sel)
  236. {
  237. Uint16 i;
  238. for (i=28; i<=52; i++)
  239. {
  240. if ((i != 42) && (i != 43))
  241. {
  242. GPIO_SetupPinMux(i,cpu_sel,2);
  243. }
  244. }
  245. for (i=63; i<=87; i++)
  246. {
  247. if (i != 84)
  248. {
  249. GPIO_SetupPinMux(i,cpu_sel,2);
  250. }
  251. }
  252. GPIO_SetupPinMux(88,cpu_sel,3);
  253. GPIO_SetupPinMux(89,cpu_sel,3);
  254. GPIO_SetupPinMux(90,cpu_sel,3);
  255. GPIO_SetupPinMux(91,cpu_sel,3);
  256. GPIO_SetupPinMux(92,cpu_sel,3);
  257. GPIO_SetupPinMux(93,cpu_sel,3);
  258. GPIO_SetupPinMux(94,cpu_sel,2);
  259. //
  260. //setup async mode and enable pull-ups for Data pins
  261. //
  262. for (i=69; i<=85; i++)
  263. {
  264. if (i != 84)
  265. {
  266. GPIO_SetupPinOptions(i,0,0x31); // GPIO_ASYNC||GPIO_PULLUP
  267. }
  268. }
  269. }
  270. //
  271. // setup_emif1_pinmux_async_32bit - Setup pinmux for 32bit async
  272. //
  273. void setup_emif1_pinmux_async_32bit(Uint16 cpu_sel)
  274. {
  275. Uint16 i;
  276. for (i=28; i<=87; i++)
  277. {
  278. if ((i != 42) && (i != 43) && (i != 84))
  279. {
  280. GPIO_SetupPinMux(i,cpu_sel,2);
  281. }
  282. }
  283. GPIO_SetupPinMux(88,cpu_sel,3);
  284. GPIO_SetupPinMux(89,cpu_sel,3);
  285. GPIO_SetupPinMux(90,cpu_sel,3);
  286. GPIO_SetupPinMux(91,cpu_sel,3);
  287. GPIO_SetupPinMux(92,cpu_sel,3);
  288. GPIO_SetupPinMux(93,cpu_sel,3);
  289. GPIO_SetupPinMux(94,cpu_sel,2);
  290. //
  291. //setup async mode for Data pins
  292. //
  293. for (i=53; i<=85; i++)
  294. {
  295. if (i != 84)
  296. {
  297. GPIO_SetupPinOptions(i,0,0x31);
  298. }
  299. }
  300. }
  301. //
  302. // setup_emif2_pinmux_async_16bit - function for EMIF1 GPIO pin setup
  303. //
  304. void setup_emif2_pinmux_async_16bit(Uint16 cpu_sel)
  305. {
  306. Uint16 i;
  307. for (i=96; i<=121; i++)
  308. {
  309. GPIO_SetupPinMux(i,cpu_sel,3);
  310. }
  311. for (i=53; i<=68; i++)
  312. {
  313. GPIO_SetupPinMux(i,cpu_sel,3);
  314. }
  315. //
  316. //setup async mode for Data pins
  317. //
  318. for (i=53; i<=68; i++)
  319. {
  320. GPIO_SetupPinOptions(i,0,0x31);
  321. }
  322. }
  323. //
  324. // setup_emif1_pinmux_sdram_16bit - Setup pinmux for 16bit SDRAM
  325. //
  326. void setup_emif1_pinmux_sdram_16bit(Uint16 cpu_sel)
  327. {
  328. int i;
  329. for (i=29; i<=52; i++)
  330. {
  331. if ((i != 42) && (i != 43))
  332. {
  333. GPIO_SetupPinMux(i,cpu_sel,2);
  334. }
  335. }
  336. for (i=69; i<=85; i++)
  337. {
  338. if (i != 84)
  339. {
  340. GPIO_SetupPinMux(i,cpu_sel,2);
  341. }
  342. }
  343. for(i=86; i<=93; i++)
  344. {
  345. GPIO_SetupPinMux(i,cpu_sel,3);
  346. }
  347. //
  348. //configure Data pins for Async mode
  349. //
  350. for (i = 69; i <= 85; i++)
  351. {
  352. if (i != 84)
  353. {
  354. GPIO_SetupPinOptions(i,0,0x31);
  355. }
  356. }
  357. GPIO_SetupPinOptions(88,0,0x31);
  358. GPIO_SetupPinOptions(89,0,0x31);
  359. GPIO_SetupPinOptions(90,0,0x31);
  360. GPIO_SetupPinOptions(91,0,0x31);
  361. }
  362. //
  363. // setup_emif2_pinmux_sdram_16bit - Setup pinmux for 16bit SDRAM
  364. //
  365. void setup_emif2_pinmux_sdram_16bit(Uint16 cpu_sel)
  366. {
  367. int i;
  368. for (i=53; i<=68; i++)
  369. {
  370. GPIO_SetupPinMux(i,cpu_sel,3);
  371. }
  372. for (i=96; i<=121; i++)
  373. {
  374. GPIO_SetupPinMux(i,cpu_sel,3);
  375. }
  376. //
  377. //configure Data pins for Async mode
  378. //
  379. for (i = 53; i <= 68; i++)
  380. {
  381. GPIO_SetupPinOptions(i,0,0x31);
  382. }
  383. }
  384. //
  385. // setup_emif1_pinmux_sdram_32bit - Setup pinmux for 32bit SDRAM
  386. //
  387. void setup_emif1_pinmux_sdram_32bit(Uint16 cpu_sel)
  388. {
  389. int i;
  390. for (i=28; i<=85; i++)
  391. {
  392. if ((i != 42) && (i != 43) && (i != 84))
  393. {
  394. GPIO_SetupPinMux(i,cpu_sel,2);
  395. }
  396. }
  397. for(i=86; i<=93; i++)
  398. {
  399. GPIO_SetupPinMux(i,cpu_sel,3);
  400. }
  401. GPIO_SetupPinMux(94,cpu_sel,2);
  402. //
  403. //configure Data pins for Async mode
  404. //
  405. for (i = 53; i <= 85; i++)
  406. {
  407. if (i != 84)
  408. {
  409. GPIO_SetupPinOptions(i,0,0x31);
  410. }
  411. }
  412. GPIO_SetupPinOptions(88,0,0x31);
  413. GPIO_SetupPinOptions(89,0,0x31);
  414. GPIO_SetupPinOptions(90,0,0x31);
  415. GPIO_SetupPinOptions(91,0,0x31);
  416. }
  417. #endif // CPU1
  418. //
  419. // End of file
  420. //