{# # The MIT License (MIT) # # Copyright (c) 2020 Philippe Proulx # # Permission is hereby granted, free of charge, to any person obtaining # a copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, # distribute, sublicense, and/or sell copies of the Software, and to # permit persons to whom the Software is furnished to do so, subject to # the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #} {% import 'common.j2' as common %} {% import 'c/common.j2' as c_common %} {% set prefix = common.prefix %} {% set ucprefix = common.ucprefix %} {% set trace_type = cfg.trace.type %} {% set cg_opts = cfg.options.code_generation_options %} {% set def_stream_type = cg_opts.default_stream_type %} {% set header_opts = cg_opts.header_options %} #ifndef _{{ ucprefix }}H #define _{{ ucprefix }}H {% include 'licence-header.j2' %} #include #ifdef __cplusplus extern "C" { #endif {% if header_opts.identifier_prefix_definition %} #define _BARECTF_PREFIX {{ prefix }} {% endif %} {% if def_stream_type and header_opts.default_stream_type_name_definition %} #define _BARECTF_DEFAULT_STREAM {{ def_stream_type.name }} {% endif %} {% if def_stream_type %} {% for ev_type in def_stream_type.event_types | sort %} #define {{ prefix }}trace_{{ ev_type.name }} {{ c_common.trace_func_name(def_stream_type, ev_type) }} {% endfor %} {% endif %} struct {{ prefix }}ctx; uint32_t {{ prefix }}packet_size(void *ctx); int {{ prefix }}packet_is_full(void *ctx); int {{ prefix }}packet_is_empty(void *ctx); uint32_t {{ prefix }}packet_events_discarded(void *ctx); uint8_t *{{ prefix }}packet_buf(void *ctx); void {{ prefix }}packet_set_buf(void *ctx, uint8_t *buf, uint32_t buf_size); uint32_t {{ prefix }}packet_buf_size(void *ctx); int {{ prefix }}packet_is_open(void *ctx); int {{ prefix }}is_in_tracing_section(void *ctx); volatile const int *{{ prefix }}is_in_tracing_section_ptr(void *ctx); int {{ prefix }}is_tracing_enabled(void *ctx); void {{ prefix }}enable_tracing(void *ctx, int enable); /* barectf platform callbacks */ struct {{ prefix }}platform_callbacks { {% set clk_types = trace_type.clock_types %} {% if clk_types %} /* clock callbacks */ {% for clk_type in clk_types | sort %} {{ cg_opts.clock_type_c_types[clk_type] }} (*{{ clk_type.name }}_clock_get_value)(void *); {% endfor %} {% endif %} /* is back-end full? */ int (*is_backend_full)(void *); /* open packet */ void (*open_packet)(void *); /* close packet */ void (*close_packet)(void *); }; /* common barectf context */ struct {{ prefix }}ctx { /* platform callbacks */ struct {{ prefix }}platform_callbacks cbs; /* platform data (passed to callbacks) */ void *data; /* output buffer (will contain a CTF binary packet) */ uint8_t *buf; /* packet's total size (bits) */ uint32_t packet_size; /* packet's content size (bits) */ uint32_t content_size; /* current position from beginning of packet (bits) */ uint32_t at; /* size of packet header + context fields (content offset) */ uint32_t off_content; /* discarded event counter */ uint32_t events_discarded; /* current packet is open? */ int packet_is_open; /* in tracing code? */ volatile int in_tracing_section; /* tracing is enabled? */ volatile int is_tracing_enabled; /* use current/last event time when opening/closing packets */ int use_cur_last_event_ts; }; {% for stream_type in trace_type.stream_types | sort %} /* context for stream type `{{ stream_type.name }}` */ struct {{ prefix }}{{ stream_type.name }}_ctx { /* parent */ struct {{ prefix }}ctx parent; /* config-specific members follow */ {% if trace_type._pkt_header_ft %} {% for member_name in trace_type._pkt_header_ft.members %} uint32_t off_tph_{{ member_name }}; {% endfor %} {% endif %} {% for member_name in stream_type._pkt_ctx_ft.members %} uint32_t off_spc_{{ member_name }}; {% endfor %} {% if stream_type.default_clock_type %} {{ cg_opts.clock_type_c_types[stream_type.default_clock_type] }} cur_last_event_ts; {% endif %} }; {% endfor %} {% include 'c/ctx-init-func-proto.j2' %}; {% for stream_type in trace_type.stream_types | sort %} {% include 'c/open-func-proto.j2' %}; {% include 'c/close-func-proto.j2' %}; {% for ev_type in stream_type.event_types | sort %} {% include 'c/trace-func-proto.j2' %}; {% endfor %} {% endfor %} #ifdef __cplusplus } #endif #endif /* _{{ ucprefix }}H */