2 # The MIT License (MIT)
4 # Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com>
6 # Permission is hereby granted, free of charge, to any person obtaining
7 # a copy of this software and associated documentation files (the
8 # "Software"), to deal in the Software without restriction, including
9 # without limitation the rights to use, copy, modify, merge, publish,
10 # distribute, sublicense, and/or sell copies of the Software, and to
11 # permit persons to whom the Software is furnished to do so, subject to
12 # the following conditions:
14 # The above copyright notice and this permission notice shall be
15 # included in all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
21 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
22 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
23 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 {% import 'common.j2' as common %}
26 {% import 'c/common.j2' as c_common %}
27 {% set prefix = common.prefix %}
28 {% set ucprefix = common.ucprefix %}
29 {% set trace_type = cfg.trace.type %}
30 {% set cg_opts = cfg.options.code_generation_options %}
31 {% set def_stream_type = cg_opts.default_stream_type %}
32 {% set header_opts = cg_opts.header_options %}
33 #ifndef _{{ ucprefix }}H
34 #define _{{ ucprefix }}H
37 * The MIT License (MIT)
39 * Copyright (c) 2015-2020 Philippe Proulx <pproulx@efficios.com>
41 * Permission is hereby granted, free of charge, to any person obtaining
42 * a copy of this software and associated documentation files (the
43 * "Software"), to deal in the Software without restriction, including
44 * without limitation the rights to use, copy, modify, merge, publish,
45 * distribute, sublicense, and/or sell copies of the Software, and to
46 * permit persons to whom the Software is furnished to do so, subject to
47 * the following conditions:
49 * The above copyright notice and this permission notice shall be
50 * included in all copies or substantial portions of the Software.
52 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
53 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
54 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
55 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
56 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
57 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
58 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
61 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
63 * The following C code was generated by barectf v{{ barectf_version.__version__ }}
64 * on {{ common.gen_date }}.
66 * For more details, see <https://barectf.org/>.
75 {% if header_opts.identifier_prefix_definition %}
76 #define _BARECTF_PREFIX {{ prefix }}
78 {% if def_stream_type and header_opts.default_stream_type_name_definition %}
79 #define _BARECTF_DEFAULT_STREAM {{ def_stream_type.name }}
81 {% if def_stream_type %}
83 {% for ev_type in def_stream_type.event_types | sort %}
84 #define {{ prefix }}trace_{{ ev_type.name }} {{ c_common.trace_func_name(def_stream_type, ev_type) }}
88 struct {{ prefix }}ctx;
90 uint32_t {{ prefix }}packet_size(void *ctx);
91 int {{ prefix }}packet_is_full(void *ctx);
92 int {{ prefix }}packet_is_empty(void *ctx);
93 uint32_t {{ prefix }}packet_events_discarded(void *ctx);
94 uint8_t *{{ prefix }}packet_buf(void *ctx);
95 void {{ prefix }}packet_set_buf(void *ctx, uint8_t *buf, uint32_t buf_size);
96 uint32_t {{ prefix }}packet_buf_size(void *ctx);
97 int {{ prefix }}packet_is_open(void *ctx);
98 int {{ prefix }}is_in_tracing_section(void *ctx);
99 volatile const int *{{ prefix }}is_in_tracing_section_ptr(void *ctx);
100 int {{ prefix }}is_tracing_enabled(void *ctx);
101 void {{ prefix }}enable_tracing(void *ctx, int enable);
103 /* barectf platform callbacks */
104 struct {{ prefix }}platform_callbacks {
105 {% set clk_types = trace_type.clock_types %}
107 /* clock callbacks */
108 {% for clk_type in clk_types | sort %}
109 {{ cg_opts.clock_type_c_types[clk_type] }} (*{{ clk_type.name }}_clock_get_value)(void *);
113 /* is back-end full? */
114 int (*is_backend_full)(void *);
117 void (*open_packet)(void *);
120 void (*close_packet)(void *);
123 /* common barectf context */
124 struct {{ prefix }}ctx {
125 /* platform callbacks */
126 struct {{ prefix }}platform_callbacks cbs;
128 /* platform data (passed to callbacks) */
131 /* output buffer (will contain a CTF binary packet) */
134 /* packet's total size (bits) */
135 uint32_t packet_size;
137 /* packet's content size (bits) */
138 uint32_t content_size;
140 /* current position from beginning of packet (bits) */
143 /* size of packet header + context fields (content offset) */
144 uint32_t off_content;
146 /* discarded event counter */
147 uint32_t events_discarded;
149 /* current packet is open? */
152 /* in tracing code? */
153 volatile int in_tracing_section;
155 /* tracing is enabled? */
156 volatile int is_tracing_enabled;
158 /* use current/last event time when opening/closing packets */
159 int use_cur_last_event_ts;
162 {% for stream_type in trace_type.stream_types | sort %}
163 /* context for stream type `{{ stream_type.name }}` */
164 struct {{ prefix }}{{ stream_type.name }}_ctx {
166 struct {{ prefix }}ctx parent;
168 /* config-specific members follow */
169 {% if trace_type._pkt_header_ft %}
170 {% for member_name in trace_type._pkt_header_ft.members %}
171 uint32_t off_tph_{{ member_name }};
174 {% for member_name in stream_type._pkt_ctx_ft.members %}
175 uint32_t off_spc_{{ member_name }};
177 {% if stream_type.default_clock_type %}
178 {{ cg_opts.clock_type_c_types[stream_type.default_clock_type] }} cur_last_event_ts;
183 {% include 'c/ctx-init-func-proto.j2' %};
185 {% for stream_type in trace_type.stream_types | sort %}
186 {% include 'c/open-func-proto.j2' %};
188 {% include 'c/close-func-proto.j2' %};
189 {% for ev_type in stream_type.event_types | sort %}
191 {% include 'c/trace-func-proto.j2' %};
199 #endif /* _{{ ucprefix }}H */