Files
esp-idf/components/bt/common/ble_log/include/ble_log.h
T
Zhou Xiao 06478ec313 feat(ble_log): make TS sync unconditional with toggle-IO-only Kconfig
TS sync now always runs: the periodic tick (TS sample, OPEN transport
flush, internal snapshot) exists in every build, so the unified periodic
output no longer depends on BLE_LOG_TS_ENABLED and idle systems without
dispatch activity still flush every second.

- New BLE_LOG_TS_SYNC_TOGGLE_IO_ENABLED gates only the analyzer toggle
  IO (GPIO config, level writes, reset); with it unset, TS snapshots
  still sample the clocks and carry io_level = 0. BLE_LOG_TS_ENABLED
  keeps its prompt as a deprecated compatibility entry that selects
  BLE_LOG_TS_SYNC_TOGGLE_IO_ENABLED, so existing projects keep the old
  toggle behavior, and the TS trigger entries drop their dependency on
  it.
- ble_log_ts is no longer a separate module: its 95-line shell (clock
  sampling, toggle IO management) joins ble_log_rt.c, the only runtime
  that drives it. ble_log_ts_info_t moves to ble_log_lbm_v2.h (the
  snapshot interface that consumes it), the BLE_LOG_GET_LC_TS chip
  table moves next to its single caller, the init/deinit folds into
  ble_log_rt_init/deinit, the reset folds into ble_log_sync_enable, and
  the sampler becomes a void static now that its failure paths are gone.
- The runtime hook is gone: with the tick always present, its throttled
  defer-callback fallback for runtime-disabled sync served no one. The
  TS tick is the only periodic output source; ble_log_sync_enable(false)
  now means full periodic silence, and ble_log_rt_dispatch loses its
  return value. The version-info regression now arms the tick instead
  of the hook.
- BLE_LOG_GET_LC_TS branches on CONFIG_BT_DUAL_MODE_ARCH: the
  dual-mode-arch controllers (ESP32-H4, ESP32-S31) expose their link
  layer timer as r_sched_timer_getCurrentTimeU32, but the symbol is
  obfuscated in the current prebuilt libraries, so those targets report
  lc_ts = 0 for now; call the accessor once the libraries export it.
  The Gen 2 branch keeps r_ble_lll_timer_current_tick_get (defined by
  every C5/C6/C61/H2/H21 library, verified by nm and by linking
  ble_log_test for ESP32-C6); ESP32-H4 and ESP32-S31 fall out of it.
- ble_log_ts_info_update's old shape is gone entirely: the heap-allocated
  global ts_info and its critical section memcpy were leftovers from the
  pointer-return API; the sampler writes the caller object in place and
  keeps only the toggle IO phase as cross-call state. int_src_code is
  filled outside the critical section; the phase toggle stays inside to
  exclude the write in ble_log_sync_enable.

Idle systems no longer touch the controller clock: the legacy
accessors dereference controller state and INIT precedes controller
initialization, so the sampler returns lc_ts = 0 while the controller
is idle instead of reading it. The deferred dispatch callback drains
only the queue depth observed at entry and re-arms itself for arrivals
left behind, so it cannot monopolize the shared ESP timer task.
2026-09-10 15:39:56 +08:00

80 lines
2.6 KiB
C

/*
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __BLE_LOG_H__
#define __BLE_LOG_H__
/* ------- */
/* BLE Log */
/* ------- */
/* INCLUDE */
#include <stdbool.h>
#include <stdint.h>
#include <stddef.h>
/* TYPEDEF */
/* CRITICAL:
* The number of BLE Log source code will directly determine the number of statistic manager
* memory requirements, keep it as less as possible; it's recommended to use subcode for more
* log data structure decoding */
/* CRITICAL: this enum is a public ABI and must not be reordered or renamed.
* Its values are also the on-wire source IDs of protocol v7 frames. */
typedef enum {
/* Internal */
BLE_LOG_SRC_INTERNAL = 0,
/* Custom */
BLE_LOG_SRC_CUSTOM,
/* BLE Stack */
BLE_LOG_SRC_LL_TASK,
BLE_LOG_SRC_LL_HCI,
BLE_LOG_SRC_LL_ISR,
BLE_LOG_SRC_HOST,
BLE_LOG_SRC_HCI,
BLE_LOG_SRC_ENCODE,
/* UART redirection (PORT 0 only) */
BLE_LOG_SRC_REDIR,
BLE_LOG_SRC_MAX,
} ble_log_src_t;
/* HCI Log Direction */
#define BLE_LOG_HCI_DOWNSTREAM 0
#define BLE_LOG_HCI_UPSTREAM 1
/* Encodes HCI direction in payload byte 0 bit 7 for the synchronous copy,
* then restores the complete original HCI type byte. The caller guarantees a
* non-NULL buffer with len > 0. */
#define ble_log_write_hci(direction, data, len) do { \
uint8_t *const ble_log_hci_data__ = (data); \
const uint8_t ble_log_hci_type__ = ble_log_hci_data__[0]; \
ble_log_hci_data__[0] = (ble_log_hci_type__ & 0x7fU) | \
((direction) ? 0x80U : 0U); \
(void)ble_log_write_hex(BLE_LOG_SRC_HCI, ble_log_hci_data__, \
(len)); \
ble_log_hci_data__[0] = ble_log_hci_type__; \
} while (0)
/* INTERFACE */
bool ble_log_init(void);
void ble_log_deinit(void);
bool ble_log_enable(bool enable);
/* Blocking; call only from a caller-owned task, not an ISR or system callback. */
void ble_log_flush(void);
bool ble_log_write_hex(ble_log_src_t src_code, const uint8_t *addr, size_t len);
uint8_t *ble_log_claim(ble_log_src_t src_code, size_t max_len, uint32_t *handle);
void ble_log_commit(uint32_t handle, size_t actual_len);
void ble_log_dump_to_console(void);
#if CONFIG_BLE_LOG_LL_ENABLED
void ble_log_write_hex_ll(uint32_t len, const uint8_t *addr,
uint32_t len_append, const uint8_t *addr_append, uint32_t flag);
#endif /* CONFIG_BLE_LOG_LL_ENABLED */
bool ble_log_sync_enable(bool enable);
#endif /* __BLE_LOG_H__ */