hal_lld.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file LPC214x/hal_lld.c
  15. * @brief LPC214x HAL subsystem low level driver source.
  16. *
  17. * @addtogroup HAL
  18. * @{
  19. */
  20. #include "hal.h"
  21. /*===========================================================================*/
  22. /* Driver exported variables. */
  23. /*===========================================================================*/
  24. /*===========================================================================*/
  25. /* Driver local variables and types. */
  26. /*===========================================================================*/
  27. /*===========================================================================*/
  28. /* Driver local functions. */
  29. /*===========================================================================*/
  30. /*===========================================================================*/
  31. /* Driver interrupt handlers. */
  32. /*===========================================================================*/
  33. /*
  34. * Non-vectored IRQs handler, the default action can be overridden by
  35. * redefining the @p LPC214x_NON_VECTORED_IRQ_HOOK() hook macro.
  36. */
  37. static CH_IRQ_HANDLER(irq_handler) {
  38. CH_IRQ_PROLOGUE();
  39. LPC214x_NON_VECTORED_IRQ_HOOK();
  40. VICVectAddr = 0;
  41. CH_IRQ_EPILOGUE();
  42. }
  43. /*===========================================================================*/
  44. /* Driver exported functions. */
  45. /*===========================================================================*/
  46. /**
  47. * @brief Low level HAL driver initialization.
  48. *
  49. * @notapi
  50. */
  51. void hal_lld_init(void) {
  52. vic_init();
  53. VICDefVectAddr = (IOREG32)irq_handler;
  54. }
  55. /**
  56. * @brief LPC214x clocks and PLL initialization.
  57. * @note All the involved constants come from the file @p board.h.
  58. * @note This function must be invoked only after the system reset.
  59. *
  60. * @special
  61. */
  62. void lpc214x_clock_init(void) {
  63. /*
  64. * All peripherals clock disabled by default in order to save power.
  65. */
  66. PCONP = PCRTC | PCTIM0;
  67. /*
  68. * MAM setup.
  69. */
  70. MAMTIM = 0x3; /* 3 cycles for flash accesses. */
  71. MAMCR = 0x2; /* MAM fully enabled. */
  72. /*
  73. * PLL setup for Fosc=12MHz and CCLK=48MHz.
  74. * P=2 M=3.
  75. */
  76. PLL *pll = PLL0Base;
  77. pll->PLL_CFG = 0x23; /* P and M values. */
  78. pll->PLL_CON = 0x1; /* Enables the PLL 0. */
  79. pll->PLL_FEED = 0xAA;
  80. pll->PLL_FEED = 0x55;
  81. while (!(pll->PLL_STAT & 0x400))
  82. ; /* Wait for PLL lock. */
  83. pll->PLL_CON = 0x3; /* Connects the PLL. */
  84. pll->PLL_FEED = 0xAA;
  85. pll->PLL_FEED = 0x55;
  86. /*
  87. * VPB setup.
  88. * PCLK = CCLK / 4.
  89. */
  90. VPBDIV = VPD_D4;
  91. }
  92. /** @} */