board.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 "board.h"
  17. #define TIMER_LOAD(hw_base) __REG32(hw_base + 0x00)
  18. #define TIMER_VALUE(hw_base) __REG32(hw_base + 0x04)
  19. #define TIMER_CTRL(hw_base) __REG32(hw_base + 0x08)
  20. #define TIMER_CTRL_ONESHOT (1 << 0)
  21. #define TIMER_CTRL_32BIT (1 << 1)
  22. #define TIMER_CTRL_DIV1 (0 << 2)
  23. #define TIMER_CTRL_DIV16 (1 << 2)
  24. #define TIMER_CTRL_DIV256 (2 << 2)
  25. #define TIMER_CTRL_IE (1 << 5) /* Interrupt Enable (versatile only) */
  26. #define TIMER_CTRL_PERIODIC (1 << 6)
  27. #define TIMER_CTRL_ENABLE (1 << 7)
  28. #define TIMER_INTCLR(hw_base) __REG32(hw_base + 0x0c)
  29. #define TIMER_RIS(hw_base) __REG32(hw_base + 0x10)
  30. #define TIMER_MIS(hw_base) __REG32(hw_base + 0x14)
  31. #define TIMER_BGLOAD(hw_base) __REG32(hw_base + 0x18)
  32. #define SYS_CTRL __REG32(REALVIEW_SCTL_BASE)
  33. #ifdef RT_USING_VMM
  34. #include <vmm.h>
  35. static rt_uint32_t timer_hw_base = 0;
  36. #define TIMER_HW_BASE (timer_hw_base)
  37. #else
  38. #define TIMER_HW_BASE REALVIEW_TIMER2_3_BASE
  39. #endif
  40. void rt_hw_timer_ack(void)
  41. {
  42. /* clear interrupt */
  43. TIMER_INTCLR(TIMER_HW_BASE) = 0x01;
  44. }
  45. static void rt_hw_timer_isr(int vector, void *param)
  46. {
  47. rt_tick_increase();
  48. rt_hw_timer_ack();
  49. }
  50. int rt_hw_timer_init(void)
  51. {
  52. rt_uint32_t val;
  53. #ifdef RT_USING_VMM
  54. {
  55. rt_uint32_t sys_ctrl;
  56. sys_ctrl = vmm_find_iomap("SYS_CTRL");
  57. __REG32(sys_ctrl) |= REALVIEW_REFCLK;
  58. }
  59. timer_hw_base = vmm_find_iomap("TIMER");
  60. #else
  61. SYS_CTRL |= REALVIEW_REFCLK;
  62. #endif
  63. /* Setup Timer0 for generating irq */
  64. val = TIMER_CTRL(TIMER_HW_BASE);
  65. val &= ~TIMER_CTRL_ENABLE;
  66. val |= (TIMER_CTRL_32BIT | TIMER_CTRL_PERIODIC | TIMER_CTRL_IE);
  67. TIMER_CTRL(TIMER_HW_BASE) = val;
  68. TIMER_LOAD(TIMER_HW_BASE) = 1000;
  69. /* enable timer */
  70. TIMER_CTRL(TIMER_HW_BASE) |= TIMER_CTRL_ENABLE;
  71. rt_hw_interrupt_install(IRQ_PBA8_TIMER2_3, rt_hw_timer_isr, RT_NULL, "tick");
  72. rt_hw_interrupt_umask(IRQ_PBA8_TIMER2_3);
  73. return 0;
  74. }
  75. INIT_BOARD_EXPORT(rt_hw_timer_init);
  76. /**
  77. * This function will initialize beaglebone board
  78. */
  79. void rt_hw_board_init(void)
  80. {
  81. rt_components_board_init();
  82. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  83. }
  84. /*@}*/