drv_timer.c 925 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /*
  2. * Copyright (c) 2006-2022, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2018-11-22 Jesven first version
  9. */
  10. #include <rthw.h>
  11. #include <rtthread.h>
  12. #include <stdint.h>
  13. #include "cp15.h"
  14. #include "board.h"
  15. #include "gtimer.h"
  16. #define TIMER_IRQ 30
  17. static rt_uint64_t timerStep = 0;
  18. static void rt_hw_timer_isr(int vector, void *param)
  19. {
  20. rt_hw_set_gtimer_val(timerStep);
  21. rt_tick_increase();
  22. }
  23. void rt_hw_timer_enable(void)
  24. {
  25. rt_hw_set_gtimer_val(timerStep);
  26. rt_hw_interrupt_umask(TIMER_IRQ);
  27. rt_hw_gtimer_enable();
  28. }
  29. int rt_hw_timer_init(void)
  30. {
  31. rt_hw_interrupt_install(TIMER_IRQ, rt_hw_timer_isr, RT_NULL, "tick");
  32. __ISB();
  33. timerStep = rt_hw_get_gtimer_frq();
  34. __DSB();
  35. timerStep /= RT_TICK_PER_SECOND;
  36. rt_hw_timer_enable();
  37. return 0;
  38. }
  39. INIT_BOARD_EXPORT(rt_hw_timer_init);