board.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2021-03-04 Carl the first version
  9. *
  10. */
  11. #include <rtthread.h>
  12. #include "ft_printf.h"
  13. #include "ft_assert.h"
  14. #include "ft_cpu.h"
  15. #include "ft_psci.h"
  16. #include "ft_parameters.h"
  17. #include "board.h"
  18. #include "gtimer.h"
  19. #include "ft_generic_timer.h"
  20. #include <gicv3.h>
  21. #include "interrupt.h"
  22. #include <mmu.h>
  23. #include "cp15.h"
  24. #include "ft2004.h"
  25. #define DDR_MEM (SHARED | AP_RW | DOMAIN0 | MEMWT | DESC_SEC)
  26. struct mem_desc platform_mem_desc[] = {
  27. {0x80000000,
  28. 0x80000000 + 0x7f000000,
  29. 0x80000000,
  30. DDR_MEM},
  31. {0, //< QSPI
  32. 0x1FFFFFFF,
  33. 0,
  34. DEVICE_MEM},
  35. {0x20000000, //<! LPC
  36. 0x27FFFFFF,
  37. 0x20000000,
  38. DEVICE_MEM},
  39. {FT_DEV_BASE_ADDR, //<! Device register
  40. FT_DEV_END_ADDR,
  41. FT_DEV_BASE_ADDR,
  42. DEVICE_MEM},
  43. {0x30000000, //<! debug
  44. 0x39FFFFFF,
  45. 0x30000000,
  46. DEVICE_MEM},
  47. {0x3A000000, //<! Internal register space in the on-chip network
  48. 0x3AFFFFFF,
  49. 0x3A000000,
  50. DEVICE_MEM},
  51. {FT_PCI_CONFIG_BASEADDR,
  52. FT_PCI_CONFIG_BASEADDR + FT_PCI_CONFIG_REG_LENGTH,
  53. FT_PCI_CONFIG_BASEADDR,
  54. DEVICE_MEM},
  55. {FT_PCI_IO_CONFIG_BASEADDR,
  56. FT_PCI_IO_CONFIG_BASEADDR + FT_PCI_IO_CONFIG_REG_LENGTH,
  57. FT_PCI_IO_CONFIG_BASEADDR,
  58. DEVICE_MEM},
  59. {FT_PCI_MEM32_BASEADDR,
  60. FT_PCI_MEM32_BASEADDR + FT_PCI_MEM32_REG_LENGTH,
  61. FT_PCI_MEM32_BASEADDR,
  62. DEVICE_MEM},
  63. };
  64. const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]);
  65. static rt_uint32_t timerStep;
  66. void rt_hw_timer_isr(int vector, void *parameter)
  67. {
  68. gtimer_set_load_value(timerStep);
  69. rt_tick_increase();
  70. }
  71. int rt_hw_timer_init(void)
  72. {
  73. rt_hw_interrupt_install(30, rt_hw_timer_isr, RT_NULL, "tick");
  74. rt_hw_interrupt_umask(30);
  75. timerStep = gtimer_get_counter_frequency();
  76. timerStep /= RT_TICK_PER_SECOND;
  77. gtimer_set_load_value(timerStep);
  78. gtimer_set_control(1);
  79. return 0;
  80. }
  81. INIT_BOARD_EXPORT(rt_hw_timer_init);
  82. static void AssertCallback(const char *File, s32 Line)
  83. {
  84. Ft_printf("Assert Error is %s : %d \r\n", File, Line);
  85. }
  86. #ifdef RT_USING_SMP
  87. void rt_hw_ipi_handler_install(int ipi_vector, rt_isr_handler_t ipi_isr_handler);
  88. #endif
  89. /**
  90. * This function will initialize hardware board
  91. */
  92. void rt_hw_board_init(void)
  93. {
  94. /* bsp debug */
  95. FCpu_SpinLockInit();
  96. Ft_GenericTimer_Init(0, RT_NULL);
  97. Ft_vsprintfRegister((vsprintf_p)rt_vsprintf);
  98. Ft_assertSetCallBack((Ft_assertCallback)AssertCallback);
  99. /* interrupt init */
  100. arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + 0, 0);
  101. #if RT_CPUS_NR == 2
  102. Ft_printf("arm_gic_redist_address_set is 2 \r\n");
  103. arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + (2U << 16), 1);
  104. #elif RT_CPUS_NR == 3
  105. arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + (2U << 16), 1);
  106. arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + 2 * (2U << 16), 2);
  107. #elif RT_CPUS_NR == 4
  108. arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + (2U << 16), 1);
  109. arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + 2 * (2U << 16), 2);
  110. arm_gic_redist_address_set(0, FT_GICV3_RD_BASEADDRESS + 3 * (2U << 16), 3);
  111. #endif
  112. rt_hw_interrupt_init();
  113. rt_components_board_init();
  114. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  115. /* 初始化内存池 */
  116. #ifdef RT_USING_HEAP
  117. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  118. #endif
  119. #ifdef RT_USING_SMP
  120. /* install IPI handle */
  121. rt_hw_interrupt_set_priority(RT_SCHEDULE_IPI, 16);
  122. rt_hw_ipi_handler_install(RT_SCHEDULE_IPI, rt_scheduler_ipi_handler);
  123. rt_hw_interrupt_umask(RT_SCHEDULE_IPI);
  124. #endif
  125. }
  126. static void ft_reset(void)
  127. {
  128. FPsci_Reset();
  129. }
  130. MSH_CMD_EXPORT_ALIAS(ft_reset, ft_reset, ft_reset);
  131. /*@}*/