board.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * File : board.c
  3. * This file is part of RT-Thread RTOS
  4. * COPYRIGHT (C) 2016, 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 <imx_uart.h>
  20. #include <epit.h>
  21. #include <cortex_a.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. // Make sure the timer is off.
  31. HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 0;
  32. HW_ARMGLOBALTIMER_CONTROL.B.FCR0 =1;
  33. HW_ARMGLOBALTIMER_CONTROL.B.FCR1 =0;
  34. HW_ARMGLOBALTIMER_CONTROL.B.DBG_ENABLE =0;
  35. // Clear counter.
  36. HW_ARMGLOBALTIMER_COUNTER_HI_WR(0);
  37. HW_ARMGLOBALTIMER_COUNTER_LO_WR(0);
  38. // Now turn on the timer.
  39. HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 1;
  40. freq = get_main_clock(IPG_CLK);
  41. epit_init(HW_EPIT1, CLKSRC_IPG_CLK, freq / 1000000,
  42. SET_AND_FORGET, 10000, WAIT_MODE_EN | STOP_MODE_EN);
  43. epit_counter_enable(HW_EPIT1, 10000, IRQ_MODE);
  44. rt_hw_interrupt_install(IMX_INT_EPIT1, rt_hw_timer_isr, RT_NULL, "tick");
  45. rt_hw_interrupt_umask(IMX_INT_EPIT1);
  46. return 0;
  47. }
  48. INIT_BOARD_EXPORT(rt_hw_timer_init);
  49. /**
  50. * This function will initialize hardware board
  51. */
  52. void rt_hw_board_init(void)
  53. {
  54. enable_neon_fpu();
  55. disable_strict_align_check();
  56. rt_components_board_init();
  57. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  58. }
  59. /*@}*/