1 /*
2  * Copyright (c) 2017 Oticon A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 #include <stdarg.h>
7 #include "bs_tracing.h"
8 
9 /*
10  * Provide the posix_print_* functions required from all POSIX arch boards
11  * (This functions provide a lower level, more direct, print mechanism than
12  * Zephyr's printk or logger and therefore can be relied on even if the kernel
13  * is down.
14  */
15 
16 #if (CONFIG_NATIVE_SIMULATOR_NUMBER_MCUS > 1)
17 static const char *cpu_prefix = "CPU";
18 static const unsigned int cpu_number = CONFIG_NATIVE_SIMULATOR_MCU_N;
19 #else
20 static const char *cpu_prefix;
21 static const unsigned int cpu_number;
22 #endif /* (CONFIG_NATIVE_SIMULATOR_NUMBER_MCUS > 1) */
23 
posix_vprint_error_and_exit(const char * format,va_list vargs)24 void posix_vprint_error_and_exit(const char *format, va_list vargs)
25 {
26 	bs_trace_vprint(BS_TRACE_ERROR, cpu_prefix, cpu_number, 0, BS_TRACE_AUTOTIME, 0,
27 			format, vargs);
28 }
29 
posix_vprint_warning(const char * format,va_list vargs)30 void posix_vprint_warning(const char *format, va_list vargs)
31 {
32 	bs_trace_vprint(BS_TRACE_WARNING, cpu_prefix, cpu_number, 0, BS_TRACE_AUTOTIME, 0,
33 				format, vargs);
34 }
35 
posix_vprint_trace(const char * format,va_list vargs)36 void posix_vprint_trace(const char *format, va_list vargs)
37 {
38 	bs_trace_vprint(BS_TRACE_RAW, cpu_prefix, cpu_number, 2, BS_TRACE_AUTOTIME, 0,
39 				format, vargs);
40 }
41 
posix_print_error_and_exit(const char * format,...)42 void posix_print_error_and_exit(const char *format, ...)
43 {
44 	va_list variable_argsp;
45 
46 	va_start(variable_argsp, format);
47 	posix_vprint_error_and_exit(format, variable_argsp);
48 	va_end(variable_argsp);
49 }
50 
posix_print_warning(const char * format,...)51 void posix_print_warning(const char *format, ...)
52 {
53 	va_list variable_argsp;
54 
55 	va_start(variable_argsp, format);
56 	bs_trace_vprint(BS_TRACE_WARNING, cpu_prefix, cpu_number, 0, BS_TRACE_AUTOTIME, 0,
57 			format, variable_argsp);
58 	va_end(variable_argsp);
59 }
60 
posix_print_trace(const char * format,...)61 void posix_print_trace(const char *format, ...)
62 {
63 	va_list variable_argsp;
64 
65 	va_start(variable_argsp, format);
66 	bs_trace_vprint(BS_TRACE_RAW, cpu_prefix, cpu_number, 2, BS_TRACE_AUTOTIME, 0,
67 			format, variable_argsp);
68 	va_end(variable_argsp);
69 }
70 
posix_trace_over_tty(int file_number)71 int posix_trace_over_tty(int file_number)
72 {
73 	return bs_trace_is_tty(file_number);
74 }
75 
nsi_vprint_error_and_exit(const char * format,va_list vargs)76 void nsi_vprint_error_and_exit(const char *format, va_list vargs)
77 {
78 	bs_trace_vprint(BS_TRACE_ERROR, cpu_prefix, cpu_number, 0, BS_TRACE_AUTOTIME, 0,
79 			format, vargs);
80 }
81 
nsi_vprint_warning(const char * format,va_list vargs)82 void nsi_vprint_warning(const char *format, va_list vargs)
83 {
84 	bs_trace_vprint(BS_TRACE_WARNING, cpu_prefix, cpu_number, 0, BS_TRACE_AUTOTIME, 0,
85 				format, vargs);
86 }
87 
nsi_vprint_trace(const char * format,va_list vargs)88 void nsi_vprint_trace(const char *format, va_list vargs)
89 {
90 	bs_trace_vprint(BS_TRACE_RAW, cpu_prefix, cpu_number, 2, BS_TRACE_AUTOTIME, 0,
91 				format, vargs);
92 }
93