board.c 2.3 KB

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