1 {% import 'common.j2' as common %}
2 {% import 'c-common.j2' as c_common %}
3 {% set prefix = common.prefix %}
4 {% set ucprefix = common.ucprefix %}
5 {% set trace_type = cfg.trace.type %}
6 {% set cg_opts = cfg.options.code_generation_options %}
7 {% set def_stream_type = cg_opts.default_stream_type %}
8 {% set header_opts = cg_opts.header_options %}
9 #ifndef _{{ ucprefix }}H
10 #define _{{ ucprefix }}H
13 * The MIT License (MIT)
15 * Copyright (c) 2015-2020 Philippe Proulx <pproulx@efficios.com>
17 * Permission is hereby granted, free of charge, to any person obtaining
18 * a copy of this software and associated documentation files (the
19 * "Software"), to deal in the Software without restriction, including
20 * without limitation the rights to use, copy, modify, merge, publish,
21 * distribute, sublicense, and/or sell copies of the Software, and to
22 * permit persons to whom the Software is furnished to do so, subject to
23 * the following conditions:
25 * The above copyright notice and this permission notice shall be
26 * included in all copies or substantial portions of the Software.
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
32 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
33 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
39 * The following C code was generated by barectf v{{ barectf_version.__version__ }}
40 * on {{ common.gen_date }}.
42 * For more details, see <https://barectf.org/>.
51 {% if header_opts.identifier_prefix_definition %}
52 #define _BARECTF_PREFIX {{ prefix }}
54 {% if def_stream_type and header_opts.default_stream_type_name_definition %}
55 #define _BARECTF_DEFAULT_STREAM {{ def_stream_type.name }}
57 {% if def_stream_type %}
59 {% for ev_type in def_stream_type.event_types | sort %}
60 #define {{ prefix }}trace_{{ ev_type.name }} {{ c_common.trace_func_name(def_stream_type, ev_type) }}
64 struct {{ prefix }}ctx;
66 uint32_t {{ prefix }}packet_size(void *ctx);
67 int {{ prefix }}packet_is_full(void *ctx);
68 int {{ prefix }}packet_is_empty(void *ctx);
69 uint32_t {{ prefix }}packet_events_discarded(void *ctx);
70 uint8_t *{{ prefix }}packet_buf(void *ctx);
71 void {{ prefix }}packet_set_buf(void *ctx, uint8_t *buf, uint32_t buf_size);
72 uint32_t {{ prefix }}packet_buf_size(void *ctx);
73 int {{ prefix }}packet_is_open(void *ctx);
74 int {{ prefix }}is_in_tracing_section(void *ctx);
75 volatile const int *{{ prefix }}is_in_tracing_section_ptr(void *ctx);
76 int {{ prefix }}is_tracing_enabled(void *ctx);
77 void {{ prefix }}enable_tracing(void *ctx, int enable);
79 /* barectf platform callbacks */
80 struct {{ prefix }}platform_callbacks {
81 {% set clk_types = trace_type.clock_types %}
84 {% for clk_type in clk_types | sort %}
85 {{ cg_opts.clock_type_c_types[clk_type] }} (*{{ clk_type.name }}_clock_get_value)(void *);
89 /* is back-end full? */
90 int (*is_backend_full)(void *);
93 void (*open_packet)(void *);
96 void (*close_packet)(void *);
99 /* common barectf context */
100 struct {{ prefix }}ctx {
101 /* platform callbacks */
102 struct {{ prefix }}platform_callbacks cbs;
104 /* platform data (passed to callbacks) */
107 /* output buffer (will contain a CTF binary packet) */
110 /* packet's total size (bits) */
111 uint32_t packet_size;
113 /* packet's content size (bits) */
114 uint32_t content_size;
116 /* current position from beginning of packet (bits) */
119 /* size of packet header + context fields (content offset) */
120 uint32_t off_content;
122 /* discarded event counter */
123 uint32_t events_discarded;
125 /* current packet is open? */
128 /* in tracing code? */
129 volatile int in_tracing_section;
131 /* tracing is enabled? */
132 volatile int is_tracing_enabled;
134 /* use current/last event time when opening/closing packets */
135 int use_cur_last_event_ts;
138 {% for stream_type in trace_type.stream_types | sort %}
139 /* context for stream type `{{ stream_type.name }}` */
140 struct {{ prefix }}{{ stream_type.name }}_ctx {
142 struct {{ prefix }}ctx parent;
144 /* config-specific members follow */
145 {% if trace_type._pkt_header_ft %}
146 {% for member_name in trace_type._pkt_header_ft.members %}
147 uint32_t off_tph_{{ member_name }};
150 {% for member_name in stream_type._pkt_ctx_ft.members %}
151 uint32_t off_spc_{{ member_name }};
153 {% if stream_type.default_clock_type %}
154 {{ cg_opts.clock_type_c_types[stream_type.default_clock_type] }} cur_last_event_ts;
159 {% include 'c-ctx-init-func-proto.j2' %};
161 {% for stream_type in trace_type.stream_types | sort %}
162 {% include 'c-open-func-proto.j2' %};
164 {% include 'c-close-func-proto.j2' %};
165 {% for ev_type in stream_type.event_types | sort %}
167 {% include 'c-trace-func-proto.j2' %};
175 #endif /* _{{ ucprefix }}H */