board.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include <rthw.h>
  2. #include <rtthread.h>
  3. #include "xil_assert.h"
  4. #include "rtdevice.h"
  5. #include "drv_gpio.h"
  6. #include <mmu.h>
  7. extern rt_uint32_t __text_start;
  8. struct mem_desc platform_mem_desc[] = {
  9. /* no access to the memory below .text */
  10. /* 521Mb cached DDR memory */
  11. {(rt_uint32_t)&__text_start, 0x3F600000-1, (rt_uint32_t)&__text_start, NORMAL_MEM},
  12. /* PL region */
  13. {0x40000000, 0xBFFFFFFF, 0x40000000, DEVICE_MEM},
  14. /* IOP registers */
  15. {0xE0000000, 0xE02FFFFF, 0xE0000000, DEVICE_MEM},
  16. /* SLCR, PS and CPU private registers, note we map more memory space as the
  17. * entry is 1MB in size. */
  18. {0xF8000000, 0xFFFFFFFF, 0xF8000000, DEVICE_MEM},
  19. };
  20. const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
  21. void idle_wfi(void)
  22. {
  23. asm volatile ("wfi");
  24. }
  25. static void rt_xil_assert_callback(const char8 *File, s32 Line)
  26. {
  27. rt_kprintf("Xil_AssertCallback: %s, %d\n", File, Line);
  28. RT_ASSERT(0);
  29. }
  30. typedef void (*usleep_hook_t) (unsigned long useconds);
  31. // note: should edit usleep.c in bsp to fix it
  32. //
  33. // static usleep_hook_t usleep_hook;
  34. //
  35. // void zynq_set_usleep_hook(usleep_hook_t hook)
  36. // {
  37. // usleep_hook = hook;
  38. // }
  39. //
  40. // int usleep(unsigned long useconds)
  41. // {
  42. // if (usleep_hook)
  43. // {
  44. // usleep_hook(useconds);
  45. // return 0;
  46. // }
  47. // XTime tEnd, tCur;
  48. // XTime_GetTime(&tCur);
  49. // tEnd = tCur + (((XTime) useconds) * COUNTS_PER_USECOND);
  50. // do
  51. // {
  52. // XTime_GetTime(&tCur);
  53. // } while (tCur < tEnd);
  54. // return 0;
  55. // }
  56. //
  57. extern void zynq_set_usleep_hook(usleep_hook_t hook);
  58. static void hw_usleep_hook(unsigned long useconds)
  59. {
  60. useconds /= 1000;
  61. if (useconds == 0)
  62. useconds = 1;
  63. rt_thread_mdelay(useconds);
  64. }
  65. static int setup_zynq_usleep_hook(void)
  66. {
  67. zynq_set_usleep_hook(hw_usleep_hook);
  68. return 0;
  69. }
  70. INIT_BOARD_EXPORT(setup_zynq_usleep_hook);
  71. static void _assert_hook (const char *ex, const char *func, rt_size_t line)
  72. {
  73. RT_ASSERT(0);
  74. }
  75. /**
  76. * This function will initialize beaglebone board
  77. */
  78. void rt_hw_board_init(void)
  79. {
  80. Xil_AssertSetCallback(rt_xil_assert_callback);
  81. /* initialize hardware interrupt */
  82. rt_hw_interrupt_init();
  83. /* initialize system heap */
  84. rt_system_heap_init(HEAP_BEGIN, HEAP_END);
  85. rt_hw_pin_init();
  86. rt_components_board_init();
  87. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  88. rt_thread_idle_sethook(idle_wfi);
  89. #ifdef RT_USING_SMP
  90. /* install IPI handle */
  91. rt_hw_ipi_handler_install(RT_SCHEDULE_IPI, rt_scheduler_ipi_handler);
  92. #endif
  93. rt_assert_set_hook(_assert_hook);
  94. }
  95. #include "xil_io.h"
  96. #define PSS_RST_CTRL_REG 0xF8000200
  97. #define SLCR_UNLOCK_ADDR 0xF8000008
  98. #define UNLOCK_KEY 0xDF0D
  99. #define PSS_RST_MASK 0x01
  100. static void zynq_hw_software_reset(void)
  101. {
  102. Xil_Out32(SLCR_UNLOCK_ADDR, UNLOCK_KEY);
  103. Xil_Out32(PSS_RST_CTRL_REG, PSS_RST_MASK);
  104. }
  105. MSH_CMD_EXPORT_ALIAS(zynq_hw_software_reset, reboot, soft reboot);