board.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. #include <mmu.h>
  19. struct mem_desc platform_mem_desc[] = {
  20. {0x00000000, 0x80000000, 0x00000000, DEVICE_MEM},
  21. {0x80000000, 0xFFF00000, 0x80000000, NORMAL_MEM}
  22. };
  23. const rt_uint32_t platform_mem_desc_size = sizeof(platform_mem_desc)/sizeof(platform_mem_desc[0]);
  24. static void rt_hw_timer_isr(int vector, void *param)
  25. {
  26. rt_tick_increase();
  27. epit_get_compare_event(HW_EPIT1);
  28. }
  29. int rt_hw_timer_init(void)
  30. {
  31. uint32_t freq;
  32. // Make sure the timer is off.
  33. HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 0;
  34. HW_ARMGLOBALTIMER_CONTROL.B.FCR0 =1;
  35. HW_ARMGLOBALTIMER_CONTROL.B.FCR1 =0;
  36. HW_ARMGLOBALTIMER_CONTROL.B.DBG_ENABLE =0;
  37. // Clear counter.
  38. HW_ARMGLOBALTIMER_COUNTER_HI_WR(0);
  39. HW_ARMGLOBALTIMER_COUNTER_LO_WR(0);
  40. // Now turn on the timer.
  41. HW_ARMGLOBALTIMER_CONTROL.B.TIMER_ENABLE = 1;
  42. freq = get_main_clock(IPG_CLK);
  43. epit_init(HW_EPIT1, CLKSRC_IPG_CLK, freq / 1000000,
  44. SET_AND_FORGET, 10000, WAIT_MODE_EN | STOP_MODE_EN);
  45. epit_counter_enable(HW_EPIT1, 10000, IRQ_MODE);
  46. rt_hw_interrupt_install(IMX_INT_EPIT1, rt_hw_timer_isr, RT_NULL, "tick");
  47. rt_hw_interrupt_umask(IMX_INT_EPIT1);
  48. return 0;
  49. }
  50. INIT_BOARD_EXPORT(rt_hw_timer_init);
  51. /**
  52. * This function will initialize hardware board
  53. */
  54. void rt_hw_board_init(void)
  55. {
  56. enable_neon_fpu();
  57. disable_strict_align_check();
  58. rt_components_board_init();
  59. rt_console_set_device(RT_CONSOLE_DEVICE_NAME);
  60. }
  61. /*@}*/