board.c 2.1 KB

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