board.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. * 2012-11-20 Bernard the first version
  9. * 2018-11-22 Jesven add rt_hw_spin_lock
  10. * add rt_hw_spin_unlock
  11. * add smp ipi init
  12. */
  13. #include <rthw.h>
  14. #include <rtthread.h>
  15. #include <rtdbg.h>
  16. #include "board.h"
  17. #include "mm_aspace.h"
  18. #include <mmu.h>
  19. #ifdef RT_USING_SMART
  20. #include <page.h>
  21. #include <lwp_arch.h>
  22. #endif
  23. #ifdef RT_USING_SMART
  24. extern size_t MMUTable[];
  25. struct mem_desc platform_mem_desc[] = { /* 100ask_imx6ull ddr 512M */
  26. {KERNEL_VADDR_START, KERNEL_VADDR_START + 0x1FFFFFFF, (rt_size_t)ARCH_MAP_FAILED, NORMAL_MEM}
  27. };
  28. #else
  29. struct mem_desc platform_mem_desc[] = {
  30. {0x00000000, 0x80000000, 0x00000000, DEVICE_MEM},
  31. {0x80000000, 0xFFF00000, 0x80000000, NORMAL_MEM}
  32. };
  33. #endif
  34. const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
  35. void idle_wfi(void)
  36. {
  37. asm volatile ("wfi");
  38. }
  39. /**
  40. * This function will initialize board
  41. */
  42. #ifdef RT_USING_SMART
  43. rt_region_t init_page_region = {
  44. (uint32_t)PAGE_START,
  45. (uint32_t)PAGE_END,
  46. };
  47. #endif
  48. int board_reboot(int argc, char **argv)
  49. {
  50. wdog_config_t config;
  51. SRC_Type *src = (SRC_Type*)g_src_vbase;
  52. WDOG_Type *wdog = (WDOG_Type*)g_wdog1_vbase;
  53. LOG_E("resetting ...\n");
  54. rt_hw_ms_delay(50);
  55. src->SCR &= ~SRC_SCR_WARM_RESET_ENABLE_MASK;
  56. CLOCK_EnableClock(kCLOCK_Wdog1);
  57. WDOG_GetDefaultConfig(&config);
  58. config.timeoutValue = 0x00u;
  59. WDOG_Init(wdog, &config);
  60. while (1)
  61. {
  62. //waiting...
  63. }
  64. return 0;
  65. }
  66. MSH_CMD_EXPORT_ALIAS(board_reboot, reboot, reboot system);
  67. void assert_handler(const char *ex_string, const char *func, rt_size_t line)
  68. {
  69. volatile char dummy = 0;
  70. extern int list_thread(void);
  71. list_thread();
  72. rt_backtrace();
  73. rt_kprintf("(%s) assertion failed at function:%s, line number:%d \n", ex_string, func, line);
  74. while (dummy == 0)
  75. ;
  76. }
  77. #define PUTC(periph, ch) \
  78. do { \
  79. while (0 == (periph->USR2 & UART_USR2_TXDC_MASK)); \
  80. periph->UTXD = ch; \
  81. } while (0)
  82. void rt_hw_board_init(void)
  83. {
  84. #ifdef RT_USING_SMART
  85. rt_uint32_t mmutable_p = 0;
  86. rt_hw_mmu_map_init(&rt_kernel_space, (void*)0xf0000000, 0x10000000, MMUTable, PV_OFFSET);
  87. rt_hw_init_mmu_table(platform_mem_desc, platform_mem_desc_size);
  88. mmutable_p = (rt_uint32_t)MMUTable + (rt_uint32_t)PV_OFFSET ;
  89. rt_hw_mmu_switch((void*)mmutable_p);
  90. rt_page_init(init_page_region);
  91. rt_hw_mmu_ioremap_init(&rt_kernel_space, (void*)0xf0000000, 0x10000000);
  92. arch_kuser_init(&rt_kernel_space, (void*)0xffff0000);
  93. #else
  94. rt_hw_mmu_map_init(&rt_kernel_space, (void*)0x80000000, 0x10000000, MMUTable, 0);
  95. rt_hw_init_mmu_table(platform_mem_desc,platform_mem_desc_size);
  96. rt_hw_mmu_init();
  97. rt_hw_mmu_ioremap_init(&rt_kernel_space, (void*)0x80000000, 0x10000000);
  98. #endif
  99. /* initialize system heap */
  100. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  101. /* initialize hardware interrupt */
  102. rt_hw_interrupt_init();
  103. SystemAddressMapping();
  104. SystemClockInit();
  105. rt_components_board_init();
  106. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  107. rt_thread_idle_sethook(idle_wfi);
  108. rt_assert_set_hook(assert_handler);
  109. }