elektor_ir1.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright 2010-2011 by egnite GmbH
  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/arm/board/eir1.c
  36. * \brief Elektor Internet Radio board initialization.
  37. *
  38. * \verbatim
  39. * $Id$
  40. * \endverbatim
  41. */
  42. #include <toolchain.h>
  43. /*!
  44. * \brief Delay loop.
  45. *
  46. * In this early stage of NutBoardInit() we have to roll our own delay
  47. * loop.
  48. *
  49. * \param Number of loops to execute. Each loop takes at least 150ns
  50. * on the EIR running at 48 MHz.
  51. */
  52. static void Delay(int n)
  53. {
  54. int l;
  55. for (l = 0; l < n; l++) {
  56. _NOP();
  57. }
  58. }
  59. /*!
  60. * \brief Early hardware initialization.
  61. */
  62. void NutBoardInit(void)
  63. {
  64. /*
  65. * Reset the NIC.
  66. *
  67. * The low active PW_RST line of the DM9000E is connected to PC17.
  68. * Unfortunately the datasheet does not specify the minimum active
  69. * time. It only tells us, that the NIC will be available 5us
  70. * after de-asserting PW_RST. We keep the line low for 75us and
  71. * add a delay of 75us after putting it high again. This seems
  72. * to work reliable.
  73. */
  74. outr(PIOC_PER, _BV(17));
  75. outr(PIOC_OER, _BV(17));
  76. outr(PIOC_CODR, _BV(17));
  77. Delay(50);
  78. outr(PIOC_SODR, _BV(17));
  79. Delay(50);
  80. /* Enable Ethernet controller chip select. */
  81. outr(PIOA_BSR, _BV(PA20_NCS2_B));
  82. outr(PIOA_PDR, _BV(PA20_NCS2_B));
  83. /* Enable external memory read, write and wait signals. */
  84. outr(PIOC_BSR, _BV(PC16_NWAIT_B) | _BV(PC21_NWR0_B) | _BV(PC22_NRD_B));
  85. outr(PIOC_PDR, _BV(PC16_NWAIT_B) | _BV(PC21_NWR0_B) | _BV(PC22_NRD_B));
  86. /* Configure Ethernet controller chip select. */
  87. outr(SMC_CSR(2)
  88. , (1 << SMC_NWS_LSB)
  89. | SMC_WSEN
  90. | (2 << SMC_TDF_LSB)
  91. | SMC_BAT
  92. | SMC_DBW_16
  93. | (1 << SMC_RWSETUP_LSB)
  94. | (1 << SMC_RWHOLD_LSB)
  95. );
  96. }