cputimer.c 798 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. unsigned long rt_ktime_cputimer_getres(void)
  14. {
  15. return ((1000UL * 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. unsigned long rt_ktime_cputimer_getstep(void)
  26. {
  27. return rt_ktime_cputimer_getfrq() / RT_TICK_PER_SECOND;
  28. }
  29. void rt_ktime_cputimer_init(void)
  30. {
  31. _init_cnt = rt_hw_get_cntpct_val();
  32. }