cputimer.c 686 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Copyright (c) 2006-2023, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: Apache-2.0
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2023-07-10 xqyjlj The first version.
  9. */
  10. #include "gtimer.h"
  11. #include "ktime.h"
  12. static volatile unsigned long _init_cnt = 0;
  13. rt_uint64_t rt_ktime_cputimer_getres(void)
  14. {
  15. return ((1000ULL * 1000 * 1000) * RT_KTIME_RESMUL) / rt_hw_get_gtimer_frq();
  16. }
  17. unsigned long rt_ktime_cputimer_getfrq(void)
  18. {
  19. return rt_hw_get_gtimer_frq();
  20. }
  21. unsigned long rt_ktime_cputimer_getcnt(void)
  22. {
  23. return rt_hw_get_cntpct_val() - _init_cnt;
  24. }
  25. void rt_ktime_cputimer_init(void)
  26. {
  27. _init_cnt = rt_hw_get_cntpct_val();
  28. }