Commit | Line | Data |
---|---|---|
fdbf8740 PP |
1 | {# |
2 | # The MIT License (MIT) | |
3 | # | |
4 | # Copyright (c) 2020 Philippe Proulx <pproulx@efficios.com> | |
5 | # | |
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: | |
13 | # | |
14 | # The above copyright notice and this permission notice shall be | |
15 | # included in all copies or substantial portions of the Software. | |
16 | # | |
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. | |
24 | #} | |
1b49c7b8 | 25 | {% import 'common.j2' as common %} |
d6483c83 | 26 | {% import 'c/common.j2' as c_common %} |
1b49c7b8 PP |
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 %} | |
e8f0d548 | 31 | {% set def_dst = cg_opts.default_data_stream_type %} |
1b49c7b8 | 32 | {% set header_opts = cg_opts.header_options %} |
e18cf9d6 | 33 | {% set const_params = false %} |
1b49c7b8 PP |
34 | #ifndef _{{ ucprefix }}H |
35 | #define _{{ ucprefix }}H | |
36 | ||
1cf325c4 | 37 | {% include 'license-header.j2' %} |
e72875eb | 38 | |
1b49c7b8 PP |
39 | |
40 | #include <stdint.h> | |
41 | ||
42 | #ifdef __cplusplus | |
43 | extern "C" { | |
44 | #endif | |
45 | ||
46 | {% if header_opts.identifier_prefix_definition %} | |
3b04a0d6 | 47 | /* Backward compatibility */ |
1b49c7b8 | 48 | #define _BARECTF_PREFIX {{ prefix }} |
3b04a0d6 PP |
49 | |
50 | #define _BARECTF_IDENTIFIER_PREFIX {{ prefix }} | |
1b49c7b8 | 51 | {% endif %} |
e8f0d548 | 52 | {% if def_dst and header_opts.default_data_stream_type_name_definition %} |
3b04a0d6 | 53 | /* Backward compatibility */ |
e8f0d548 | 54 | #define _BARECTF_DEFAULT_STREAM {{ def_dst.name }} |
3b04a0d6 PP |
55 | |
56 | #define _BARECTF_DEFAULT_DATA_STREAM_TYPE_NAME {{ def_dst.name }} | |
1b49c7b8 | 57 | {% endif %} |
e8f0d548 | 58 | {% if def_dst %} |
1b49c7b8 | 59 | |
e8f0d548 PP |
60 | {% for ert in def_dst.event_record_types | sort %} |
61 | #define {{ prefix }}trace_{{ ert.name }} {{ c_common.trace_func_name(def_dst, ert) }} | |
d6483c83 | 62 | {% endfor %} |
1b49c7b8 PP |
63 | {% endif %} |
64 | ||
65 | struct {{ prefix }}ctx; | |
66 | ||
e18cf9d6 PP |
67 | uint32_t {{ prefix }}packet_size(const void *ctx); |
68 | int {{ prefix }}packet_is_full(const void *ctx); | |
69 | int {{ prefix }}packet_is_empty(const void *ctx); | |
70 | uint32_t {{ prefix }}packet_events_discarded(const void *ctx); | |
71 | uint8_t *{{ prefix }}packet_buf(const void *ctx); | |
1b49c7b8 | 72 | void {{ prefix }}packet_set_buf(void *ctx, uint8_t *buf, uint32_t buf_size); |
e18cf9d6 PP |
73 | uint32_t {{ prefix }}packet_buf_size(const void *ctx); |
74 | int {{ prefix }}packet_is_open(const void *ctx); | |
75 | int {{ prefix }}is_in_tracing_section(const void *ctx); | |
76 | volatile const int *{{ prefix }}is_in_tracing_section_ptr(const void *ctx); | |
77 | int {{ prefix }}is_tracing_enabled(const void *ctx); | |
1b49c7b8 PP |
78 | void {{ prefix }}enable_tracing(void *ctx, int enable); |
79 | ||
80 | /* barectf platform callbacks */ | |
81 | struct {{ prefix }}platform_callbacks { | |
82 | {% set clk_types = trace_type.clock_types %} | |
83 | {% if clk_types %} | |
a5435dc8 | 84 | /* Clock source callbacks */ |
d6483c83 | 85 | {% for clk_type in clk_types | sort %} |
1b49c7b8 | 86 | {{ cg_opts.clock_type_c_types[clk_type] }} (*{{ clk_type.name }}_clock_get_value)(void *); |
d6483c83 | 87 | {% endfor %} |
1b49c7b8 PP |
88 | |
89 | {% endif %} | |
644b3b4f | 90 | /* Is the back end full? */ |
1b49c7b8 PP |
91 | int (*is_backend_full)(void *); |
92 | ||
9318c705 | 93 | /* Open packet */ |
1b49c7b8 PP |
94 | void (*open_packet)(void *); |
95 | ||
9318c705 | 96 | /* Close packet */ |
1b49c7b8 PP |
97 | void (*close_packet)(void *); |
98 | }; | |
99 | ||
9318c705 | 100 | /* Common barectf context */ |
1b49c7b8 | 101 | struct {{ prefix }}ctx { |
9318c705 | 102 | /* Platform callbacks */ |
1b49c7b8 PP |
103 | struct {{ prefix }}platform_callbacks cbs; |
104 | ||
9318c705 | 105 | /* Platform data (passed to callbacks) */ |
1b49c7b8 PP |
106 | void *data; |
107 | ||
9318c705 | 108 | /* Output buffer (will contain a CTF binary packet) */ |
1b49c7b8 PP |
109 | uint8_t *buf; |
110 | ||
9318c705 | 111 | /* Packet's total size (bits) */ |
1b49c7b8 PP |
112 | uint32_t packet_size; |
113 | ||
9318c705 | 114 | /* Packet's content size (bits) */ |
1b49c7b8 PP |
115 | uint32_t content_size; |
116 | ||
9318c705 | 117 | /* Current position from beginning of packet (bits) */ |
1b49c7b8 PP |
118 | uint32_t at; |
119 | ||
9318c705 | 120 | /* Size of packet header + context fields (content offset) */ |
1b49c7b8 PP |
121 | uint32_t off_content; |
122 | ||
e8f0d548 | 123 | /* Discarded event records counter snapshot */ |
1b49c7b8 PP |
124 | uint32_t events_discarded; |
125 | ||
9318c705 | 126 | /* Current packet is open? */ |
1b49c7b8 PP |
127 | int packet_is_open; |
128 | ||
9318c705 | 129 | /* In tracing code? */ |
1b49c7b8 PP |
130 | volatile int in_tracing_section; |
131 | ||
9318c705 | 132 | /* Tracing is enabled? */ |
1b49c7b8 PP |
133 | volatile int is_tracing_enabled; |
134 | ||
462e49b3 | 135 | /* Use current/last event record timestamp when opening/closing packets */ |
1b49c7b8 PP |
136 | int use_cur_last_event_ts; |
137 | }; | |
138 | ||
e8f0d548 PP |
139 | {% for dst in trace_type.data_stream_types | sort %} |
140 | /* Context for data stream type `{{ dst.name }}` */ | |
141 | struct {{ prefix }}{{ dst.name }}_ctx { | |
9318c705 | 142 | /* Parent */ |
1b49c7b8 PP |
143 | struct {{ prefix }}ctx parent; |
144 | ||
9318c705 | 145 | /* Config-specific members follow */ |
d6483c83 PP |
146 | {% if trace_type._pkt_header_ft %} |
147 | {% for member_name in trace_type._pkt_header_ft.members %} | |
1c650e47 | 148 | uint32_t off_ph_{{ member_name }}; |
d6483c83 PP |
149 | {% endfor %} |
150 | {% endif %} | |
e8f0d548 | 151 | {% for member_name in dst._pkt_ctx_ft.members %} |
1c650e47 | 152 | uint32_t off_pc_{{ member_name }}; |
d6483c83 | 153 | {% endfor %} |
e8f0d548 PP |
154 | {% if dst.default_clock_type %} |
155 | {{ cg_opts.clock_type_c_types[dst.default_clock_type] }} cur_last_event_ts; | |
d6483c83 | 156 | {% endif %} |
1b49c7b8 PP |
157 | }; |
158 | ||
159 | {% endfor %} | |
d6483c83 | 160 | {% include 'c/ctx-init-func-proto.j2' %}; |
1b49c7b8 | 161 | |
e8f0d548 | 162 | {% for dst in trace_type.data_stream_types | sort %} |
d6483c83 | 163 | {% include 'c/open-func-proto.j2' %}; |
1b49c7b8 | 164 | |
d6483c83 | 165 | {% include 'c/close-func-proto.j2' %}; |
e8f0d548 | 166 | {% for ert in dst.event_record_types | sort %} |
1b49c7b8 | 167 | |
d6483c83 PP |
168 | {% include 'c/trace-func-proto.j2' %}; |
169 | {% endfor %} | |
1b49c7b8 PP |
170 | {% endfor %} |
171 | ||
172 | #ifdef __cplusplus | |
173 | } | |
174 | #endif | |
175 | ||
176 | #endif /* _{{ ucprefix }}H */ |