gtimer.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2006-2021, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2011-12-20 GuEe-GUI first version
  9. */
  10. #include <rtthread.h>
  11. #include <rthw.h>
  12. #include <gtimer.h>
  13. #include <cpuport.h>
  14. #ifdef RT_USING_KTIME
  15. #include <ktime.h>
  16. #endif
  17. #define EL1_PHY_TIMER_IRQ_NUM 30
  18. static volatile rt_uint64_t timer_step;
  19. static void rt_hw_timer_isr(int vector, void *parameter)
  20. {
  21. rt_hw_set_gtimer_val(timer_step);
  22. rt_tick_increase();
  23. }
  24. void rt_hw_gtimer_init(void)
  25. {
  26. rt_hw_interrupt_install(EL1_PHY_TIMER_IRQ_NUM, rt_hw_timer_isr, RT_NULL, "tick");
  27. rt_hw_isb();
  28. timer_step = rt_hw_get_gtimer_frq();
  29. rt_hw_dsb();
  30. timer_step /= RT_TICK_PER_SECOND;
  31. rt_hw_gtimer_local_enable();
  32. }
  33. void rt_hw_gtimer_local_enable(void)
  34. {
  35. rt_hw_gtimer_disable();
  36. rt_hw_set_gtimer_val(timer_step);
  37. rt_hw_interrupt_umask(EL1_PHY_TIMER_IRQ_NUM);
  38. #ifdef RT_USING_KTIME
  39. rt_ktime_cputimer_init();
  40. #endif
  41. rt_hw_gtimer_enable();
  42. }
  43. void rt_hw_gtimer_local_disable(void)
  44. {
  45. rt_hw_gtimer_disable();
  46. rt_hw_interrupt_mask(EL1_PHY_TIMER_IRQ_NUM);
  47. }