board.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2012-11-20 Bernard the first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include "board.h"
  13. #define TIMER_LOAD(hw_base) __REG32(hw_base + 0x00)
  14. #define TIMER_VALUE(hw_base) __REG32(hw_base + 0x04)
  15. #define TIMER_CTRL(hw_base) __REG32(hw_base + 0x08)
  16. #define TIMER_CTRL_ONESHOT (1 << 0)
  17. #define TIMER_CTRL_32BIT (1 << 1)
  18. #define TIMER_CTRL_DIV1 (0 << 2)
  19. #define TIMER_CTRL_DIV16 (1 << 2)
  20. #define TIMER_CTRL_DIV256 (2 << 2)
  21. #define TIMER_CTRL_IE (1 << 5) /* Interrupt Enable (versatile only) */
  22. #define TIMER_CTRL_PERIODIC (1 << 6)
  23. #define TIMER_CTRL_ENABLE (1 << 7)
  24. #define TIMER_INTCLR(hw_base) __REG32(hw_base + 0x0c)
  25. #define TIMER_RIS(hw_base) __REG32(hw_base + 0x10)
  26. #define TIMER_MIS(hw_base) __REG32(hw_base + 0x14)
  27. #define TIMER_BGLOAD(hw_base) __REG32(hw_base + 0x18)
  28. #define SYS_CTRL __REG32(REALVIEW_SCTL_BASE)
  29. #define TIMER_HW_BASE REALVIEW_TIMER2_3_BASE
  30. void rt_hw_timer_ack(void)
  31. {
  32. /* clear interrupt */
  33. TIMER_INTCLR(TIMER_HW_BASE) = 0x01;
  34. }
  35. static void rt_hw_timer_isr(int vector, void *param)
  36. {
  37. rt_tick_increase();
  38. rt_hw_timer_ack();
  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. /**
  58. * This function will initialize beaglebone board
  59. */
  60. void rt_hw_board_init(void)
  61. {
  62. rt_components_board_init();
  63. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  64. }
  65. /*@}*/