lisa.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * Copyright (C) 2012 by Ole Reinhardt (ole.reinhardt@embedded-it.de)
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. /*
  35. * \file arch/cm3/board/lisa.c
  36. * \brief Lisa board initialization.
  37. *
  38. *
  39. * \verbatim
  40. * $Id: $
  41. * \endverbatim
  42. */
  43. #include <arch/cm3.h>
  44. #include <inttypes.h>
  45. #include <sys/timer.h>
  46. #include <arch/cm3/nxp/lpc177x_8x_clk.h>
  47. #include <arch/cm3/nxp/lpc177x_8x_emc.h>
  48. #include <dev/gpio.h>
  49. #include <dev/sdram.h>
  50. #include <sys/heap.h>
  51. /* SDRAM configuration for Lisa board */
  52. /* configuration for IS42S16100E sdram. */
  53. #define SDRAM_BASE_ADDR 0xA0000000
  54. #define SDRAM_SIZE 0x00200000
  55. /* Samsung IS42S16100E SDRAMs */
  56. static SDRAM sdram_is42s16100e = {
  57. .base_addr = SDRAM_BASE_ADDR,
  58. .size = SDRAM_SIZE,
  59. .bus_width = 16,
  60. .rows = 11,
  61. .cols = 8,
  62. .ras_latency = 3,
  63. .cas_latency = 3,
  64. .tRP = 21,
  65. .tRAS = 42,
  66. .tSREX = 70, /* same as .tXSR */
  67. .tAPR = 1,
  68. .tDAL = 5,
  69. .tWR = 3,
  70. .tRC = 63,
  71. .tRFC = 66,
  72. .tXSR = 70,
  73. .tRRD = 15,
  74. .tMRD = 2,
  75. .refresh = 7000,
  76. // .refresh = 32000,
  77. };
  78. /*!
  79. * \brief Delay loop.
  80. *
  81. * We are running prior to Nut/OS timer initialization and cannot use
  82. * NutSleep, not even NutDelay.
  83. *
  84. * \param Number of loops to execute.
  85. */
  86. static void Lisa_Delay(int n)
  87. {
  88. int l;
  89. for (l = 0; l < n; l++) {
  90. _NOP();
  91. }
  92. }
  93. /*!
  94. * \brief Early LISA hardware initialization. Especialy SD-RAM
  95. *
  96. * This routine is called during system initalization.
  97. */
  98. void NutBoardInit(void)
  99. {
  100. int i;
  101. /* Configure SDRAM interface GPIO Pins */
  102. /* Pin configuration:
  103. * P2.14 - /EMC_CS2 - not used
  104. * P2.15 - /EMC_CS3 - not used
  105. *
  106. * P2.16 - /EMC_CAS
  107. * P2.17 - /EMC_RAS
  108. * P2.18 - EMC_CLK[0]
  109. * P2.19 - EMC_CLK[1] - not used
  110. *
  111. * P2.20 - EMC_DYCS0
  112. * P2.21 - EMC_DYCS1 - not used
  113. * P2.22 - EMC_DYCS2 - not used
  114. * P2.23 - EMC_DYCS3 - not used
  115. *
  116. * P2.24 - EMC_CKE0
  117. * P2.25 - EMC_CKE1 - not used
  118. * P2.26 - EMC_CKE2 - not used
  119. * P2.27 - EMC_CKE3 - not used
  120. *
  121. * P2.28 - EMC_DQM0
  122. * P2.29 - EMC_DQM1
  123. * P2.30 - EMC_DQM2 - not used
  124. * P2.31 - EMC_DQM3 - not used
  125. *
  126. * P3.0-P3.31 - EMC_D[0-31] - only D0 .. D15 used
  127. * P4.0-P4.23 - EMC_A[0-23] - only A0 .. A11 used
  128. *
  129. * P4.24 - /EMC_OE - not used
  130. * P4.25 - /EMC_WE
  131. *
  132. * P4.30 - /EMC_CS0 - not used
  133. * P4.31 - /EMC_CS1 - not used
  134. */
  135. GpioPinConfigSet(NUTGPIO_PORT2, 16, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  136. GpioPinConfigSet(NUTGPIO_PORT2, 17, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  137. GpioPinConfigSet(NUTGPIO_PORT2, 18, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  138. GpioPinConfigSet(NUTGPIO_PORT2, 20, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  139. GpioPinConfigSet(NUTGPIO_PORT2, 24, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  140. GpioPinConfigSet(NUTGPIO_PORT2, 28, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  141. GpioPinConfigSet(NUTGPIO_PORT2, 29, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  142. /* Configure D0 .. D15 */
  143. for(i = 0; i < 16; i++) {
  144. GpioPinConfigSet(NUTGPIO_PORT3, i, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL | GPIO_CFG_REPEATER);
  145. }
  146. /* Configure A0 .. A10 */
  147. for(i = 0; i < 11; i++) {
  148. GpioPinConfigSet(NUTGPIO_PORT4, i, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  149. }
  150. /* Configure A13 (bank select) */
  151. GpioPinConfigSet(NUTGPIO_PORT4, 13, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  152. GpioPinConfigSet(NUTGPIO_PORT4, 25, GPIO_CFG_PERIPHERAL1 | GPIO_CFG_SLEWCTRL);
  153. /* Initialize the external memory controller */
  154. Lpc177x_8x_EmcInit();
  155. Lpc177x_8x_EmcSDRAMInit(sdram_is42s16100e, 0x00001080 /* bank-row-column mode: 11 rows, 8 cols, 1Mx16, 16MBit */);
  156. /* Configure Ethernet PHY */
  157. /* Reset the PHY and configure the bootstrap pins using the pullup / pulldown resistors */
  158. GpioPinConfigSet(NUTGPIO_PORT1, 13, GPIO_CFG_OUTPUT); /* PHY Reset */
  159. GpioPinSetLow(NUTGPIO_PORT1, 13); /* Put PHY into reset */
  160. GpioPinConfigSet(NUTGPIO_PORT1, 9, GPIO_CFG_INPUT | GPIO_CFG_PULLUP | GPIO_CFG_PERIPHERAL0); /* MODE0 -- ETH_RXD0 */
  161. GpioPinConfigSet(NUTGPIO_PORT1, 10, GPIO_CFG_INPUT | GPIO_CFG_PULLUP | GPIO_CFG_PERIPHERAL0); /* MODE1 -- ETH_RXD1 */
  162. GpioPinConfigSet(NUTGPIO_PORT1, 8, GPIO_CFG_INPUT | GPIO_CFG_PULLUP | GPIO_CFG_PERIPHERAL0); /* MODE2 -- ETH_CRS */
  163. GpioPinConfigSet(NUTGPIO_PORT1, 14, GPIO_CFG_INPUT | GPIO_CFG_PULLDOWN | GPIO_CFG_PERIPHERAL0); /* PHY_AD0 -- ETH_RXER */
  164. Lisa_Delay(25000);
  165. GpioPinSetHigh(NUTGPIO_PORT1, 13); /* Put PHY into reset */
  166. Lisa_Delay(1000);
  167. }
  168. /*!
  169. * \brief Adjust the sdram timings to compensate temperature drifts
  170. *
  171. * This function is called as timer callback which was initialised at NutIdleInit()
  172. */
  173. static void adjust_sdram_timing(HANDLE this, void* arg)
  174. {
  175. Lpc177x_8x_EmcSDRAMAdjustTiming();
  176. }
  177. /*!
  178. * \brief Extended system initialisation. Add sdram memory to the available memory
  179. *
  180. * This routine is called during system initialisation right before the idle
  181. * thread is created. We will use it to add the SDRAM memory space to out heap.
  182. */
  183. void NutIdleInit(void)
  184. {
  185. /* Sanity check if the sdram is working. If all is fine add the sdram to
  186. heap space.
  187. */
  188. if (Lpc177x_8x_EmcSDRAMCheck(sdram_is42s16100e, 0xaa55) == 0) {
  189. NutHeapAdd((void*)sdram_is42s16100e.base_addr, sdram_is42s16100e.size);
  190. }
  191. /* Initialise a timer that re-calibrates the delay loops once a minute to
  192. compensate temperature drift of the sdram controller
  193. */
  194. NutTimerStart(60000, adjust_sdram_timing, NULL, 0);
  195. }