board.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. struct mem_desc platform_mem_desc[] = {
  17. {0x0, 0x6400000, 0x0, NORMAL_MEM},
  18. {0x8000000, 0x8100000, 0x8000000, DEVICE_MEM}, //mbox msg
  19. {0x0EA00000, 0x0EE00000, 0x0EA00000, DEVICE_MEM}, //framebuffer
  20. {0xFE000000, 0xFE400000, 0xFE000000, DEVICE_MEM}, //peripheral
  21. {0xFF800000, 0xFFA00000, 0xFF800000, DEVICE_MEM} //gic
  22. };
  23. const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
  24. void rt_hw_timer_isr(int vector, void *parameter)
  25. {
  26. ARM_TIMER_IRQCLR = 0;
  27. rt_tick_increase();
  28. }
  29. void rt_hw_timer_init(void)
  30. {
  31. rt_hw_interrupt_install(ARM_TIMER_IRQ, rt_hw_timer_isr, RT_NULL, "tick");
  32. rt_hw_interrupt_umask(ARM_TIMER_IRQ);
  33. /* timer_clock = apb_clock/(pre_divider + 1) */
  34. ARM_TIMER_PREDIV = (250 - 1);
  35. ARM_TIMER_RELOAD = 0;
  36. ARM_TIMER_LOAD = 0;
  37. ARM_TIMER_IRQCLR = 0;
  38. ARM_TIMER_CTRL = 0;
  39. ARM_TIMER_RELOAD = 10000;
  40. ARM_TIMER_LOAD = 10000;
  41. /* 23-bit counter, enable interrupt, enable timer */
  42. ARM_TIMER_CTRL = (1 << 1) | (1 << 5) | (1 << 7);
  43. }
  44. void idle_wfi(void)
  45. {
  46. asm volatile ("wfi");
  47. }
  48. /**
  49. * Initialize the Hardware related stuffs. Called from rtthread_startup()
  50. * after interrupt disabled.
  51. */
  52. void rt_hw_board_init(void)
  53. {
  54. /* initialize hardware interrupt */
  55. rt_hw_interrupt_init();
  56. /* initialize uart */
  57. rt_hw_uart_init(); // driver/drv_uart.c
  58. #ifdef RT_USING_CONSOLE
  59. /* set console device */
  60. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  61. #endif /* RT_USING_CONSOLE */
  62. #ifdef RT_USING_HEAP
  63. /* initialize memory system */
  64. rt_kprintf("heap: 0x%08x - 0x%08x\n", RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  65. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  66. #endif
  67. /* initialize timer for os tick */
  68. rt_hw_timer_init();
  69. rt_thread_idle_sethook(idle_wfi);
  70. #ifdef RT_USING_COMPONENTS_INIT
  71. rt_components_board_init();
  72. #endif
  73. }