1 /*
2  * Copyright (c) 2019 Intel corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_INCLUDE_TRACING_TRACING_FORMAT_H
8 #define ZEPHYR_INCLUDE_TRACING_TRACING_FORMAT_H
9 
10 #include <zephyr/toolchain/common.h>
11 
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15 
16 /**
17  * @brief Tracing format APIs
18  * @defgroup subsys_tracing_format_apis Tracing format APIs
19  * @ingroup subsys_tracing
20  * @{
21  */
22 
23 /** @brief A structure to represent tracing data format. */
24 typedef struct tracing_data {
25 	uint8_t *data;
26 	uint32_t length;
27 } __packed tracing_data_t;
28 
29 /**
30  * @brief Macro to trace a message in string format.
31  *
32  * @param fmt The format string.
33  * @param ... The format arguments.
34  */
35 #define TRACING_STRING(fmt, ...)					       \
36 	do {								       \
37 		tracing_format_string(fmt, ##__VA_ARGS__);		       \
38 	} while (false)
39 
40 /**
41  * @brief Macro to format data to tracing data format.
42  *
43  * @param x Data field.
44  */
45 #define TRACING_FORMAT_DATA(x)						       \
46 	((struct tracing_data){.data = (uint8_t *)&(x), .length = sizeof((x))})
47 
48 /**
49  * @brief Macro to trace a message in tracing data format.
50  *
51  * All the parameters should be struct tracing_data.
52  */
53 #define TRACING_DATA(...)						       \
54 	do {								       \
55 		struct tracing_data arg[] = {__VA_ARGS__};		       \
56 									       \
57 		tracing_format_data(arg, sizeof(arg) /			       \
58 				    sizeof(struct tracing_data));	       \
59 	} while (false)
60 
61 /**
62  * @brief Tracing a message in string format.
63  *
64  * @param str String to format.
65  * @param ... Variable length arguments.
66  */
67 void tracing_format_string(const char *str, ...);
68 
69 /**
70  * @brief Tracing a message in raw data format.
71  *
72  * @param data   Raw data to be traced.
73  * @param length Raw data length.
74  */
75 void tracing_format_raw_data(uint8_t *data, uint32_t length);
76 
77 /**
78  * @brief Tracing a message in tracing data format.
79  *
80  * @param tracing_data_array Tracing_data format data array to be traced.
81  * @param count Tracing_data array data count.
82  */
83 void tracing_format_data(tracing_data_t *tracing_data_array, uint32_t count);
84 
85 /** @} */ /* end of subsys_tracing_format_apis */
86 
87 #ifdef __cplusplus
88 }
89 #endif
90 
91 #endif /* ZEPHYR_INCLUDE_TRACING_TRACING_FORMAT_H */
92