board.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2017-5-30 Bernard the first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "board.h"
  13. #include "drv_uart.h"
  14. #include "interrupt.h"
  15. #include "mmu.h"
  16. static void os_clock_irq_handle(int irqno, void *param)
  17. {
  18. volatile rt_uint32_t *temp_addr = (rt_uint32_t *)(0x01C20C00 + 0x04);
  19. /* clear timer */
  20. *temp_addr |= 0x01;
  21. rt_tick_increase();
  22. }
  23. static void mmu_init(void)
  24. {
  25. struct mem_desc r6_mem_desc[] =
  26. {
  27. { 0x00000000, 0xFFFFFFFF, 0x00000000, RW_NCNB }, /* None cached for 4G memory */
  28. { 0x80000000, 0x82000000 - 1, 0x80000000, RW_CB }, /* 32M cached SDRAM memory */
  29. //{ 0x00000000, 0x00001000-1, 0x80000000, RW_CB }, /* isr vector table */
  30. //here not set mmu
  31. //start_gcc.S Copy vector to the correct address
  32. };
  33. rt_hw_mmu_init(r6_mem_desc, sizeof(r6_mem_desc) / sizeof(r6_mem_desc[0]));
  34. }
  35. static void os_clock_init(void)
  36. {
  37. rt_uint32_t temp;
  38. volatile rt_uint32_t *temp_addr;
  39. /* reload value */
  40. temp = 0xB71B00 / RT_TICK_PER_SECOND;
  41. temp_addr = (rt_uint32_t *)(0x01C20C00 + 0x14);
  42. *temp_addr = temp;
  43. /* continuous | /2 | 24Mhz | reload*/
  44. temp = (0x00 << 7) | (0x01 << 4) | (0x01 << 2) | (0x00 << 1);
  45. temp_addr = (rt_uint32_t *)(0x01C20C00 + 0x10);
  46. *temp_addr &= 0xffffff00;
  47. *temp_addr |= temp;
  48. /* open timer irq */
  49. temp = 0x01 << 0;
  50. temp_addr = (rt_uint32_t *)(0x01C20C00);
  51. *temp_addr |= temp;
  52. /* set init value */
  53. temp_addr = (rt_uint32_t *)(0x01C20C00 + 0x18);
  54. *temp_addr = 0;
  55. /* begin run timer */
  56. temp = 0x01 << 0;
  57. temp_addr = (rt_uint32_t *)(0x01C20C00 + 0x10);
  58. *temp_addr |= temp;
  59. temp_addr = (rt_uint32_t *)(0x01C20C00);
  60. /* set irq handle */
  61. rt_hw_interrupt_install(TIMER0_INTERRUPT, os_clock_irq_handle, (void *)temp_addr, "timer");
  62. rt_hw_interrupt_umask(TIMER0_INTERRUPT);
  63. }
  64. void rt_hw_board_init(void)
  65. {
  66. mmu_init();
  67. rt_hw_interrupt_init();
  68. #ifdef RT_USING_HEAP
  69. /* init memory system */
  70. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  71. #endif
  72. #ifdef RT_USING_SERIAL
  73. /* init hardware interrupt */
  74. rt_hw_uart_init();
  75. #endif
  76. #if defined(RT_USING_CONSOLE) && defined(RT_USING_DEVICE)
  77. /* set console device */
  78. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  79. #endif
  80. os_clock_init();
  81. #ifdef RT_USING_COMPONENTS_INIT
  82. rt_components_board_init();
  83. #endif
  84. }