board.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. #define TIMER_HW_BASE REALVIEW_TIMER2_3_BASE
  34. void rt_hw_timer_ack(void)
  35. {
  36. /* clear interrupt */
  37. TIMER_INTCLR(TIMER_HW_BASE) = 0x01;
  38. }
  39. static void rt_hw_timer_isr(int vector, void *param)
  40. {
  41. rt_tick_increase();
  42. rt_hw_timer_ack();
  43. }
  44. int rt_hw_timer_init(void)
  45. {
  46. rt_uint32_t val;
  47. SYS_CTRL |= REALVIEW_REFCLK;
  48. /* Setup Timer0 for generating irq */
  49. val = TIMER_CTRL(TIMER_HW_BASE);
  50. val &= ~TIMER_CTRL_ENABLE;
  51. val |= (TIMER_CTRL_32BIT | TIMER_CTRL_PERIODIC | TIMER_CTRL_IE);
  52. TIMER_CTRL(TIMER_HW_BASE) = val;
  53. TIMER_LOAD(TIMER_HW_BASE) = 1000;
  54. /* enable timer */
  55. TIMER_CTRL(TIMER_HW_BASE) |= TIMER_CTRL_ENABLE;
  56. rt_hw_interrupt_install(IRQ_PBA8_TIMER2_3, rt_hw_timer_isr, RT_NULL, "tick");
  57. rt_hw_interrupt_umask(IRQ_PBA8_TIMER2_3);
  58. return 0;
  59. }
  60. INIT_BOARD_EXPORT(rt_hw_timer_init);
  61. /**
  62. * This function will initialize beaglebone board
  63. */
  64. void rt_hw_board_init(void)
  65. {
  66. rt_components_board_init();
  67. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  68. }
  69. /*@}*/