drv_timer.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #define TIMER_IRQ 30
  16. static rt_uint64_t timerStep = 0;
  17. int rt_hw_get_gtimer_frq(void);
  18. void rt_hw_set_gtimer_val(rt_uint64_t value);
  19. int rt_hw_get_gtimer_val(void);
  20. int rt_hw_get_cntpct_val(void);
  21. void rt_hw_gtimer_enable(void);
  22. void rt_hw_gtimer_disable(void);
  23. static void rt_hw_timer_isr(int vector, void *param)
  24. {
  25. rt_hw_set_gtimer_val(timerStep);
  26. rt_tick_increase();
  27. }
  28. void rt_hw_timer_enable(void)
  29. {
  30. rt_hw_set_gtimer_val(timerStep);
  31. rt_hw_interrupt_umask(TIMER_IRQ);
  32. rt_hw_gtimer_enable();
  33. }
  34. int rt_hw_timer_init(void)
  35. {
  36. rt_hw_interrupt_install(TIMER_IRQ, rt_hw_timer_isr, RT_NULL, "tick");
  37. __ISB();
  38. timerStep = rt_hw_get_gtimer_frq();
  39. __DSB();
  40. timerStep /= RT_TICK_PER_SECOND;
  41. rt_hw_timer_enable();
  42. return 0;
  43. }
  44. INIT_BOARD_EXPORT(rt_hw_timer_init);