board.c 2.5 KB

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