/*
 * SPDX-License-Identifier: Apache-2.0
 * Copyright (c) 2026 Embedya.
 *
 * TraxProbe <-> ESP-IDF esp_trace core glue (inert adapters).
 *
 * TraxProbe injects its FreeRTOS trace hooks through ESP-IDF's supported
 * external trace-library mechanism (CONFIG_ESP_TRACE_LIB_EXTERNAL):
 * FreeRTOSConfig.h -> esp_trace_freertos.h -> esp_trace_freertos_impl.h.
 *
 * Selecting that option also force-enables the esp_trace *core*
 * (CONFIG_ESP_TRACE_ENABLE, Kconfig: `default !ESP_TRACE_LIB_NONE`). The core's
 * boot-time ESP_SYSTEM_INIT_FN runs on every core before app_main() and looks
 * up an encoder named CONFIG_ESP_TRACE_LIB_NAME ("ext") and a transport named
 * CONFIG_ESP_TRACE_TRANSPORT_NAME ("none") in the link-time registry. ESP-IDF
 * provides neither (the "ext" encoder is the external library's responsibility,
 * and there is no built-in "none" transport -- only "apptrace"). The lookup then
 * fails with ESP_ERR_NOT_FOUND and cpu_start aborts before app_main:
 *
 *     E esp_trace_core: Encoder 'ext' or transport 'none' not found
 *     E cpu_start: init function ... has failed (0x105), aborting
 *
 * TraxProbe does NOT route trace data through the esp_trace core: it owns its
 * own ring buffer and USB-Serial/JTAG transport, and the FreeRTOS trace macros
 * call into TraxProbe directly, never through esp_trace_write(). We therefore
 * register inert (all-NULL) encoder/transport vtables purely to satisfy the
 * core's startup lookup so it initialises successfully and then stays dormant.
 * esp_trace_core.c invokes a vtable slot only when it is non-NULL, so empty
 * vtables are never called and add no overhead to the trace path.
 *
 * NOTE: This translation unit must be force-linked (the descriptors are
 * referenced only by the linker, not by code). The TraxProbe component is built
 * with WHOLE_ARCHIVE TRUE so the .esp_trace_{encoder,transport}_desc records are
 * pulled into the image, where esp_trace's linker.lf (archive: *) KEEPs them.
 */

/* Self-gating translation unit: this file is ESP-IDF SDK glue -- it needs
 * sdkconfig.h and esp_trace's registry headers, which exist only inside an
 * ESP-IDF build. ESP_PLATFORM is the canonical IDF-defined marker, so on any
 * non-IDF target (e.g. an Eclipse/CDT STM32 project that compiles the shared
 * TraxProbe tree wholesale) the whole file is empty and never reaches
 * sdkconfig.h. */
#if defined(ESP_PLATFORM)

#include "sdkconfig.h"

#if defined(CONFIG_ESP_TRACE_ENABLE)

#include "esp_trace_registry.h"

#if defined(CONFIG_ESP_TRACE_LIB_EXTERNAL)
/* Inert "ext" encoder. All vtable slots NULL -> the core never invokes them. */
static const esp_trace_encoder_vtable_t s_trax_noop_encoder_vt = { 0 };
ESP_TRACE_REGISTER_ENCODER("ext", &s_trax_noop_encoder_vt);
#endif /* CONFIG_ESP_TRACE_LIB_EXTERNAL */

#if defined(CONFIG_ESP_TRACE_TRANSPORT_NONE)
/* Inert "none" transport. ESP-IDF ships no built-in "none" transport, so the
 * core would otherwise fail to resolve CONFIG_ESP_TRACE_TRANSPORT_NAME. */
static const esp_trace_transport_vtable_t s_trax_noop_transport_vt = { 0 };
ESP_TRACE_REGISTER_TRANSPORT("none", &s_trax_noop_transport_vt);
#endif /* CONFIG_ESP_TRACE_TRANSPORT_NONE */

#endif /* CONFIG_ESP_TRACE_ENABLE */

#endif /* ESP_PLATFORM */
