board.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 <imx_uart.h>
  16. #include <epit.h>
  17. #include <cortex_a.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. // Make sure the timer is off.
  27. HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 0;
  28. HW_ARMGLOBALTIMER_CONTROL.B.FCR0 =1;
  29. HW_ARMGLOBALTIMER_CONTROL.B.FCR1 =0;
  30. HW_ARMGLOBALTIMER_CONTROL.B.DBG_ENABLE =0;
  31. // Clear counter.
  32. HW_ARMGLOBALTIMER_COUNTER_HI_WR(0);
  33. HW_ARMGLOBALTIMER_COUNTER_LO_WR(0);
  34. // Now turn on the timer.
  35. HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 1;
  36. freq = get_main_clock(IPG_CLK);
  37. epit_init(HW_EPIT1, CLKSRC_IPG_CLK, freq / 1000000,
  38. SET_AND_FORGET, 10000, WAIT_MODE_EN | STOP_MODE_EN);
  39. epit_counter_enable(HW_EPIT1, 10000, IRQ_MODE);
  40. rt_hw_interrupt_install(IMX_INT_EPIT1, rt_hw_timer_isr, RT_NULL, "tick");
  41. rt_hw_interrupt_umask(IMX_INT_EPIT1);
  42. return 0;
  43. }
  44. INIT_BOARD_EXPORT(rt_hw_timer_init);
  45. /**
  46. * This function will initialize hardware board
  47. */
  48. void rt_hw_board_init(void)
  49. {
  50. enable_neon_fpu();
  51. disable_strict_align_check();
  52. rt_components_board_init();
  53. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  54. }
  55. /*@}*/