system_lpc407x_8x.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. * Copyright (C) 2013 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. #include <stdint.h>
  35. #include <arch/cm3/nxp/lpc407x_8x.h>
  36. /** @addtogroup LPC407x_8x_System_Defines
  37. * @{
  38. */
  39. /**
  40. * Note: LPC40xx Code Read Protection field field must be present in
  41. * LPC40xx flash image and ocupy a word at 0x000002FC
  42. *
  43. */
  44. const uint32_t LPC40XX_CRP __attribute__((section(".crp"), used)) = 0xFFFFFFFF;
  45. uint32_t Lpc407x_8xGetCrpValue(void)
  46. {
  47. return *(&LPC40XX_CRP);
  48. }
  49. #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
  50. /**
  51. * Initialize the FPU
  52. *
  53. * @param none
  54. * @return none
  55. *
  56. * @brief Bring up the FPU
  57. */
  58. static void FpuInit(void)
  59. {
  60. /* From ARM trm manual:
  61. ; CPACR is located at address 0xE000ED88
  62. LDR.W R0, =0xE000ED88
  63. ; Read CPACR
  64. LDR R1, [R0]
  65. ; Set bits 20-23 to enable CP10 and CP11 coprocessors
  66. ORR R1, R1, #(0xF << 20)
  67. ; Write back the modified value to the CPACR
  68. STR R1, [R0]
  69. */
  70. volatile uint32_t* regCpacr = (uint32_t*) LPC_CPACR;
  71. volatile uint32_t* regMvfr0 = (uint32_t*) SCB_MVFR0;
  72. volatile uint32_t* regMvfr1 = (uint32_t*) SCB_MVFR1;
  73. volatile uint32_t Cpacr;
  74. volatile uint32_t Mvfr0;
  75. volatile uint32_t Mvfr1;
  76. char vfpPresent = 0;
  77. Mvfr0 = *regMvfr0;
  78. Mvfr1 = *regMvfr1;
  79. vfpPresent = ((SCB_MVFR0_RESET == Mvfr0) && (SCB_MVFR1_RESET == Mvfr1));
  80. if(vfpPresent)
  81. {
  82. Cpacr = *regCpacr;
  83. Cpacr |= (0xF << 20);
  84. *regCpacr = Cpacr; // enable CP10 and CP11 for full access
  85. }
  86. }
  87. #endif
  88. /**
  89. * Initialize the system
  90. *
  91. * @param none
  92. * @return none
  93. *
  94. * @brief Setup the microcontroller system.
  95. * Initialize the System and update the SystemFrequency variable.
  96. */
  97. void SystemInit (void)
  98. {
  99. #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
  100. FpuInit();
  101. #endif
  102. }
  103. /**
  104. * @}
  105. */