gtimer.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. #define EL1_PHY_TIMER_IRQ_NUM 30
  15. static volatile rt_uint64_t timer_step;
  16. static void rt_hw_timer_isr(int vector, void *parameter)
  17. {
  18. rt_hw_set_gtimer_val(timer_step);
  19. rt_tick_increase();
  20. }
  21. void rt_hw_gtimer_init(void)
  22. {
  23. rt_hw_interrupt_install(EL1_PHY_TIMER_IRQ_NUM, rt_hw_timer_isr, RT_NULL, "tick");
  24. __ISB();
  25. timer_step = rt_hw_get_gtimer_frq();
  26. __DSB();
  27. timer_step /= RT_TICK_PER_SECOND;
  28. rt_hw_gtimer_local_enable();
  29. }
  30. void rt_hw_gtimer_local_enable(void)
  31. {
  32. rt_hw_gtimer_disable();
  33. rt_hw_set_gtimer_val(timer_step);
  34. rt_hw_interrupt_umask(EL1_PHY_TIMER_IRQ_NUM);
  35. rt_hw_gtimer_enable();
  36. }
  37. void rt_hw_gtimer_local_disable(void)
  38. {
  39. rt_hw_gtimer_disable();
  40. rt_hw_interrupt_mask(EL1_PHY_TIMER_IRQ_NUM);
  41. }