board.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * Copyright (c) 2006-2018, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. */
  9. #include <rthw.h>
  10. #include <rtthread.h>
  11. #include "board.h"
  12. #include "tick.h"
  13. #include "drv_uart.h"
  14. #include "encoding.h"
  15. #include "fpioa.h"
  16. #include "dmac.h"
  17. void init_bss(void)
  18. {
  19. unsigned int *dst;
  20. dst = &__bss_start;
  21. while (dst < &__bss_end)
  22. {
  23. *dst++ = 0;
  24. }
  25. }
  26. void primary_cpu_entry(void)
  27. {
  28. extern void entry(void);
  29. /* disable global interrupt */
  30. init_bss();
  31. rt_hw_interrupt_disable();
  32. entry();
  33. }
  34. #include <clint.h>
  35. #include <sysctl.h>
  36. int freq(void)
  37. {
  38. rt_uint64_t value = 0;
  39. value = sysctl_clock_get_freq(SYSCTL_CLOCK_PLL0);
  40. rt_kprintf("PLL0: %d\n", value);
  41. value = sysctl_clock_get_freq(SYSCTL_CLOCK_PLL1);
  42. rt_kprintf("PLL1: %d\n", value);
  43. value = sysctl_clock_get_freq(SYSCTL_CLOCK_PLL2);
  44. rt_kprintf("PLL2: %d\n", value);
  45. value = sysctl_clock_get_freq(SYSCTL_CLOCK_CPU);
  46. rt_kprintf("CPU : %d\n", value);
  47. value = sysctl_clock_get_freq(SYSCTL_CLOCK_APB0);
  48. rt_kprintf("APB0: %d\n", value);
  49. value = sysctl_clock_get_freq(SYSCTL_CLOCK_APB1);
  50. rt_kprintf("APB1: %d\n", value);
  51. value = sysctl_clock_get_freq(SYSCTL_CLOCK_APB2);
  52. rt_kprintf("APB2: %d\n", value);
  53. value = sysctl_clock_get_freq(SYSCTL_CLOCK_HCLK);
  54. rt_kprintf("HCLK: %d\n", value);
  55. value = clint_get_time();
  56. rt_kprintf("mtime: %d\n", value);
  57. return 0;
  58. }
  59. MSH_CMD_EXPORT(freq, show freq info);
  60. #ifdef RT_USING_SMP
  61. extern int rt_hw_clint_ipi_enable(void);
  62. #endif
  63. void rt_hw_board_init(void)
  64. {
  65. sysctl_pll_set_freq(SYSCTL_PLL0, 800000000UL);
  66. sysctl_pll_set_freq(SYSCTL_PLL1, 400000000UL);
  67. /* Init FPIOA */
  68. fpioa_init();
  69. /* Dmac init */
  70. dmac_init();
  71. /* initalize interrupt */
  72. rt_hw_interrupt_init();
  73. /* initialize hardware interrupt */
  74. rt_hw_uart_init();
  75. rt_hw_tick_init();
  76. #ifdef RT_USING_SMP
  77. rt_hw_clint_ipi_enable();
  78. #endif
  79. #ifdef RT_USING_CONSOLE
  80. /* set console device */
  81. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  82. #endif /* RT_USING_CONSOLE */
  83. #ifdef RT_USING_HEAP
  84. rt_kprintf("heap: [0x%08x - 0x%08x]\n", (rt_ubase_t) RT_HW_HEAP_BEGIN, (rt_ubase_t) RT_HW_HEAP_END);
  85. /* initialize memory system */
  86. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  87. #endif
  88. #ifdef RT_USING_COMPONENTS_INIT
  89. rt_components_board_init();
  90. #endif
  91. }
  92. void rt_hw_cpu_reset(void)
  93. {
  94. sysctl->soft_reset.soft_reset = 1;
  95. while(1);
  96. }
  97. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);