board.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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-01-30 lizhirui first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <rtdevice.h>
  13. #include "board.h"
  14. #include "tick.h"
  15. #include "drv_uart.h"
  16. #include <sbi.h>
  17. #ifdef RT_USING_SMART
  18. #include <mmu.h>
  19. #include "page.h"
  20. /* respect to boot loader, must be 0xFFFFFFC000200000 */
  21. RT_STATIC_ASSERT(kmem_region, KERNEL_VADDR_START == 0xFFFFFFC000220000);
  22. rt_region_t init_page_region = {(rt_size_t)RT_HW_PAGE_START, (rt_size_t)RT_HW_PAGE_END};
  23. extern size_t MMUTable[];
  24. struct mem_desc platform_mem_desc[] = {
  25. {KERNEL_VADDR_START, (rt_size_t)RT_HW_PAGE_END - 1, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM},
  26. };
  27. #define NUM_MEM_DESC (sizeof(platform_mem_desc) / sizeof(platform_mem_desc[0]))
  28. #endif /* RT_USING_SMART */
  29. #ifndef ARCH_REMAP_KERNEL
  30. #define IOREMAP_VEND USER_VADDR_START
  31. #else
  32. #define IOREMAP_VEND 0ul
  33. #endif
  34. //初始化BSS节区
  35. void init_bss(void)
  36. {
  37. unsigned int *dst;
  38. dst = &__bss_start;
  39. while (dst < &__bss_end)
  40. {
  41. *dst++ = 0;
  42. }
  43. }
  44. static void __rt_assert_handler(const char *ex_string, const char *func, rt_size_t line)
  45. {
  46. rt_kprintf("(%s) assertion failed at function:%s, line number:%d \n", ex_string, func, line);
  47. asm volatile("ebreak":::"memory");
  48. }
  49. //BSP的C入口
  50. void primary_cpu_entry(void)
  51. {
  52. //关中断
  53. rt_hw_interrupt_disable();
  54. rt_assert_set_hook(__rt_assert_handler);
  55. //启动RT-Thread Smart内核
  56. entry();
  57. }
  58. #define IOREMAP_SIZE (1ul << 30)
  59. //这个初始化程序由内核主动调用,此时调度器还未启动,因此在此不能使用依赖线程上下文的函数
  60. void rt_hw_board_init(void)
  61. {
  62. #ifdef RT_USING_SMART
  63. /* init data structure */
  64. rt_hw_mmu_map_init(&rt_kernel_space, (void *)(IOREMAP_VEND - IOREMAP_SIZE), IOREMAP_SIZE, (rt_size_t *)MMUTable, PV_OFFSET);
  65. /* init page allocator */
  66. rt_page_init(init_page_region);
  67. /* setup region, and enable MMU */
  68. rt_hw_mmu_setup(&rt_kernel_space, platform_mem_desc, NUM_MEM_DESC);
  69. #endif
  70. #ifdef RT_USING_HEAP
  71. /* initialize memory system */
  72. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  73. #endif
  74. /* initalize interrupt */
  75. rt_hw_interrupt_init();
  76. /* initialize hardware interrupt */
  77. rt_hw_uart_init();
  78. rt_hw_tick_init();
  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_COMPONENTS_INIT
  84. rt_components_board_init();
  85. #endif
  86. }
  87. void rt_hw_cpu_reset(void)
  88. {
  89. sbi_shutdown();
  90. while(1);
  91. }
  92. MSH_CMD_EXPORT_ALIAS(rt_hw_cpu_reset, reboot, reset machine);