board.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. void rt_hw_timer_isr(int vector, void *parameter)
  28. {
  29. ARM_TIMER_IRQCLR = 0;
  30. rt_tick_increase();
  31. }
  32. int rt_hw_timer_init(void)
  33. {
  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. rt_hw_interrupt_install(IRQ_ARM_TIMER, rt_hw_timer_isr, RT_NULL, "tick");
  45. rt_hw_interrupt_umask(IRQ_ARM_TIMER);
  46. return 0;
  47. }
  48. void vector_copy(void)
  49. {
  50. rt_memcpy((void*)0x0, (void*)0x8000, 64);
  51. }
  52. void rt_hw_board_init(void)
  53. {
  54. /* initialize hardware interrupt */
  55. rt_hw_interrupt_init();
  56. vector_copy();
  57. /* initialize uart */
  58. rt_hw_uart_init();
  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. #ifdef RT_USING_COMPONENTS_INIT
  71. rt_components_board_init();
  72. #endif
  73. }