board.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. */
  23. #include <rthw.h>
  24. #include <rtthread.h>
  25. #include "board.h"
  26. #include "drv_uart.h"
  27. #include "cp15.h"
  28. void rt_hw_timer_isr(int vector, void *parameter)
  29. {
  30. ARM_TIMER_IRQCLR = 0;
  31. rt_tick_increase();
  32. }
  33. int rt_hw_timer_init(void)
  34. {
  35. /* timer_clock = apb_clock/(pre_divider + 1) */
  36. ARM_TIMER_PREDIV = (250 - 1);
  37. ARM_TIMER_RELOAD = 0;
  38. ARM_TIMER_LOAD = 0;
  39. ARM_TIMER_IRQCLR = 0;
  40. ARM_TIMER_CTRL = 0;
  41. ARM_TIMER_RELOAD = 10000;
  42. ARM_TIMER_LOAD = 10000;
  43. /* 23-bit counter, enable interrupt, enable timer */
  44. ARM_TIMER_CTRL = (1 << 1) | (1 << 5) | (1 << 7);
  45. rt_hw_interrupt_install(IRQ_ARM_TIMER, rt_hw_timer_isr, RT_NULL, "tick");
  46. rt_hw_interrupt_umask(IRQ_ARM_TIMER);
  47. return 0;
  48. }
  49. void vector_copy(void)
  50. {
  51. rt_memcpy((void*)0x0, (void*)0x8000, 64);
  52. }
  53. void rt_hw_board_init(void)
  54. {
  55. /* initialize hardware interrupt */
  56. rt_hw_interrupt_init();
  57. rt_hw_vector_init();
  58. /* initialize uart */
  59. rt_hw_uart_init();
  60. #ifdef RT_USING_CONSOLE
  61. /* set console device */
  62. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  63. #endif /* RT_USING_CONSOLE */
  64. #ifdef RT_USING_HEAP
  65. /* initialize memory system */
  66. rt_kprintf("heap: 0x%08x - 0x%08x\n", RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  67. rt_system_heap_init(RT_HW_HEAP_BEGIN, RT_HW_HEAP_END);
  68. #endif
  69. /* initialize timer for os tick */
  70. rt_hw_timer_init();
  71. #ifdef RT_USING_COMPONENTS_INIT
  72. rt_components_board_init();
  73. #endif
  74. }