board.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2017, RT-Thread Development Team
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along
  17. * with this program; if not, write to the Free Software Foundation, Inc.,
  18. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. *
  20. * Change Logs:
  21. * Date Author Notes
  22. * 2017-5-30 Bernard the first version
  23. */
  24. #include <rthw.h>
  25. #include <rtthread.h>
  26. #include "board.h"
  27. #include "drv_uart.h"
  28. #include "interrupt.h"
  29. #include "mmu.h"
  30. static void os_clock_irq_handle(int irqno, void *param)
  31. {
  32. volatile rt_uint32_t *temp_addr = (rt_uint32_t *)(0x01C20C00 + 0x04);
  33. /* clear timer */
  34. *temp_addr |= 0x01;
  35. rt_tick_increase();
  36. }
  37. static void mmu_init(void)
  38. {
  39. struct mem_desc r6_mem_desc[] =
  40. {
  41. { 0x00000000, 0xFFFFFFFF, 0x00000000, RW_NCNB }, /* None cached for 4G memory */
  42. { 0x80000000, 0x82000000 - 1, 0x80000000, RW_CB }, /* 32M cached SDRAM memory */
  43. //{ 0x00000000, 0x00001000-1, 0x80000000, RW_CB }, /* isr vector table */
  44. //here not set mmu
  45. //start_gcc.S Copy vector to the correct address
  46. };
  47. rt_hw_mmu_init(r6_mem_desc, sizeof(r6_mem_desc) / sizeof(r6_mem_desc[0]));
  48. }
  49. static void os_clock_init(void)
  50. {
  51. rt_uint32_t temp;
  52. volatile rt_uint32_t *temp_addr;
  53. /* reload value */
  54. temp = 0xB71B00 / RT_TICK_PER_SECOND;
  55. temp_addr = (rt_uint32_t *)(0x01C20C00 + 0x14);
  56. *temp_addr = temp;
  57. /* continuous | /2 | 24Mhz | reload*/
  58. temp = (0x00 << 7) | (0x01 << 4) | (0x01 << 2) | (0x00 << 1);
  59. temp_addr = (rt_uint32_t *)(0x01C20C00 + 0x10);
  60. *temp_addr &= 0xffffff00;
  61. *temp_addr |= temp;
  62. /* open timer irq */
  63. temp = 0x01 << 0;
  64. temp_addr = (rt_uint32_t *)(0x01C20C00);
  65. *temp_addr |= temp;
  66. /* set init value */
  67. temp_addr = (rt_uint32_t *)(0x01C20C00 + 0x18);
  68. *temp_addr = 0;
  69. /* begin run timer */
  70. temp = 0x01 << 0;
  71. temp_addr = (rt_uint32_t *)(0x01C20C00 + 0x10);
  72. *temp_addr |= temp;
  73. temp_addr = (rt_uint32_t *)(0x01C20C00);
  74. /* set irq handle */
  75. rt_hw_interrupt_install(TIMER0_INTERRUPT, os_clock_irq_handle, (void *)temp_addr, "timer");
  76. rt_hw_interrupt_umask(TIMER0_INTERRUPT);
  77. }
  78. void rt_hw_board_init(void)
  79. {
  80. mmu_init();
  81. rt_hw_interrupt_init();
  82. #ifdef RT_USING_HEAP
  83. /* init memory system */
  84. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  85. #endif
  86. /* init hardware interrupt */
  87. rt_hw_uart_init();
  88. #ifdef RT_USING_CONSOLE
  89. /* set console device */
  90. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  91. #endif /* RT_USING_CONSOLE */
  92. os_clock_init();
  93. #ifdef RT_USING_COMPONENTS_INIT
  94. rt_components_board_init();
  95. #endif
  96. }