1 /*
2  * Copyright (c) 2018 Oticon A/S
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <soc.h>
8 #include <cmdline.h>
9 #include <tracing_backend.h>
10 #include "tracing_backend_posix_bottom.h"
11 
12 static void *out_stream;
13 static const char *file_name;
14 
tracing_backend_posix_init(void)15 static void tracing_backend_posix_init(void)
16 {
17 	if (file_name == NULL) {
18 		file_name = "channel0_0";
19 	}
20 
21 	out_stream = tracing_backend_posix_init_bottom(file_name);
22 }
23 
tracing_backend_posix_output(const struct tracing_backend * backend,uint8_t * data,uint32_t length)24 static void tracing_backend_posix_output(
25 		const struct tracing_backend *backend,
26 		uint8_t *data, uint32_t length)
27 {
28 	ARG_UNUSED(backend);
29 
30 	tracing_backend_posix_output_bottom(data, length, out_stream);
31 }
32 
33 const struct tracing_backend_api tracing_backend_posix_api = {
34 	.init = tracing_backend_posix_init,
35 	.output  = tracing_backend_posix_output
36 };
37 
38 TRACING_BACKEND_DEFINE(tracing_backend_posix, tracing_backend_posix_api);
39 
tracing_backend_posix_option(void)40 void tracing_backend_posix_option(void)
41 {
42 	static struct args_struct_t tracing_backend_option[] = {
43 		{
44 			.manual = false,
45 			.is_mandatory = false,
46 			.is_switch = false,
47 			.option = "trace-file",
48 			.name = "file_name",
49 			.type = 's',
50 			.dest = (void *)&file_name,
51 			.call_when_found = NULL,
52 			.descript = "File name for tracing output.",
53 		},
54 		ARG_TABLE_ENDMARKER
55 	};
56 
57 	native_add_command_line_opts(tracing_backend_option);
58 }
59 
60 NATIVE_TASK(tracing_backend_posix_option, PRE_BOOT_1, 1);
61