board.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2012, RT-Thread Development Team
  5. *
  6. * The license and distribution terms for this file may be
  7. * found in the file LICENSE in this distribution or at
  8. * http://www.rt-thread.org/license/LICENSE
  9. *
  10. * Change Logs:
  11. * Date Author Notes
  12. * 2012-11-20 Bernard the first version
  13. */
  14. #include <rthw.h>
  15. #include <rtthread.h>
  16. #include <components.h>
  17. #include "board.h"
  18. #define TIMER_LOAD(hw_base) __REG32(hw_base + 0x00)
  19. #define TIMER_VALUE(hw_base) __REG32(hw_base + 0x04)
  20. #define TIMER_CTRL(hw_base) __REG32(hw_base + 0x08)
  21. #define TIMER_CTRL_ONESHOT (1 << 0)
  22. #define TIMER_CTRL_32BIT (1 << 1)
  23. #define TIMER_CTRL_DIV1 (0 << 2)
  24. #define TIMER_CTRL_DIV16 (1 << 2)
  25. #define TIMER_CTRL_DIV256 (2 << 2)
  26. #define TIMER_CTRL_IE (1 << 5) /* Interrupt Enable (versatile only) */
  27. #define TIMER_CTRL_PERIODIC (1 << 6)
  28. #define TIMER_CTRL_ENABLE (1 << 7)
  29. #define TIMER_INTCLR(hw_base) __REG32(hw_base + 0x0c)
  30. #define TIMER_RIS(hw_base) __REG32(hw_base + 0x10)
  31. #define TIMER_MIS(hw_base) __REG32(hw_base + 0x14)
  32. #define TIMER_BGLOAD(hw_base) __REG32(hw_base + 0x18)
  33. #define SYS_CTRL __REG32(REALVIEW_SCTL_BASE)
  34. #ifdef RT_USING_VMM
  35. #include <vmm.h>
  36. static rt_uint32_t timer_hw_base = 0;
  37. #define TIMER_HW_BASE (timer_hw_base)
  38. #else
  39. #define TIMER_HW_BASE REALVIEW_TIMER2_3_BASE
  40. #endif
  41. void rt_hw_timer_ack(void)
  42. {
  43. /* clear interrupt */
  44. TIMER_INTCLR(TIMER_HW_BASE) = 0x01;
  45. }
  46. static void rt_hw_timer_isr(int vector, void *param)
  47. {
  48. rt_tick_increase();
  49. rt_hw_timer_ack();
  50. }
  51. int rt_hw_timer_init(void)
  52. {
  53. rt_uint32_t val;
  54. #ifdef RT_USING_VMM
  55. {
  56. rt_uint32_t sys_ctrl;
  57. sys_ctrl = vmm_find_iomap("SYS_CTRL");
  58. __REG32(sys_ctrl) |= REALVIEW_REFCLK;
  59. }
  60. timer_hw_base = vmm_find_iomap("TIMER");
  61. #else
  62. SYS_CTRL |= REALVIEW_REFCLK;
  63. #endif
  64. /* Setup Timer0 for generating irq */
  65. val = TIMER_CTRL(TIMER_HW_BASE);
  66. val &= ~TIMER_CTRL_ENABLE;
  67. val |= (TIMER_CTRL_32BIT | TIMER_CTRL_PERIODIC | TIMER_CTRL_IE);
  68. TIMER_CTRL(TIMER_HW_BASE) = val;
  69. TIMER_LOAD(TIMER_HW_BASE) = 1000;
  70. /* enable timer */
  71. TIMER_CTRL(TIMER_HW_BASE) |= TIMER_CTRL_ENABLE;
  72. rt_hw_interrupt_install(IRQ_PBA8_TIMER2_3, rt_hw_timer_isr, RT_NULL, "tick");
  73. rt_hw_interrupt_umask(IRQ_PBA8_TIMER2_3);
  74. return 0;
  75. }
  76. INIT_BOARD_EXPORT(rt_hw_timer_init);
  77. /**
  78. * This function will initialize beaglebone board
  79. */
  80. void rt_hw_board_init(void)
  81. {
  82. rt_components_board_init();
  83. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  84. }
  85. /*@}*/