1 /*
2  * Copyright (c) 2012-2014 Wind River Systems, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _LATENCY_MEASURE_UNIT_H
8 #define _LATENCY_MEASURE_UNIT_H
9 /*
10  * @brief This file contains function declarations, macroses and inline functions
11  * used in latency measurement.
12  */
13 
14 #include <zephyr/timing/timing.h>
15 #include <zephyr/sys/printk.h>
16 #include <stdio.h>
17 #include <zephyr/timestamp.h>
18 
19 #define INT_IMM8_OFFSET   1
20 #define IRQ_PRIORITY      3
21 
22 extern int error_count;
23 
24 #define PRINT_OVERFLOW_ERROR()			\
25 	printk(" Error: tick occurred\n")
26 
27 #ifdef CSV_FORMAT_OUTPUT
28 #define FORMAT "%-60s,%8u,%8u\n"
29 #else
30 #define FORMAT "%-60s:%8u cycles , %8u ns\n"
31 #endif
32 
33 #define PRINT_F(...)						\
34 	{							\
35 		char sline[256]; 				\
36 		snprintk(sline, 254, FORMAT, ##__VA_ARGS__); 	\
37 		printk("%s", sline);			     	\
38 	}
39 
40 #define PRINT_STATS(x, y) \
41 	PRINT_F(x, y, (uint32_t)timing_cycles_to_ns(y))
42 
43 #define PRINT_STATS_AVG(x, y, counter)	\
44 	PRINT_F(x, y / counter, (uint32_t)timing_cycles_to_ns_avg(y, counter));
45 
46 
47 #endif
48