board.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Copyright (c) 2006-2020, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2020-04-16 bigmagic first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "board.h"
  13. #include "drv_uart.h"
  14. #include "cp15.h"
  15. #include "mmu.h"
  16. static rt_uint64_t timerStep;
  17. int rt_hw_get_gtimer_frq(void);
  18. void rt_hw_set_gtimer_val(rt_uint64_t value);
  19. int rt_hw_get_gtimer_val(void);
  20. int rt_hw_get_cntpct_val(void);
  21. void rt_hw_gtimer_enable(void);
  22. void core0_timer_enable_interrupt_controller(void)
  23. {
  24. CORE0_TIMER_IRQ_CTRL |= NON_SECURE_TIMER_IRQ;
  25. }
  26. void rt_hw_timer_isr(int vector, void *parameter)
  27. {
  28. rt_hw_set_gtimer_val(timerStep);
  29. rt_tick_increase();
  30. }
  31. void rt_hw_timer_init(void)
  32. {
  33. rt_hw_interrupt_install(TIMER_IRQ, rt_hw_timer_isr, RT_NULL, "tick");
  34. rt_hw_interrupt_umask(TIMER_IRQ);
  35. __ISB();
  36. timerStep = rt_hw_get_gtimer_frq();
  37. __DSB();
  38. timerStep /= RT_TICK_PER_SECOND;
  39. rt_hw_gtimer_enable();
  40. rt_hw_set_gtimer_val(timerStep);
  41. core0_timer_enable_interrupt_controller();
  42. }
  43. void idle_wfi(void)
  44. {
  45. asm volatile ("wfi");
  46. }
  47. /**
  48. * Initialize the Hardware related stuffs. Called from rtthread_startup()
  49. * after interrupt disabled.
  50. */
  51. void rt_hw_board_init(void)
  52. {
  53. mmu_init();
  54. armv8_map(0, 0, 0x6400000, MEM_ATTR_MEMORY);
  55. armv8_map(0xFE200000, 0xFE200000, 0x200000, MEM_ATTR_IO);//uart gpio
  56. armv8_map(0xFF800000, 0xFF800000, 0x200000, MEM_ATTR_IO);//gic timer
  57. mmu_enable();
  58. /* initialize hardware interrupt */
  59. rt_hw_interrupt_init(); // in libcpu/interrupt.c. Set some data structures, no operation on device
  60. rt_hw_vector_init(); // in libcpu/interrupt.c. == rt_cpu_vector_set_base((rt_ubase_t)&system_vectors);
  61. /* initialize uart */
  62. rt_hw_uart_init(); // driver/drv_uart.c
  63. #ifdef RT_USING_CONSOLE
  64. /* set console device */
  65. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  66. #endif /* RT_USING_CONSOLE */
  67. #ifdef RT_USING_HEAP
  68. /* initialize memory system */
  69. rt_kprintf("heap: 0x%08x - 0x%08x\n", RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  70. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  71. #endif
  72. /* initialize timer for os tick */
  73. rt_hw_timer_init();
  74. rt_thread_idle_sethook(idle_wfi);
  75. #ifdef RT_USING_COMPONENTS_INIT
  76. rt_components_board_init();
  77. #endif
  78. }