1 /*
2  * Copyright (c) 2020 Intel Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/kernel.h>
8 #include <zephyr/sys_clock.h>
9 #include <zephyr/timing/timing.h>
10 
arch_timing_init(void)11 void arch_timing_init(void)
12 {
13 }
14 
arch_timing_start(void)15 void arch_timing_start(void)
16 {
17 }
18 
arch_timing_stop(void)19 void arch_timing_stop(void)
20 {
21 }
22 
arch_timing_counter_get(void)23 timing_t arch_timing_counter_get(void)
24 {
25 	return k_cycle_get_32();
26 }
27 
arch_timing_cycles_get(volatile timing_t * const start,volatile timing_t * const end)28 uint64_t arch_timing_cycles_get(volatile timing_t *const start,
29 				volatile timing_t *const end)
30 {
31 	return (*end - *start);
32 }
33 
34 
arch_timing_freq_get(void)35 uint64_t arch_timing_freq_get(void)
36 {
37 	return sys_clock_hw_cycles_per_sec();
38 }
39 
arch_timing_cycles_to_ns(uint64_t cycles)40 uint64_t arch_timing_cycles_to_ns(uint64_t cycles)
41 {
42 	return k_cyc_to_ns_floor64(cycles);
43 }
44 
arch_timing_cycles_to_ns_avg(uint64_t cycles,uint32_t count)45 uint64_t arch_timing_cycles_to_ns_avg(uint64_t cycles, uint32_t count)
46 {
47 	return arch_timing_cycles_to_ns(cycles) / count;
48 }
49 
arch_timing_freq_get_mhz(void)50 uint32_t arch_timing_freq_get_mhz(void)
51 {
52 	return (uint32_t)(arch_timing_freq_get() / 1000000U);
53 }
54