1
0

board.c 2.5 KB

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