board.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*
  2. * Copyright (c) 2006-2018, 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. #include <registers/regsarmglobaltimer.h>
  14. #include <registers/regsepit.h>
  15. #include <uart/imx_uart.h>
  16. #include <timer/epit.h>
  17. #include <core/cortex_a9.h>
  18. static void rt_hw_timer_isr(int vector, void *param)
  19. {
  20. rt_tick_increase();
  21. epit_get_compare_event(HW_EPIT1);
  22. }
  23. int rt_hw_timer_init(void)
  24. {
  25. uint32_t freq;
  26. // The ARM private peripheral clock is half the CPU clock.
  27. uint32_t periphClock = get_main_clock(CPU_CLK) / 2;
  28. uint32_t prescaler = (periphClock / 1000000) - 1;
  29. // Divide down the prescaler until it fits into 8 bits. We add up the number of ticks
  30. // it takes to equal a microsecond interval.
  31. while (prescaler > 0xff)
  32. {
  33. prescaler /= 2;
  34. }
  35. // Make sure the timer is off.
  36. HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 0;
  37. // Clear counter.
  38. HW_ARMGLOBALTIMER_COUNTERn_WR(0, 0);
  39. HW_ARMGLOBALTIMER_COUNTERn_WR(1, 0);
  40. // Set prescaler and clear other flags.
  41. HW_ARMGLOBALTIMER_CONTROL_WR(BF_ARMGLOBALTIMER_CONTROL_PRESCALER(prescaler));
  42. // Now turn on the timer.
  43. HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 1;
  44. freq = get_main_clock(IPG_CLK);
  45. epit_init(HW_EPIT1, CLKSRC_IPG_CLK, freq / 1000000,
  46. SET_AND_FORGET, 10000, WAIT_MODE_EN | STOP_MODE_EN);
  47. epit_counter_enable(HW_EPIT1, 10000, IRQ_MODE);
  48. rt_hw_interrupt_install(IMX_INT_EPIT1, rt_hw_timer_isr, RT_NULL, "tick");
  49. rt_hw_interrupt_umask(IMX_INT_EPIT1);
  50. return 0;
  51. }
  52. INIT_BOARD_EXPORT(rt_hw_timer_init);
  53. /**
  54. * This function will initialize beaglebone board
  55. */
  56. void rt_hw_board_init(void)
  57. {
  58. enable_neon_fpu();
  59. disable_strict_align_check();
  60. rt_components_board_init();
  61. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  62. }
  63. /*@}*/