board.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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-06-10 xiaoyu implement rt_hw_us_delay()
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "board.h"
  13. #include "tick.h"
  14. #include "drv_uart.h"
  15. #include "encoding.h"
  16. #include "fpioa.h"
  17. #include "dmac.h"
  18. void init_bss(void)
  19. {
  20. unsigned int *dst;
  21. dst = &__bss_start;
  22. while (dst < &__bss_end)
  23. {
  24. *dst++ = 0;
  25. }
  26. }
  27. void primary_cpu_entry(void)
  28. {
  29. extern void entry(void);
  30. /* disable global interrupt */
  31. init_bss();
  32. rt_hw_interrupt_disable();
  33. entry();
  34. }
  35. #include <clint.h>
  36. #include <sysctl.h>
  37. int freq(void)
  38. {
  39. rt_uint64_t value = 0;
  40. value = sysctl_clock_get_freq(SYSCTL_CLOCK_PLL0);
  41. rt_kprintf("PLL0: %d\n", value);
  42. value = sysctl_clock_get_freq(SYSCTL_CLOCK_PLL1);
  43. rt_kprintf("PLL1: %d\n", value);
  44. value = sysctl_clock_get_freq(SYSCTL_CLOCK_PLL2);
  45. rt_kprintf("PLL2: %d\n", value);
  46. value = sysctl_clock_get_freq(SYSCTL_CLOCK_CPU);
  47. rt_kprintf("CPU : %d\n", value);
  48. value = sysctl_clock_get_freq(SYSCTL_CLOCK_APB0);
  49. rt_kprintf("APB0: %d\n", value);
  50. value = sysctl_clock_get_freq(SYSCTL_CLOCK_APB1);
  51. rt_kprintf("APB1: %d\n", value);
  52. value = sysctl_clock_get_freq(SYSCTL_CLOCK_APB2);
  53. rt_kprintf("APB2: %d\n", value);
  54. value = sysctl_clock_get_freq(SYSCTL_CLOCK_HCLK);
  55. rt_kprintf("HCLK: %d\n", value);
  56. value = clint_get_time();
  57. rt_kprintf("mtime: %d\n", value);
  58. return 0;
  59. }
  60. MSH_CMD_EXPORT(freq, show freq info);
  61. #ifdef RT_USING_SMP
  62. extern int rt_hw_clint_ipi_enable(void);
  63. #endif
  64. void rt_hw_board_init(void)
  65. {
  66. sysctl_pll_set_freq(SYSCTL_PLL0, 800000000UL);
  67. sysctl_pll_set_freq(SYSCTL_PLL1, 400000000UL);
  68. /* Init FPIOA */
  69. fpioa_init();
  70. /* Dmac init */
  71. dmac_init();
  72. /* initalize interrupt */
  73. rt_hw_interrupt_init();
  74. /* initialize hardware interrupt */
  75. rt_hw_uart_init();
  76. rt_hw_tick_init();
  77. #ifdef RT_USING_SMP
  78. rt_hw_clint_ipi_enable();
  79. #endif
  80. #ifdef RT_USING_CONSOLE
  81. /* set console device */
  82. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  83. #endif /* RT_USING_CONSOLE */
  84. #ifdef RT_USING_HEAP
  85. rt_kprintf("heap: [0x%08x - 0x%08x]\n", (rt_ubase_t) RT_HW_HEAP_BEGIN, (rt_ubase_t) RT_HW_HEAP_END);
  86. /* initialize memory system */
  87. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  88. #endif
  89. #ifdef RT_USING_COMPONENTS_INIT
  90. rt_components_board_init();
  91. #endif
  92. }
  93. void rt_hw_cpu_reset(void)
  94. {
  95. sysctl->soft_reset.soft_reset = 1;
  96. while(1);
  97. }
  98. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);
  99. /**
  100. * This function will delay for some us.
  101. *
  102. * @param us the delay time of us
  103. */
  104. void rt_hw_us_delay(rt_uint32_t usec)
  105. {
  106. rt_uint32_t cycle = read_cycle();
  107. rt_uint32_t nop_all = usec * sysctl_clock_get_freq(SYSCTL_CLOCK_CPU) / 1000000UL;
  108. while (1)
  109. {
  110. if(read_cycle() - cycle >= nop_all)
  111. break;
  112. }
  113. }