flecx1.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright 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/cm3/board/flecx1.c
  36. * \brief FLECX 1 board initialization.
  37. *
  38. * \verbatim
  39. * $Id$
  40. * \endverbatim
  41. */
  42. #include <arch/cm3.h>
  43. /********** TODO: Clock setup is done in arch/cm3/dev/nxp/lpc176x_clk.c
  44. Correct config values should be made configurable in the
  45. configurator... Left this code as reference...
  46. eventually pin setup has to be integrated here later
  47. */
  48. __attribute__ ((section(".crp"))) const uint32_t CRP_WORD = 0xFFFFFFFF;
  49. /*!
  50. * \brief Early hardware initialization for FLECX 1 board.
  51. *
  52. * This routine is called during system initialization, if NUT_INIT_BOARD
  53. * has been enabled in the architecture configuration.
  54. *
  55. * It will mainly set up the basic clocks for the CPU to run at 99.6MHz.
  56. */
  57. void NutBoardInit(void)
  58. {
  59. #if 0
  60. /* Set flash for 100MHz CPU. */
  61. outr(SC_FLASHCFG, (inr(SC_FLASHCFG) & ~SC_FLASHTIM) | (5 << SC_FLASHTIM_LSB));
  62. /* Divide all peripheral clocks by 4. */
  63. outr(SC_PCLKSEL0, 0);
  64. outr(SC_PCLKSEL1, 0);
  65. /* Enable main oscillator. */
  66. outr(SC_SCS, SC_OSCEN);
  67. while ((inr(SC_SCS) & SC_OSCSTAT) == 0);
  68. /* Set CPU clock divider to 4. */
  69. outr(SC_CCLKCFG, (4 - 1) << SC_CCLKSEL_LSB);
  70. /* Select main clock as clock source for PLL0. */
  71. outr(SC_CLKSRCSEL, SC_CLKSRC_MCLK);
  72. /* Configure PLL0 divider and multiplier to 99.6 MHz. */
  73. outr(SC_PLL0CFG, ((5 - 1) << SC_NSEL_LSB) | ((83 - 1) << SC_MSEL_LSB));
  74. outr(SC_PLL0FEED, PLLFEED_FEED1);
  75. outr(SC_PLL0FEED, PLLFEED_FEED2);
  76. /* Enable PLL0. */
  77. outr(SC_PLL0CON, SC_PLLE);
  78. outr(SC_PLL0FEED, PLLFEED_FEED1);
  79. outr(SC_PLL0FEED, PLLFEED_FEED2);
  80. /* Wait for PLL0 locked. */
  81. while ((inr(SC_PLL0STAT) & SC_PLOCK) == 0);
  82. /* Enable and connect PLL0. */
  83. outr(SC_PLL0CON, SC_PLLE | SC_PLLC);
  84. outr(SC_PLL0FEED, PLLFEED_FEED1);
  85. outr(SC_PLL0FEED, PLLFEED_FEED2);
  86. /* Wait for PLL0 ready. */
  87. while ((inr(SC_PLL0STAT) & (SC_PLLE_STAT | SC_PLLC_STAT)) != (SC_PLLE_STAT | SC_PLLC_STAT));
  88. /* Enable peripheral clocks. */
  89. outr(SC_PCONP,
  90. SC_PCTIM0 | SC_PCTIM1 | SC_PCUART0 | SC_PCPWM1 |
  91. SC_PCI2C0 | SC_PCSPI | SC_PCRTC | SC_PCSSP1 |
  92. SC_PCGPIO | SC_PCI2C1 | SC_PCTIM2 | SC_PCI2C2);
  93. /* Clock output pin configuration. */
  94. outr(SC_CLKOUTCFG, SC_CLKOUT_EN | ((2 - 1) << SC_CLKOUTDIV_LSB));
  95. outr(PINSEL(3), inr(PINSEL(3)) | PS3_P1_27_CLKOUT);
  96. #endif
  97. }