hal_lld.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. SPC5 HAL - Copyright (C) 2013 STMicroelectronics
  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 SPC563Mxx/hal_lld.c
  15. * @brief SPC563Mxx 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. /* Driver exported functions. */
  35. /*===========================================================================*/
  36. /**
  37. * @brief Low level HAL driver initialization.
  38. *
  39. * @notapi
  40. */
  41. void hal_lld_init(void) {
  42. uint32_t n;
  43. /* Optimal crossbar settings. The DMA priority is placed above the CPU
  44. priority in order to not starve I/O activities while the CPU is
  45. executing tight loops (FLASH and SRAM slave ports only).
  46. The SRAM is parked on the load/store port, for some unknown reason it
  47. is defaulted on the instructions port and this kills performance.*/
  48. XBAR.SGPCR3.B.PARK = 4; /* RAM slave on load/store port.*/
  49. XBAR.MPR0.R = 0x00030201; /* Flash slave port priorities:
  50. eDMA (1): 0 (highest)
  51. Core Instructions (0): 1
  52. Undocumented (2): 2
  53. Core Data (4): 3 */
  54. XBAR.MPR3.R = 0x00030201; /* SRAM slave port priorities:
  55. eDMA (1): 0 (highest)
  56. Core Instructions (0): 1
  57. Undocumented (2): 2
  58. Core Data (4): 3 */
  59. /* Decrementer timer initialized for system tick use, note, it is
  60. initialized here because in the OSAL layer the system clock frequency
  61. is not yet known.*/
  62. n = SPC5_SYSCLK / OSAL_ST_FREQUENCY;
  63. asm volatile ("mtspr 22, %[n] \t\n" /* Init. DEC register. */
  64. "mtspr 54, %[n] \t\n" /* Init. DECAR register.*/
  65. "e_lis %%r3, 0x0440 \t\n" /* DIE ARE bits. */
  66. "mtspr 340, %%r3" /* TCR register. */
  67. : : [n] "r" (n) : "r3");
  68. /* TB counter enabled for debug and measurements.*/
  69. asm volatile ("e_li %%r3, 0x4000 \t\n" /* TBEN bit. */
  70. "mtspr 1008, %%r3" /* HID0 register. */
  71. : : : "r3");
  72. /* eMIOS initialization.*/
  73. EMIOS.MCR.R = (1U << 26) | SPC5_EMIOS_GPRE; /* GPREN and GPRE. */
  74. /* EDMA initialization.*/
  75. edmaInit();
  76. }
  77. /**
  78. * @brief SPC563 clocks and PLL initialization.
  79. * @note All the involved constants come from the file @p board.h and
  80. * @p hal_lld.h
  81. * @note This function must be invoked only after the system reset.
  82. *
  83. * @special
  84. */
  85. void spc_clock_init(void) {
  86. #if !SPC5_NO_INIT
  87. /* PLL activation.*/
  88. FMPLL.ESYNCR1.B.EMODE = 1; /* Enhanced mode on. */
  89. FMPLL.ESYNCR1.B.CLKCFG &= 1; /* Bypass mode, PLL off.*/
  90. #if !SPC5_CLK_BYPASS
  91. FMPLL.ESYNCR1.B.CLKCFG |= 2; /* PLL on. */
  92. FMPLL.ESYNCR1.B.EPREDIV = SPC5_CLK_PREDIV;
  93. FMPLL.ESYNCR1.B.EMFD = SPC5_CLK_MFD;
  94. FMPLL.ESYNCR2.B.ERFD = SPC5_CLK_RFD;
  95. while (!FMPLL.SYNSR.B.LOCK)
  96. ;
  97. FMPLL.ESYNCR1.B.CLKCFG |= 4; /* Clock from the PLL. */
  98. #endif /* !SPC5_CLK_BYPASS */
  99. /* FLASH wait states and prefetching setup.*/
  100. CFLASH0.BIUCR.R = SPC5_FLASH_BIUCR | SPC5_FLASH_WS;
  101. CFLASH0.BIUCR2.R = 0;
  102. CFLASH0.PFCR3.R = 0;
  103. #endif /* !SPC5_NO_INIT */
  104. }
  105. /** @} */