feat(ble_audio): Support log compression for ISO & LE Audio logs

This commit is contained in:
Liu Linyan
2026-05-07 15:05:57 +08:00
parent c9ce65f6c1
commit cae52c454b
56 changed files with 578 additions and 65 deletions
@@ -15,6 +15,16 @@ set(HOST_LOG_INDEX_HEADER "\"\"")
set(BLE_HOST_TAGS "") set(BLE_HOST_TAGS "")
set(BLE_HOST_TAGS_PRESERVE "") set(BLE_HOST_TAGS_PRESERVE "")
# default config value for ble iso module
# (esp_ble_iso owns the unified LOG_* family; consumers like esp_ble_audio
# and future HID-over-ISO compile under the same BLE_ISO module so that all
# share one iso_log_index.h and one log-id counter — no per-consumer
# bookkeeping, no redefinition risk.)
set(BLE_ISO_CODE_PATH "")
set(BLE_ISO_LOG_INDEX_HEADER "\"\"")
set(BLE_ISO_TAGS "")
set(BLE_ISO_TAGS_PRESERVE "")
if(CONFIG_BLE_MESH_COMPRESSED_LOG_ENABLE) if(CONFIG_BLE_MESH_COMPRESSED_LOG_ENABLE)
list(APPEND LOG_COMPRESSED_MODULE "BLE_MESH") list(APPEND LOG_COMPRESSED_MODULE "BLE_MESH")
@@ -31,6 +41,26 @@ if(CONFIG_BLE_MESH_COMPRESSED_LOG_ENABLE)
list(APPEND LOG_COMPRESSED_MODULE_CODE_PATH ${BLE_MESH_CODE_PATH}) list(APPEND LOG_COMPRESSED_MODULE_CODE_PATH ${BLE_MESH_CODE_PATH})
endif() endif()
if(CONFIG_BLE_ISO_COMPRESSED_LOG_ENABLE)
list(APPEND LOG_COMPRESSED_MODULE "BLE_ISO")
# esp_ble_audio sources share the same LOG_* macro family from
# esp_ble_iso/include/zephyr/logging/log.h; compile them under the
# single BLE_ISO module so they all hit one iso_log_index.h with one
# monotonic log-id counter. Future ISO consumers (e.g. HID-over-ISO)
# extend this list the same way — no per-consumer index header or
# Kconfig toggle.
set(BLE_ISO_CODE_PATH "esp_ble_iso" "esp_ble_audio")
set(BLE_ISO_LOG_INDEX_HEADER "iso_log_index.h")
set(BLE_ISO_LOG_SCRIPT_PATH
"${CMAKE_CURRENT_LIST_DIR}/scripts/module_scripts/ble_iso/make_iso_log_macro.py")
include(${CMAKE_CURRENT_LIST_DIR}/cmake/ble_iso_log_tags.cmake)
if(NOT EXISTS "${CMAKE_BINARY_DIR}/ble_log/include/${BLE_ISO_LOG_INDEX_HEADER}")
file(WRITE "${CMAKE_BINARY_DIR}/ble_log/include/${BLE_ISO_LOG_INDEX_HEADER}" "")
endif()
list(APPEND LOG_COMPRESSED_MODULE_CODE_PATH ${BLE_ISO_CODE_PATH})
endif()
if(CONFIG_BLE_HOST_COMPRESSED_LOG_ENABLE AND CONFIG_BT_BLUEDROID_ENABLED) if(CONFIG_BLE_HOST_COMPRESSED_LOG_ENABLE AND CONFIG_BT_BLUEDROID_ENABLED)
list(APPEND LOG_COMPRESSED_MODULE "BLE_HOST") list(APPEND LOG_COMPRESSED_MODULE "BLE_HOST")
@@ -127,6 +157,12 @@ if(LOG_COMPRESSED_MODULE)
file(WRITE "${CMAKE_BINARY_DIR}/ble_log/module_info.yml") file(WRITE "${CMAKE_BINARY_DIR}/ble_log/module_info.yml")
endif() endif()
set(YML_IN "${BT_ROOT_PATH}/common/ble_log/extension/log_compression/scripts/configs/module_info.yml.in") set(YML_IN "${BT_ROOT_PATH}/common/ble_log/extension/log_compression/scripts/configs/module_info.yml.in")
# BLE_ISO has multiple code paths; rewrite CMake list ";" → YAML ", "
# into a sibling variable so BLE_ISO_CODE_PATH itself stays a CMake
# list usable by any later code that wants to iterate or append.
string(REPLACE ";" ", " BLE_ISO_CODE_PATH_YAML "${BLE_ISO_CODE_PATH}")
configure_file(${YML_IN} ${CONFIG_FILE_PATH} @ONLY) configure_file(${YML_IN} ${CONFIG_FILE_PATH} @ONLY)
string(REPLACE ";" "|" MODULE_CODE_PATH "${LOG_COMPRESSED_MODULE_CODE_PATH}") string(REPLACE ";" "|" MODULE_CODE_PATH "${LOG_COMPRESSED_MODULE_CODE_PATH}")
@@ -689,4 +689,112 @@ if BLE_COMPRESSED_LOG_ENABLE
Please refer to the help information in BLE_BLUEDROID_APPL_ERROR_LOG_PRESERVE Please refer to the help information in BLE_BLUEDROID_APPL_ERROR_LOG_PRESERVE
endmenu endmenu
endif endif
# ---------------------------------------------------------------------
# BLE ISO log compression (esp_ble_iso component)
# ---------------------------------------------------------------------
menuconfig BLE_ISO_COMPRESSED_LOG_ENABLE
bool "Enable BLE ISO log compression(Preview)"
depends on BLE_COMPRESSED_LOG_ENABLE
depends on BT_ISO
default n
help
Apply compression to ESP-BLE-ISO host shim logs (the
esp_ble_iso component) AND every IDF-source consumer that
shares the ISO LOG_* macro family — currently esp_ble_audio,
and future modules such as HID-over-ISO. All such sources
share one iso_log_index.h with one monotonic log-id counter.
Requires base BLE compression to be enabled.
Note: prebuilt libraries (e.g. libble_audio.a) emit logs via
an independent runtime callback (BLE_AUDIO_LIB) and are not
governed by this option.
Note: This library depends on additional Python packages. It
will function correctly only after these dependencies are
installed; refer to:
"components/bt/common/ble_log/log_compression/README.en.md"
for installation instructions.
If the required packages are not installed, the
log-compression mechanism will remain disabled even when this
Config is enabled.
config BLE_ISO_COMPRESSED_LOG_BUFFER_LEN
int "BLE ISO log buffer length"
depends on BLE_ISO_COMPRESSED_LOG_ENABLE
default 512
help
Maximum output length for a single log. Shared by every IDF
source compiled into the BLE_ISO compression channel
(esp_ble_iso, esp_ble_audio, and future ISO consumers).
if BLE_ISO_COMPRESSED_LOG_ENABLE
menu "Select the stack log tag to be compressed"
config BLE_ISO_STACK_ERR_LOG_COMPRESSION
bool "Compress ERROR log"
default y
help
The error log in the BLE-ISO component will be compressed
config BLE_ISO_STACK_ERR_LOG_PRESERVE
bool "Keep the original error log statement"
depends on BLE_ISO_STACK_ERR_LOG_COMPRESSION
default y
help
When this option is enabled, the log data will be output
through both the compressed log interface and the original
UART interface at the same time, meaning that the log
statements will appear on both paths. However, please note
that this dual-output approach introduces additional code
and string constants, which will increase the size of the
firmware binary file. When this option is disabled, the
logs will no longer be printed through the original UART
output path; instead, they will only be output through the
compressed log interface. As the code and strings related
to the original UART output are omitted, the size of the
firmware binary file can be effectively reduced.
config BLE_ISO_STACK_WARN_LOG_COMPRESSION
bool "Compress warn log"
default y
help
The warn log in the BLE-ISO component will be compressed.
config BLE_ISO_STACK_WARN_LOG_PRESERVE
bool "Keep the original warn log statement"
depends on BLE_ISO_STACK_WARN_LOG_COMPRESSION
default y
help
Please refer to the help information in BLE_ISO_STACK_ERR_LOG_PRESERVE.
config BLE_ISO_STACK_INFO_LOG_COMPRESSION
bool "Compress info log"
default y
help
The info log in the BLE-ISO component will be compressed.
config BLE_ISO_STACK_INFO_LOG_PRESERVE
bool "Keep the original info log statement"
depends on BLE_ISO_STACK_INFO_LOG_COMPRESSION
default n
help
Please refer to the help information in BLE_ISO_STACK_ERR_LOG_PRESERVE.
config BLE_ISO_STACK_DEBUG_LOG_COMPRESSION
bool "Compress debug log"
default y
help
The debug log in the BLE-ISO component will be compressed.
config BLE_ISO_STACK_DEBUG_LOG_PRESERVE
bool "Keep the original debug log statement"
depends on BLE_ISO_STACK_DEBUG_LOG_COMPRESSION
default n
help
Please refer to the help information in BLE_ISO_STACK_ERR_LOG_PRESERVE.
endmenu
endif
endif endif
@@ -50,6 +50,16 @@ INIT_BUFFER_MGMT(mesh, LOG_CP_MAX_LOG_BUFFER_USED_SIMU);
char * mesh_last_task_handle = NULL; char * mesh_last_task_handle = NULL;
#endif #endif
#if CONFIG_BLE_ISO_COMPRESSED_LOG_ENABLE
/* The BLE_ISO buffer is shared by every source compiled into the unified
* ISO channel: esp_ble_iso, esp_ble_audio (and future ISO consumers, e.g.
* HID-over-ISO), as well as the AUDIO_LIB runtime callback (prebuilt
* libble_audio.a, source code 5) — they all funnel here. */
DECLARE_BUFFERS(iso, CONFIG_BLE_ISO_COMPRESSED_LOG_BUFFER_LEN, LOG_CP_MAX_LOG_BUFFER_USED_SIMU);
INIT_BUFFER_MGMT(iso, LOG_CP_MAX_LOG_BUFFER_USED_SIMU);
char * iso_last_task_handle = NULL;
#endif
#if CONFIG_BLE_HOST_COMPRESSED_LOG_ENABLE && CONFIG_BT_BLUEDROID_ENABLED #if CONFIG_BLE_HOST_COMPRESSED_LOG_ENABLE && CONFIG_BT_BLUEDROID_ENABLED
DECLARE_BUFFERS(host, CONFIG_BLE_HOST_COMPRESSED_LOG_BUFFER_LEN, LOG_CP_MAX_LOG_BUFFER_USED_SIMU); DECLARE_BUFFERS(host, CONFIG_BLE_HOST_COMPRESSED_LOG_BUFFER_LEN, LOG_CP_MAX_LOG_BUFFER_USED_SIMU);
INIT_BUFFER_MGMT(host, LOG_CP_MAX_LOG_BUFFER_USED_SIMU); INIT_BUFFER_MGMT(host, LOG_CP_MAX_LOG_BUFFER_USED_SIMU);
@@ -80,6 +90,13 @@ int ble_compressed_log_cb_get(uint8_t source, ble_cp_log_buffer_mgmt_t **mgmt)
last_handle = &mesh_last_task_handle; last_handle = &mesh_last_task_handle;
break; break;
#endif #endif
#if CONFIG_BLE_ISO_COMPRESSED_LOG_ENABLE
case BLE_COMPRESSED_LOG_OUT_SOURCE_ISO:
case BLE_COMPRESSED_LOG_OUT_SOURCE_AUDIO_LIB:
buffer_mgmt = BUF_MGMT_NAME(iso);
last_handle = &iso_last_task_handle;
break;
#endif
#if CONFIG_BLE_HOST_COMPRESSED_LOG_ENABLE && (CONFIG_BT_BLUEDROID_ENABLED || CONFIG_BT_NIMBLE_ENABLED) #if CONFIG_BLE_HOST_COMPRESSED_LOG_ENABLE && (CONFIG_BT_BLUEDROID_ENABLED || CONFIG_BT_NIMBLE_ENABLED)
case BLE_COMPRESSED_LOG_OUT_SOURCE_HOST: case BLE_COMPRESSED_LOG_OUT_SOURCE_HOST:
#if CONFIG_BT_BLUEDROID_ENABLED #if CONFIG_BT_BLUEDROID_ENABLED
@@ -0,0 +1,25 @@
set(_BLE_ISO_TAG_MAP
CONFIG_BLE_ISO_STACK_ERR_LOG_COMPRESSION
CONFIG_BLE_ISO_STACK_ERR_LOG_PRESERVE
LOG_ERR
CONFIG_BLE_ISO_STACK_WARN_LOG_COMPRESSION
CONFIG_BLE_ISO_STACK_WARN_LOG_PRESERVE
LOG_WRN
CONFIG_BLE_ISO_STACK_INFO_LOG_COMPRESSION
CONFIG_BLE_ISO_STACK_INFO_LOG_PRESERVE
LOG_INF
CONFIG_BLE_ISO_STACK_DEBUG_LOG_COMPRESSION
CONFIG_BLE_ISO_STACK_DEBUG_LOG_PRESERVE
LOG_DBG
)
include(${CMAKE_CURRENT_LIST_DIR}/tag_table_function.cmake)
set(BLE_ISO_TAGS "")
set(BLE_ISO_TAGS_PRESERVE "")
tag_table_to_lists(_BLE_ISO_TAG_MAP BLE_ISO_TAGS BLE_ISO_TAGS_PRESERVE)
set(BLE_ISO_TAGS "${BLE_ISO_TAGS}" PARENT_SCOPE)
set(BLE_ISO_TAGS_PRESERVE "${BLE_ISO_TAGS_PRESERVE}" PARENT_SCOPE)
@@ -10,8 +10,13 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#ifndef CONCAT
#define CONCAT(a, b) a##b #define CONCAT(a, b) a##b
#endif
#ifndef _CONCAT
#define _CONCAT(a, b) CONCAT(a, b) #define _CONCAT(a, b) CONCAT(a, b)
#endif
#define _0 0 #define _0 0
#define _1 1 #define _1 1
@@ -27,8 +32,10 @@
#define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _n, X...) _n #define __COUNT_ARGS(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _n, X...) _n
#define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0) #define COUNT_ARGS(X...) __COUNT_ARGS(, ##X, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0)
#ifndef FOR_EACH_IDX
#define FOR_EACH_IDX(macro, name, len, ...) \ #define FOR_EACH_IDX(macro, name, len, ...) \
_CONCAT(_FOR_EACH_, COUNT_ARGS(__VA_ARGS__))(macro, name, len, __VA_ARGS__) _CONCAT(_FOR_EACH_, COUNT_ARGS(__VA_ARGS__))(macro, name, len, __VA_ARGS__)
#endif
#define _FOR_EACH_0(m, n, l, ...) #define _FOR_EACH_0(m, n, l, ...)
#define _FOR_EACH_1(m, n, l, i1, ...) m(n, l, i1) #define _FOR_EACH_1(m, n, l, i1, ...) m(n, l, i1)
@@ -50,6 +57,8 @@ enum {
BLE_COMPRESSED_LOG_OUT_SOURCE_HOST, BLE_COMPRESSED_LOG_OUT_SOURCE_HOST,
BLE_COMPRESSED_LOG_OUT_SOURCE_MESH, BLE_COMPRESSED_LOG_OUT_SOURCE_MESH,
BLE_COMPRESSED_LOG_OUT_SOURCE_MESH_LIB, BLE_COMPRESSED_LOG_OUT_SOURCE_MESH_LIB,
BLE_COMPRESSED_LOG_OUT_SOURCE_ISO,
BLE_COMPRESSED_LOG_OUT_SOURCE_AUDIO_LIB,
}; };
enum { enum {
@@ -76,6 +76,8 @@ SOURCE_ENUM_MAP = {
'BLE_HOST': 0, 'BLE_HOST': 0,
'BLE_MESH': 1, 'BLE_MESH': 1,
'BLE_MESH_LIB': 2, 'BLE_MESH_LIB': 2,
'BLE_ISO': 3,
'BLE_AUDIO_LIB': 4,
} }
# Functions that require hex formatting # Functions that require hex formatting
@@ -18,6 +18,14 @@ log_config:
tags: [@BLE_HOST_TAGS@] tags: [@BLE_HOST_TAGS@]
tags_with_preserve: [@BLE_HOST_TAGS_PRESERVE@] tags_with_preserve: [@BLE_HOST_TAGS_PRESERVE@]
BLE_ISO:
description: "BLE ISO (and consumers: esp_ble_audio, future HID-over-ISO)"
code_path: [@BLE_ISO_CODE_PATH_YAML@]
log_index_file: @BLE_ISO_LOG_INDEX_HEADER@
script: @BLE_ISO_LOG_SCRIPT_PATH@
tags: [@BLE_ISO_TAGS@]
tags_with_preserve: [@BLE_ISO_TAGS_PRESERVE@]
@BLE_COMPRESSED_LIB_NAME@: @BLE_COMPRESSED_LIB_NAME@:
description: "@BLE_COMPRESSED_LIB_DESC@" description: "@BLE_COMPRESSED_LIB_DESC@"
code_path: [@BLE_COMPRESSED_LIB_CODE_DIR@] code_path: [@BLE_COMPRESSED_LIB_CODE_DIR@]
@@ -0,0 +1,73 @@
# SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
"""Macro generator shared by the BLE_ISO and BLE_AUDIO compression modules.
Both components consume the LOG_ERR / LOG_WRN / LOG_INF / LOG_DBG macros
defined in components/bt/esp_ble_iso/include/zephyr/logging/log.h and gate
output through CONFIG_BT_ISO_LOG_LEVEL with the BT_ISO_LOG_* numeric levels.
"""
import textwrap
def generate_iso_log_prefix(tag: str, print_statm: str) -> str:
"""Wrap a compressed-print statement with the matching level check."""
level = tag.split('_')[-1] # LOG_ERR -> ERR
if level == 'ERR':
log_level = 'BT_ISO_LOG_ERROR'
elif level == 'WRN':
log_level = 'BT_ISO_LOG_WARN'
elif level == 'INF':
log_level = 'BT_ISO_LOG_INFO'
elif level == 'DBG':
log_level = 'BT_ISO_LOG_DEBUG'
else:
return ''
used_log_levl = 'CONFIG_BT_ISO_LOG_LEVEL'
return f'{{do {{ if (({used_log_levl} >= {log_level})) {{ {print_statm}; }} }} while (0);}}\\\n'
def gen_header_head() -> str:
head = textwrap.dedent("""
// Compression function declarations
extern int ble_log_compressed_hex_print
(uint8_t source, uint32_t log_index, size_t args_size_cnt, ...);
extern int ble_log_compressed_hex_print_buf
(uint8_t source, uint32_t log_index, uint8_t buf_idx, const uint8_t *buf, size_t len);
""")
return head
def gen_compressed_stmt(log_index: int, module_id: int, func_name: str, fmt: str, args: list, buffer_args: list) -> str:
if len(args) == 0:
stmt = f' ble_log_compressed_hex_print({module_id}, {log_index}, 0);'
for idx, buffer_arg in enumerate(buffer_args):
stmt += '\\\n'
stmt += (
f' ble_log_compressed_hex_print_buf('
f'{module_id}, {log_index}, {idx}, '
f'(const uint8_t *){buffer_arg["buffer"]}, {buffer_arg["length"]});'
)
stmt += '\\\n'
return ' ' + generate_iso_log_prefix(func_name, stmt)
size_str = ', '.join([arg['size_type'] for arg in args])
# Strip both backslash-newline continuations and bare newlines from arg
# names so they don't leak into the generated C macro body — the same
# cleanup the NimBLE / Bluedroid generators do.
args_str = ', '.join([arg['name'] for arg in args]).replace('\\\n', '').replace('\n', '')
stmt = f' ble_log_compressed_hex_print({module_id}, {log_index}, {len(args)}, {size_str}, {args_str});'
for idx, buffer_arg in enumerate(buffer_args):
stmt += '\\\n'
stmt += (
f' ble_log_compressed_hex_print_buf('
f'{module_id}, {log_index}, {idx}, '
f'(const uint8_t *){buffer_arg["buffer"]}, {buffer_arg["length"]});'
)
stmt += '\\\n'
return ' ' + generate_iso_log_prefix(func_name, stmt)
+18 -6
View File
@@ -100,21 +100,33 @@ menu "OTS Options"
endmenu endmenu
config BT_AUDIO_NO_LOG config BT_AUDIO_NO_LOG
bool "Disable BLE Audio Debug Log" bool "Disable BLE Audio Lib Debug Log"
default n default n
help help
Select this to save the BLE Audio related rodata code size. Enabling Select this to save rodata code size by disabling the debug log
this option will disable the output of BLE Audio debug log. emitted by the BLE Audio prebuilt library (printed with the
"LEA_LIB" tag).
menu "BLE Audio Debug Log Level" Note: this option does NOT affect logs from the BLE Audio IDF
source files (esp_ble_audio component, "LEA_*" tags) - those
are controlled by BT_ISO_NO_LOG / BT_ISO_LOG_LEVEL under the
"BLE ISO Options" menu.
menu "BLE Audio Lib Debug Log Level"
depends on !BT_AUDIO_NO_LOG depends on !BT_AUDIO_NO_LOG
choice BT_AUDIO_LOG_LEVEL choice BT_AUDIO_LOG_LEVEL
prompt "LE_AUDIO_LOG_LEVEL" prompt "BLE_AUDIO_LIB_LOG_LEVEL"
default BT_AUDIO_LOG_LEVEL_WARNING default BT_AUDIO_LOG_LEVEL_WARNING
depends on !BT_AUDIO_NO_LOG depends on !BT_AUDIO_NO_LOG
help help
Define BLE Audio trace level. Define the trace level of the BLE Audio prebuilt library
(logs printed with the "LEA_LIB" tag).
Note: logs from the BLE Audio IDF source files
(esp_ble_audio component, "LEA_*" tags) are controlled
separately by BT_ISO_LOG_LEVEL under the "BLE ISO Options"
menu.
config BT_AUDIO_LOG_LEVEL_NONE config BT_AUDIO_LOG_LEVEL_NONE
bool "NONE" bool "NONE"
@@ -23,6 +23,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_NINIT, CONFIG_BT_ISO_LOG_LEVEL);
#if CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT #if CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT
#define ASCS_ASE_SNK_CCCD_COUNT CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT #define ASCS_ASE_SNK_CCCD_COUNT CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT
#else /* CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT */ #else /* CONFIG_BT_ASCS_MAX_ASE_SNK_COUNT */
@@ -29,6 +29,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_ASCS, CONFIG_BT_ISO_LOG_LEVEL);
static const ble_uuid16_t ascs_uuid_ase_cp = BLE_UUID16_INIT(BT_UUID_ASCS_ASE_CP_VAL); static const ble_uuid16_t ascs_uuid_ase_cp = BLE_UUID16_INIT(BT_UUID_ASCS_ASE_CP_VAL);
static const ble_uuid16_t ascs_uuid_ase_snk = BLE_UUID16_INIT(BT_UUID_ASCS_ASE_SNK_VAL); static const ble_uuid16_t ascs_uuid_ase_snk = BLE_UUID16_INIT(BT_UUID_ASCS_ASE_SNK_VAL);
static const ble_uuid16_t ascs_uuid_ase_src = BLE_UUID16_INIT(BT_UUID_ASCS_ASE_SRC_VAL); static const ble_uuid16_t ascs_uuid_ase_src = BLE_UUID16_INIT(BT_UUID_ASCS_ASE_SRC_VAL);
@@ -29,6 +29,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_BASS, CONFIG_BT_ISO_LOG_LEVEL);
static const ble_uuid16_t bass_uuid_control_point = BLE_UUID16_INIT(BT_UUID_BASS_CONTROL_POINT_VAL); static const ble_uuid16_t bass_uuid_control_point = BLE_UUID16_INIT(BT_UUID_BASS_CONTROL_POINT_VAL);
static const ble_uuid16_t bass_uuid_recv_state = BLE_UUID16_INIT(BT_UUID_BASS_RECV_STATE_VAL); static const ble_uuid16_t bass_uuid_recv_state = BLE_UUID16_INIT(BT_UUID_BASS_RECV_STATE_VAL);
@@ -21,6 +21,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_CAS, CONFIG_BT_ISO_LOG_LEVEL);
#if CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER #if CONFIG_BT_CAP_ACCEPTOR_SET_MEMBER
extern struct ble_gatt_svc_def *cas_get_included_csis(void *csis_svc_p); extern struct ble_gatt_svc_def *cas_get_included_csis(void *csis_svc_p);
@@ -31,6 +31,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_CSIS, CONFIG_BT_ISO_LOG_LEVEL);
#define CSIS_SVC_COUNT CONFIG_BT_CSIP_SET_MEMBER_MAX_INSTANCE_COUNT #define CSIS_SVC_COUNT CONFIG_BT_CSIP_SET_MEMBER_MAX_INSTANCE_COUNT
#define CSIS_CHR_COUNT (4 + 1) #define CSIS_CHR_COUNT (4 + 1)
@@ -29,6 +29,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_HAS, CONFIG_BT_ISO_LOG_LEVEL);
static const ble_uuid16_t has_uuid_features = BLE_UUID16_INIT(BT_UUID_HAS_HEARING_AID_FEATURES_VAL); static const ble_uuid16_t has_uuid_features = BLE_UUID16_INIT(BT_UUID_HAS_HEARING_AID_FEATURES_VAL);
static const ble_uuid16_t has_uuid_control_point = BLE_UUID16_INIT(BT_UUID_HAS_PRESET_CONTROL_POINT_VAL); static const ble_uuid16_t has_uuid_control_point = BLE_UUID16_INIT(BT_UUID_HAS_PRESET_CONTROL_POINT_VAL);
static const ble_uuid16_t has_uuid_preset_index = BLE_UUID16_INIT(BT_UUID_HAS_ACTIVE_PRESET_INDEX_VAL); static const ble_uuid16_t has_uuid_preset_index = BLE_UUID16_INIT(BT_UUID_HAS_ACTIVE_PRESET_INDEX_VAL);
@@ -34,6 +34,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_MCS, CONFIG_BT_ISO_LOG_LEVEL);
#if CONFIG_BT_OTS #if CONFIG_BT_OTS
#define INC_OTS_CHR_COUNT 8 /* - OTS Feature (M) #define INC_OTS_CHR_COUNT 8 /* - OTS Feature (M)
* - Object Name (M) * - Object Name (M)
@@ -29,6 +29,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_MICS, CONFIG_BT_ISO_LOG_LEVEL);
#define INC_AICS_CHR_COUNT (6 + 1) #define INC_AICS_CHR_COUNT (6 + 1)
#define INC_AICS_CHR_FLAGS_STATE \ #define INC_AICS_CHR_FLAGS_STATE \
@@ -27,6 +27,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_PACS, CONFIG_BT_ISO_LOG_LEVEL);
#if CONFIG_BT_PAC_SNK #if CONFIG_BT_PAC_SNK
static uint16_t pacs_snk_handle; static uint16_t pacs_snk_handle;
#if CONFIG_BT_PAC_SNK_LOC #if CONFIG_BT_PAC_SNK_LOC
@@ -25,6 +25,8 @@
#include "common/host.h" #include "common/host.h"
LOG_MODULE_REGISTER(LEA_GSRV, CONFIG_BT_ISO_LOG_LEVEL);
static ssize_t gatts_read_cb(void *arg, uint16_t offset, const void *data, uint16_t len) static ssize_t gatts_read_cb(void *arg, uint16_t offset, const void *data, uint16_t len)
{ {
struct os_mbuf *om; struct os_mbuf *om;
@@ -27,6 +27,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_TBS, CONFIG_BT_ISO_LOG_LEVEL);
static const struct ble_gatt_svc_def gatt_svc_gtbs[] = { static const struct ble_gatt_svc_def gatt_svc_gtbs[] = {
{ {
/* Generic Telephone Bearer Service */ /* Generic Telephone Bearer Service */
@@ -27,6 +27,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_TMAS, CONFIG_BT_ISO_LOG_LEVEL);
static const struct ble_gatt_svc_def gatt_svc_tmas[] = { static const struct ble_gatt_svc_def gatt_svc_tmas[] = {
{ {
/* Telephony and Media Audio Service */ /* Telephony and Media Audio Service */
@@ -29,6 +29,8 @@
#include "../../../lib/include/audio.h" #include "../../../lib/include/audio.h"
LOG_MODULE_REGISTER(LEA_VCS, CONFIG_BT_ISO_LOG_LEVEL);
#define VOCS_INST_COUNT CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT #define VOCS_INST_COUNT CONFIG_BT_VCP_VOL_REND_VOCS_INSTANCE_COUNT
#define INC_VOCS_CHR_COUNT (4 + 1) #define INC_VOCS_CHR_COUNT (4 + 1)
@@ -7,6 +7,7 @@
#ifndef HOST_COMMON_INIT_H_ #ifndef HOST_COMMON_INIT_H_
#define HOST_COMMON_INIT_H_ #define HOST_COMMON_INIT_H_
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include "sdkconfig.h" #include "sdkconfig.h"
@@ -57,6 +58,11 @@ int bt_le_micp_mic_dev_init(void);
int bt_le_audio_start(void *info); int bt_le_audio_start(void *info);
void ble_audio_lib_compressed_out(uint8_t log_level, uint32_t log_index, size_t arg_cnt, ...);
void ble_audio_lib_compressed_buf_out(uint8_t log_level, uint32_t log_index, uint8_t buf_idx,
const uint8_t *buf, size_t len);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
+56 -9
View File
@@ -4,8 +4,10 @@
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include <stdarg.h>
#include <errno.h> #include <errno.h>
#include "sdkconfig.h" #include "sdkconfig.h"
@@ -48,6 +50,12 @@
#include "esp_ble_audio_common_api.h" #include "esp_ble_audio_common_api.h"
#if CONFIG_BLE_ISO_COMPRESSED_LOG_ENABLE
#include "log_compression/utils.h"
#endif
LOG_MODULE_REGISTER(LEA_INIT, CONFIG_BT_ISO_LOG_LEVEL);
_Static_assert(sizeof(struct bt_le_audio_start_info) == _Static_assert(sizeof(struct bt_le_audio_start_info) ==
sizeof(esp_ble_audio_start_info_t), sizeof(esp_ble_audio_start_info_t),
"Mismatch LE Audio start info structure"); "Mismatch LE Audio start info structure");
@@ -1109,11 +1117,11 @@ struct lib_ext_funcs {
void (*_ots_metadata_display)(void *metadata, uint16_t count); void (*_ots_metadata_display)(void *metadata, uint16_t count);
}; };
#define LEA_TAG "LIB" #define LEA_TAG "LEA_LIB"
static void log_debug(const char *format, ...) static void log_debug(const char *format, ...)
{ {
#if (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_AUDIO_LOG_DEBUG) #if (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_ISO_LOG_DEBUG)
va_list args; va_list args;
va_start(args, format); va_start(args, format);
@@ -1124,12 +1132,12 @@ static void log_debug(const char *format, ...)
esp_log_write(ESP_LOG_INFO, LEA_TAG, BT_ISO_LOG_RESET_COLOR "\n"); esp_log_write(ESP_LOG_INFO, LEA_TAG, BT_ISO_LOG_RESET_COLOR "\n");
va_end(args); va_end(args);
#endif /* (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_AUDIO_LOG_DEBUG) */ #endif /* (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_ISO_LOG_DEBUG) */
} }
static void log_info(const char *format, ...) static void log_info(const char *format, ...)
{ {
#if (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_AUDIO_LOG_INFO) #if (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_ISO_LOG_INFO)
va_list args; va_list args;
va_start(args, format); va_start(args, format);
@@ -1139,12 +1147,12 @@ static void log_info(const char *format, ...)
esp_log_write(ESP_LOG_INFO, LEA_TAG, BT_ISO_LOG_RESET_COLOR "\n"); esp_log_write(ESP_LOG_INFO, LEA_TAG, BT_ISO_LOG_RESET_COLOR "\n");
va_end(args); va_end(args);
#endif /* (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_AUDIO_LOG_INFO) */ #endif /* (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_ISO_LOG_INFO) */
} }
static void log_warn(const char *format, ...) static void log_warn(const char *format, ...)
{ {
#if (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_AUDIO_LOG_WARN) #if (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_ISO_LOG_WARN)
va_list args; va_list args;
va_start(args, format); va_start(args, format);
@@ -1154,12 +1162,12 @@ static void log_warn(const char *format, ...)
esp_log_write(ESP_LOG_WARN, LEA_TAG, BT_ISO_LOG_RESET_COLOR "\n"); esp_log_write(ESP_LOG_WARN, LEA_TAG, BT_ISO_LOG_RESET_COLOR "\n");
va_end(args); va_end(args);
#endif /* (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_AUDIO_LOG_WARN) */ #endif /* (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_ISO_LOG_WARN) */
} }
static void log_error(const char *format, ...) static void log_error(const char *format, ...)
{ {
#if (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_AUDIO_LOG_ERROR) #if (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_ISO_LOG_ERROR)
va_list args; va_list args;
va_start(args, format); va_start(args, format);
@@ -1169,7 +1177,7 @@ static void log_error(const char *format, ...)
esp_log_write(ESP_LOG_ERROR, LEA_TAG, BT_ISO_LOG_RESET_COLOR "\n"); esp_log_write(ESP_LOG_ERROR, LEA_TAG, BT_ISO_LOG_RESET_COLOR "\n");
va_end(args); va_end(args);
#endif /* (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_AUDIO_LOG_ERROR) */ #endif /* (CONFIG_BT_AUDIO_LOG_LEVEL >= BT_ISO_LOG_ERROR) */
} }
static const struct lib_ext_funcs ext_funcs = { static const struct lib_ext_funcs ext_funcs = {
@@ -2140,3 +2148,42 @@ int bt_le_audio_start(void *info)
return bt_le_nimble_audio_start(info); return bt_le_nimble_audio_start(info);
} }
void ble_audio_lib_compressed_out(uint8_t log_level, uint32_t log_index, size_t arg_cnt, ...)
{
#if CONFIG_BLE_ISO_COMPRESSED_LOG_ENABLE
if (CONFIG_BT_ISO_LOG_LEVEL >= log_level) {
va_list args;
va_start(args, arg_cnt);
extern int ble_log_compressed_hex_printv(uint8_t source, uint32_t log_index,
size_t args_cnt, va_list args);
ble_log_compressed_hex_printv(BLE_COMPRESSED_LOG_OUT_SOURCE_AUDIO_LIB,
log_index, arg_cnt, args);
va_end(args);
}
#else
(void)log_level;
(void)log_index;
(void)arg_cnt;
#endif
}
void ble_audio_lib_compressed_buf_out(uint8_t log_level, uint32_t log_index, uint8_t buf_idx,
const uint8_t *buf, size_t len)
{
#if CONFIG_BLE_ISO_COMPRESSED_LOG_ENABLE
if (CONFIG_BT_ISO_LOG_LEVEL >= log_level) {
extern int ble_log_compressed_hex_print_buf(uint8_t source, uint32_t log_index,
uint8_t buf_idx, const uint8_t *buf,
size_t len);
ble_log_compressed_hex_print_buf(BLE_COMPRESSED_LOG_OUT_SOURCE_AUDIO_LIB,
log_index, buf_idx, buf, len);
}
#else
(void)log_level;
(void)log_index;
(void)buf_idx;
(void)buf;
(void)len;
#endif
}
@@ -26,7 +26,7 @@
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_ots, CONFIG_BT_OTS_LOG_LEVEL); LOG_MODULE_REGISTER(LEA_OTS, CONFIG_BT_ISO_LOG_LEVEL);
#if defined(CONFIG_BT_OTS_OACP_CREATE_SUPPORT) #if defined(CONFIG_BT_OTS_OACP_CREATE_SUPPORT)
#define OACP_FEAT_BIT_CREATE BIT(BT_OTS_OACP_FEAT_CREATE) #define OACP_FEAT_BIT_CREATE BIT(BT_OTS_OACP_FEAT_CREATE)
@@ -26,9 +26,9 @@
#include "ots_oacp_internal.h" #include "ots_oacp_internal.h"
#include "ots_olcp_internal.h" #include "ots_olcp_internal.h"
#define LOG_LEVEL CONFIG_BT_OTS_CLIENT_LOG_LEVEL
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(bt_otc);
LOG_MODULE_REGISTER(LEA_OTC, CONFIG_BT_ISO_LOG_LEVEL);
/* TODO: KConfig options */ /* TODO: KConfig options */
#define OTS_CLIENT_INST_COUNT 1 #define OTS_CLIENT_INST_COUNT 1
@@ -1653,12 +1653,14 @@ static int decode_record(struct net_buf_simple *buf,
rec->metadata.id = net_buf_simple_pull_le48(buf); rec->metadata.id = net_buf_simple_pull_le48(buf);
if (IS_ENABLED(CONFIG_BT_OTS_CLIENT_LOG_LEVEL_DBG)) { #if (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_DEBUG)
{
char t[BT_OTS_OBJ_ID_STR_LEN]; char t[BT_OTS_OBJ_ID_STR_LEN];
(void)bt_ots_obj_id_to_str(rec->metadata.id, t, sizeof(t)); (void)bt_ots_obj_id_to_str(rec->metadata.id, t, sizeof(t));
LOG_DBG("Object ID 0x%s", t); LOG_DBG("Object ID 0x%s", t);
} }
#endif
if ((start_len - buf->len) + sizeof(uint8_t) > rec->len) { if ((start_len - buf->len) + sizeof(uint8_t) > rec->len) {
LOG_WRN("incorrect DirListing record, reclen %u too short, " LOG_WRN("incorrect DirListing record, reclen %u too short, "
@@ -18,7 +18,7 @@
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(bt_ots, CONFIG_BT_OTS_LOG_LEVEL); LOG_MODULE_REGISTER(LEA_OTS, CONFIG_BT_ISO_LOG_LEVEL);
static struct bt_ots_dir_list dir_lists[CONFIG_BT_OTS_MAX_INST_CNT]; static struct bt_ots_dir_list dir_lists[CONFIG_BT_OTS_MAX_INST_CNT];
@@ -17,14 +17,7 @@
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
/* This l2cap is the only OTS-file in use for OTC. LOG_MODULE_REGISTER(LEA_OTS, CONFIG_BT_ISO_LOG_LEVEL);
* If only OTC is used, the OTS log module must be registered here.
*/
#if defined(CONFIG_BT_OTS)
LOG_MODULE_DECLARE(bt_ots, CONFIG_BT_OTS_LOG_LEVEL);
#elif defined(CONFIG_BT_OTS_CLIENT)
LOG_MODULE_REGISTER(bt_ots, CONFIG_BT_OTS_CLIENT_LOG_LEVEL);
#endif
/* According to Bluetooth specification Assigned Numbers that are used in the /* According to Bluetooth specification Assigned Numbers that are used in the
* Logical Link Control for protocol/service multiplexers. * Logical Link Control for protocol/service multiplexers.
@@ -21,7 +21,7 @@
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(bt_ots, CONFIG_BT_OTS_LOG_LEVEL); LOG_MODULE_REGISTER(LEA_OTS, CONFIG_BT_ISO_LOG_LEVEL);
#define OACP_PROC_TYPE_SIZE 1 #define OACP_PROC_TYPE_SIZE 1
@@ -16,8 +16,6 @@
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(bt_ots, CONFIG_BT_OTS_LOG_LEVEL);
struct bt_gatt_ots_pool_item { struct bt_gatt_ots_pool_item {
sys_dnode_t dnode; sys_dnode_t dnode;
struct bt_gatt_ots_object val; struct bt_gatt_ots_object val;
@@ -19,7 +19,7 @@
#include <zephyr/logging/log.h> #include <zephyr/logging/log.h>
LOG_MODULE_DECLARE(bt_ots, CONFIG_BT_OTS_LOG_LEVEL); LOG_MODULE_REGISTER(LEA_OTS, CONFIG_BT_ISO_LOG_LEVEL);
#define OLCP_PROC_TYPE_SIZE 1 #define OLCP_PROC_TYPE_SIZE 1
+20 -6
View File
@@ -98,21 +98,35 @@ if BT_ISO
endif # BT_ISO_BROADCAST endif # BT_ISO_BROADCAST
config BT_ISO_NO_LOG config BT_ISO_NO_LOG
bool "Disable ISO Debug Log" bool "Disable BLE ISO Debug Log"
default n default n
help help
Select this to save the ISO related rodata code size. Enabling Select this to save rodata code size by disabling the debug
this option will disable the output of ISO debug log. log emitted by the BLE ISO IDF source files (printed with
"ISO_*" tags).
menu "ISO Debug Log Level" Note: this option also gates logs from the BLE Audio IDF
source files (esp_ble_audio component, with "LEA_*" tags)
because they share the same log header. Logs from the BLE
Audio prebuilt library are gated separately by
BT_AUDIO_NO_LOG.
menu "BLE ISO Debug Log Level"
depends on !BT_ISO_NO_LOG depends on !BT_ISO_NO_LOG
choice BT_ISO_LOG_LEVEL choice BT_ISO_LOG_LEVEL
prompt "ISO_LOG_LEVEL" prompt "BLE_ISO_LOG_LEVEL"
default BT_ISO_LOG_LEVEL_WARNING default BT_ISO_LOG_LEVEL_WARNING
depends on !BT_ISO_NO_LOG depends on !BT_ISO_NO_LOG
help help
Define ISO trace level. Define the trace level of the BLE ISO IDF source files
(logs printed with "ISO_*" tags).
Note: this level also applies to the BLE Audio IDF
source files (esp_ble_audio component, "LEA_*" tags)
because they share the same log header. The trace
level of the BLE Audio prebuilt library is configured
separately by BT_AUDIO_LOG_LEVEL.
config BT_ISO_LOG_LEVEL_NONE config BT_ISO_LOG_LEVEL_NONE
bool "NONE" bool "NONE"
@@ -25,6 +25,8 @@
#include "nimble/hs_error.h" #include "nimble/hs_error.h"
LOG_MODULE_REGISTER(ISO_NGAP, CONFIG_BT_ISO_LOG_LEVEL);
/* Map a NimBLE connection's security state to Zephyr bt_security_t. /* Map a NimBLE connection's security state to Zephyr bt_security_t.
* *
* To reach L3/L4 the app must configure NimBLE for authenticated pairing: * To reach L3/L4 the app must configure NimBLE for authenticated pairing:
@@ -27,6 +27,8 @@
#include "nimble/hs_error.h" #include "nimble/hs_error.h"
#include "common/app/gatt.h" #include "common/app/gatt.h"
LOG_MODULE_REGISTER(ISO_NGAT, CONFIG_BT_ISO_LOG_LEVEL);
void bt_le_nimble_gatt_post_event(void *param) void bt_le_nimble_gatt_post_event(void *param)
{ {
struct bt_le_gatt_event_param *qev; struct bt_le_gatt_event_param *qev;
@@ -24,6 +24,8 @@
#include "common/host.h" #include "common/host.h"
LOG_MODULE_REGISTER(ISO_NGDB, CONFIG_BT_ISO_LOG_LEVEL);
static int gattc_db_find_inc_svcs_cb_safe(uint16_t conn_handle, static int gattc_db_find_inc_svcs_cb_safe(uint16_t conn_handle,
const struct ble_gatt_error *error, const struct ble_gatt_error *error,
const struct ble_gatt_svc *svc, const struct ble_gatt_svc *svc,
@@ -26,6 +26,8 @@
#include "nimble/hs_error.h" #include "nimble/hs_error.h"
LOG_MODULE_REGISTER(ISO_NGRP, CONFIG_BT_ISO_LOG_LEVEL);
struct gatt_nrp_node { struct gatt_nrp_node {
uint8_t type; uint8_t type;
@@ -21,6 +21,8 @@
#include "nimble/hs_error.h" #include "nimble/hs_error.h"
LOG_MODULE_REGISTER(ISO_NISO, CONFIG_BT_ISO_LOG_LEVEL);
extern int ble_hs_iso_evt_rx_cb_set(void *cb); extern int ble_hs_iso_evt_rx_cb_set(void *cb);
#if CONFIG_BT_ISO_RX #if CONFIG_BT_ISO_RX
extern int ble_hs_iso_pkt_rx_cb_set(ble_hs_iso_pkt_rx_fn cb); extern int ble_hs_iso_pkt_rx_cb_set(ble_hs_iso_pkt_rx_fn cb);
@@ -25,6 +25,8 @@
#include "nimble/hs_error.h" #include "nimble/hs_error.h"
LOG_MODULE_REGISTER(ISO_N2CAP, CONFIG_BT_ISO_LOG_LEVEL);
_Static_assert(CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM && "At least one L2CAP coc shall be supported"); _Static_assert(CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM && "At least one L2CAP coc shall be supported");
#define OTS_L2CAP_BUF_COUNT (3 * CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM) #define OTS_L2CAP_BUF_COUNT (3 * CONFIG_BT_NIMBLE_L2CAP_COC_MAX_NUM)
@@ -18,6 +18,8 @@
#include "common/host.h" #include "common/host.h"
LOG_MODULE_REGISTER(ISO_ADV, CONFIG_BT_ISO_LOG_LEVEL);
static struct bt_le_ext_adv ext_adv_pool[CONFIG_BT_EXT_ADV_MAX_ADV_SET]; static struct bt_le_ext_adv ext_adv_pool[CONFIG_BT_EXT_ADV_MAX_ADV_SET];
static struct bt_le_ext_adv *ext_adv_find(uint8_t adv_handle) static struct bt_le_ext_adv *ext_adv_find(uint8_t adv_handle)
@@ -18,6 +18,8 @@
#include "common/host.h" #include "common/host.h"
#include "common/app/gap.h" #include "common/app/gap.h"
LOG_MODULE_REGISTER(ISO_AGAP, CONFIG_BT_ISO_LOG_LEVEL);
static bt_le_gap_app_cb gap_app_cb; static bt_le_gap_app_cb gap_app_cb;
int bt_le_gap_app_cb_register(bt_le_gap_app_cb cb) int bt_le_gap_app_cb_register(bt_le_gap_app_cb cb)
@@ -18,6 +18,8 @@
#include "common/host.h" #include "common/host.h"
#include "common/app/gatt.h" #include "common/app/gatt.h"
LOG_MODULE_REGISTER(ISO_AGAT, CONFIG_BT_ISO_LOG_LEVEL);
static bt_le_gatt_app_cb gatt_app_cb; static bt_le_gatt_app_cb gatt_app_cb;
int bt_le_gatt_app_cb_register(bt_le_gatt_app_cb cb) int bt_le_gatt_app_cb_register(bt_le_gatt_app_cb cb)
@@ -21,6 +21,8 @@
#include "common/host.h" #include "common/host.h"
#include "common/app/gap.h" #include "common/app/gap.h"
LOG_MODULE_REGISTER(ISO_CONN, CONFIG_BT_ISO_LOG_LEVEL);
static struct bt_conn acl_conns[CONFIG_BT_MAX_CONN]; static struct bt_conn acl_conns[CONFIG_BT_MAX_CONN];
extern struct bt_conn iso_conns[CONFIG_BT_ISO_MAX_CHAN]; extern struct bt_conn iso_conns[CONFIG_BT_ISO_MAX_CHAN];
@@ -22,6 +22,8 @@
#include "common/host.h" #include "common/host.h"
LOG_MODULE_REGISTER(ISO_GATT, CONFIG_BT_ISO_LOG_LEVEL);
static sys_slist_t gatt_db = SYS_SLIST_STATIC_INIT(&gatt_db); static sys_slist_t gatt_db = SYS_SLIST_STATIC_INIT(&gatt_db);
static struct gattc_sub subscriptions[CONFIG_BT_MAX_CONN]; static struct gattc_sub subscriptions[CONFIG_BT_MAX_CONN];
@@ -21,6 +21,8 @@
#include "common/host.h" #include "common/host.h"
LOG_MODULE_REGISTER(ISO_HCI, CONFIG_BT_ISO_LOG_LEVEL);
struct cmd_data { struct cmd_data {
/** HCI status of the command completion */ /** HCI status of the command completion */
uint8_t status; uint8_t status;
@@ -15,6 +15,8 @@
#include "common/app/gap.h" #include "common/app/gap.h"
#include "common/app/gatt.h" #include "common/app/gatt.h"
LOG_MODULE_REGISTER(ISO_HOST, CONFIG_BT_ISO_LOG_LEVEL);
static struct k_mutex host_mutex; static struct k_mutex host_mutex;
#define TIMEOUT_MS (5000 / portTICK_PERIOD_MS) /* 5s */ #define TIMEOUT_MS (5000 / portTICK_PERIOD_MS) /* 5s */
@@ -23,6 +23,8 @@
#include "common/task.h" #include "common/task.h"
#include "common/app/gap.h" #include "common/app/gap.h"
LOG_MODULE_REGISTER(ISO_SHIM, CONFIG_BT_ISO_LOG_LEVEL);
#ifdef CONFIG_BT_NIMBLE_ISO_STD_FLOW_CTRL #ifdef CONFIG_BT_NIMBLE_ISO_STD_FLOW_CTRL
#define ISO_STD_FLOW_CTRL true #define ISO_STD_FLOW_CTRL true
#else /* CONFIG_BT_NIMBLE_ISO_STD_FLOW_CTRL */ #else /* CONFIG_BT_NIMBLE_ISO_STD_FLOW_CTRL */
@@ -20,6 +20,8 @@
#include "common/host.h" #include "common/host.h"
#include "common/app/gap.h" #include "common/app/gap.h"
LOG_MODULE_REGISTER(ISO_L2CAP, CONFIG_BT_ISO_LOG_LEVEL);
#define L2CAP_LE_MIN_MTU 23 #define L2CAP_LE_MIN_MTU 23
#define L2CAP_ECRED_MIN_MTU 64 #define L2CAP_ECRED_MIN_MTU 64
@@ -20,6 +20,8 @@
#include "common/host.h" #include "common/host.h"
LOG_MODULE_REGISTER(ISO_SCAN, CONFIG_BT_ISO_LOG_LEVEL);
static sys_slist_t scan_cbs = SYS_SLIST_STATIC_INIT(&scan_cbs); static sys_slist_t scan_cbs = SYS_SLIST_STATIC_INIT(&scan_cbs);
_LIB_ONLY _LIB_ONLY
@@ -21,6 +21,8 @@
#include "common/app/gap.h" #include "common/app/gap.h"
#include "common/app/gatt.h" #include "common/app/gatt.h"
LOG_MODULE_REGISTER(ISO_TASK, CONFIG_BT_ISO_LOG_LEVEL);
static QueueHandle_t iso_queue_handle; static QueueHandle_t iso_queue_handle;
static TaskHandle_t iso_task_handle; static TaskHandle_t iso_task_handle;
+1 -1
View File
@@ -44,7 +44,7 @@
#warning "FreeRTOS with 1ms tick rate is strongly recommended for running ISO." #warning "FreeRTOS with 1ms tick rate is strongly recommended for running ISO."
#endif /* CONFIG_FREERTOS_HZ < 1000 */ #endif /* CONFIG_FREERTOS_HZ < 1000 */
LOG_MODULE_REGISTER(bt_iso, CONFIG_BT_ISO_LOG_LEVEL); LOG_MODULE_REGISTER(ISO_CORE, CONFIG_BT_ISO_LOG_LEVEL);
#if defined(CONFIG_BT_DEBUG_ISO_DATA) #if defined(CONFIG_BT_DEBUG_ISO_DATA)
#define BT_ISO_DATA_DBG(fmt, ...) LOG_DBG(fmt, ##__VA_ARGS__) #define BT_ISO_DATA_DBG(fmt, ...) LOG_DBG(fmt, ##__VA_ARGS__)
@@ -32,6 +32,8 @@
#include "esp_random.h" #include "esp_random.h"
LOG_MODULE_REGISTER(ISO_CRYPTO, CONFIG_BT_ISO_LOG_LEVEL);
int bt_rand(void *buf, size_t len) int bt_rand(void *buf, size_t len)
{ {
if (buf == NULL || len == 0) { if (buf == NULL || len == 0) {
@@ -21,6 +21,8 @@
#include "common/host.h" #include "common/host.h"
LOG_MODULE_REGISTER(ISO_TIMER, CONFIG_BT_ISO_LOG_LEVEL);
static void iso_timer_cb(void *arg) static void iso_timer_cb(void *arg)
{ {
struct k_work *work = arg; struct k_work *work = arg;
@@ -51,13 +51,24 @@ static inline void k_mutex_delete(struct k_mutex *mutex)
mutex->handle = NULL; mutex->handle = NULL;
} }
/* Inline log helper with a fixed tag. These functions are inlined into many
* translation units (including api/ wrappers), and not all of them call
* LOG_MODULE_REGISTER, so we cannot reference the per-TU __iso_log_tag
* here. Use a hardcoded "ISO_MUTEX" tag instead, keeping the same level
* gating. */
#if CONFIG_BT_ISO_NO_LOG || (CONFIG_BT_ISO_LOG_LEVEL < BT_ISO_LOG_ERROR)
#define K_MUTEX_LOG_ERR(fmt, args...)
#else
#define K_MUTEX_LOG_ERR(fmt, args...) BT_ISO_LOGE("ISO_MUTEX", fmt, ## args)
#endif
static inline int k_mutex_lock(struct k_mutex *mutex, uint32_t timeout) static inline int k_mutex_lock(struct k_mutex *mutex, uint32_t timeout)
{ {
assert(mutex); assert(mutex);
assert(mutex->handle); assert(mutex->handle);
if (xSemaphoreTakeRecursive(mutex->handle, timeout) != pdTRUE) { if (xSemaphoreTakeRecursive(mutex->handle, timeout) != pdTRUE) {
LOG_ERR("KMutexLockFail"); K_MUTEX_LOG_ERR("LockFail");
return -EIO; return -EIO;
} }
@@ -70,7 +81,7 @@ static inline int k_mutex_unlock(struct k_mutex *mutex)
assert(mutex->handle); assert(mutex->handle);
if (xSemaphoreGiveRecursive(mutex->handle) != pdTRUE) { if (xSemaphoreGiveRecursive(mutex->handle) != pdTRUE) {
LOG_ERR("KMutexUnlockFail"); K_MUTEX_LOG_ERR("UnlockFail");
return -EIO; return -EIO;
} }
@@ -1,5 +1,6 @@
/* /*
* SPDX-FileCopyrightText: 2018 Nordic Semiconductor ASA * SPDX-FileCopyrightText: 2018 Nordic Semiconductor ASA
* SPDX-FileContributor: 2026 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@@ -14,15 +15,28 @@
#include "esp_log.h" #include "esp_log.h"
/* esp_ble_iso, esp_ble_audio and any future ISO consumer are compiled
* under the unified BLE_ISO compression channel and share one
* iso_log_index.h with one monotonic log-id counter — no per-consumer
* index header, no per-TU sentinel needed. */
#if CONFIG_BLE_ISO_COMPRESSED_LOG_ENABLE
#include "iso_log_index.h"
#endif
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
extern int ets_printf(const char *fmt, ...); /* Define a per-translation-unit log tag.
* The first argument is the module name (an identifier); it is stringified to
* produce the tag passed to esp_log_write(). LOG_MODULE_DECLARE has the same
* effect and is provided for Zephyr API parity (in our port the two expand to
* identical code). */
#define LOG_MODULE_REGISTER(name, ...) \
static const char *const __iso_log_tag __attribute__((unused)) = #name
#define LOG_MODULE_REGISTER(...) #define LOG_MODULE_DECLARE(name, ...) \
static const char *const __iso_log_tag __attribute__((unused)) = #name
#define LOG_MODULE_DECLARE(...)
#define BT_ISO_LOG_COLOR_BLACK "30" #define BT_ISO_LOG_COLOR_BLACK "30"
#define BT_ISO_LOG_COLOR_RED "31" #define BT_ISO_LOG_COLOR_RED "31"
@@ -47,14 +61,6 @@ extern int ets_printf(const char *fmt, ...);
#define BT_ISO_LOG_DEBUG 4 #define BT_ISO_LOG_DEBUG 4
#define BT_ISO_LOG_VERBOSE 5 #define BT_ISO_LOG_VERBOSE 5
#define BT_AUDIO_LOG_ERROR BT_ISO_LOG_ERROR
#define BT_AUDIO_LOG_WARN BT_ISO_LOG_WARN
#define BT_AUDIO_LOG_INFO BT_ISO_LOG_INFO
#define BT_AUDIO_LOG_DEBUG BT_ISO_LOG_DEBUG
#define BT_AUDIO_LOG_VERBOSE BT_ISO_LOG_VERBOSE
#define BT_ISO_LOG_TAG "ISO"
#define BT_ISO_LOGE(tag, format, ...) \ #define BT_ISO_LOGE(tag, format, ...) \
esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), \ esp_log_write(ESP_LOG_ERROR, tag, LOG_FORMAT(E, format), \
esp_log_timestamp(), tag, ##__VA_ARGS__); esp_log_timestamp(), tag, ##__VA_ARGS__);
@@ -78,25 +84,25 @@ extern int ets_printf(const char *fmt, ...);
#define LOG_DBG(fmt, args...) #define LOG_DBG(fmt, args...)
#else /* CONFIG_BT_ISO_NO_LOG */ #else /* CONFIG_BT_ISO_NO_LOG */
#if (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_ERROR) #if (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_ERROR)
#define LOG_ERR(fmt, args...) BT_ISO_LOGE(BT_ISO_LOG_TAG, fmt, ## args) #define LOG_ERR(fmt, args...) BT_ISO_LOGE(__iso_log_tag, fmt, ## args)
#else /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_ERROR) */ #else /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_ERROR) */
#define LOG_ERR(fmt, args...) #define LOG_ERR(fmt, args...)
#endif /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_ERROR) */ #endif /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_ERROR) */
#if (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_WARN) #if (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_WARN)
#define LOG_WRN(fmt, args...) BT_ISO_LOGW(BT_ISO_LOG_TAG, fmt, ## args) #define LOG_WRN(fmt, args...) BT_ISO_LOGW(__iso_log_tag, fmt, ## args)
#else /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_WARN) */ #else /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_WARN) */
#define LOG_WRN(fmt, args...) #define LOG_WRN(fmt, args...)
#endif /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_WARN) */ #endif /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_WARN) */
#if (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_INFO) #if (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_INFO)
#define LOG_INF(fmt, args...) BT_ISO_LOGI(BT_ISO_LOG_TAG, fmt, ## args) #define LOG_INF(fmt, args...) BT_ISO_LOGI(__iso_log_tag, fmt, ## args)
#else /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_INFO) */ #else /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_INFO) */
#define LOG_INF(fmt, args...) #define LOG_INF(fmt, args...)
#endif /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_INFO) */ #endif /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_INFO) */
#if (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_DEBUG) #if (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_DEBUG)
#define LOG_DBG(fmt, args...) BT_ISO_LOGD(BT_ISO_LOG_TAG, fmt, ## args) #define LOG_DBG(fmt, args...) BT_ISO_LOGD(__iso_log_tag, fmt, ## args)
#else /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_DEBUG) */ #else /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_DEBUG) */
#define LOG_DBG(fmt, args...) #define LOG_DBG(fmt, args...)
#endif /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_DEBUG) */ #endif /* (CONFIG_BT_ISO_LOG_LEVEL >= BT_ISO_LOG_DEBUG) */
@@ -10,6 +10,10 @@
#include "esp_log.h" #include "esp_log.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#if CONFIG_BLE_LOG_ENABLED
#include "ble_log.h"
#endif
#include "nimble/nimble_port.h" #include "nimble/nimble_port.h"
#include "nimble/nimble_port_freertos.h" #include "nimble/nimble_port_freertos.h"
@@ -221,18 +225,33 @@ esp_err_t bluetooth_init(void)
{ {
esp_err_t ret; esp_err_t ret;
/* When controller log is disabled (or running in v1 mode), the
* automatic ble_log_init() inside esp_bt_controller_init() is skipped.
* Init manually here so HOST/ISO/AUDIO compressed logs aren't dropped
* during NimBLE bring-up. The function is idempotent.
*
* TODO: Remove this block (and the ble_log_flush() below) once
* ble_log_init() is decoupled from the controller log path and
* owns its own initialization independently. */
#if CONFIG_BLE_LOG_ENABLED && \
!(CONFIG_BT_LE_CONTROLLER_LOG_ENABLED && CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2)
if (!ble_log_init()) {
ESP_LOGE(TAG, "Failed to init ble_log");
return ESP_FAIL;
}
#endif
example_audio_sem = xSemaphoreCreateBinary(); example_audio_sem = xSemaphoreCreateBinary();
if (example_audio_sem == NULL) { if (example_audio_sem == NULL) {
ESP_LOGE(TAG, "Failed to create audio semaphore"); ESP_LOGE(TAG, "Failed to create audio semaphore");
return ESP_FAIL; ret = ESP_FAIL;
goto err_log;
} }
ret = nimble_port_init(); ret = nimble_port_init();
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to init nimble %d ", ret); ESP_LOGE(TAG, "Failed to init nimble %d ", ret);
vSemaphoreDelete(example_audio_sem); goto err_sem;
example_audio_sem = NULL;
return ret;
} }
/* Initialize the NimBLE host configuration */ /* Initialize the NimBLE host configuration */
@@ -254,5 +273,27 @@ esp_err_t bluetooth_init(void)
xSemaphoreTake(example_audio_sem, portMAX_DELAY); xSemaphoreTake(example_audio_sem, portMAX_DELAY);
/* Drain startup-phase log buffers and emit a FLUSH boundary so the
* parser resets stats here — the example's runtime logs start clean.
*
* TODO: Remove together with the manual ble_log_init() above once
* ble_log_init() is decoupled from the controller log path. */
#if CONFIG_BLE_LOG_ENABLED
ble_log_flush();
#endif
return ESP_OK; return ESP_OK;
err_sem:
vSemaphoreDelete(example_audio_sem);
example_audio_sem = NULL;
err_log:
/* Mirror the manual ble_log_init() block above — same Kconfig gate so
* we only deinit what we initialized; the controller-owned path is
* left alone. */
#if CONFIG_BLE_LOG_ENABLED && \
!(CONFIG_BT_LE_CONTROLLER_LOG_ENABLED && CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2)
ble_log_deinit();
#endif
return ret;
} }
@@ -10,6 +10,10 @@
#include "esp_log.h" #include "esp_log.h"
#include "sdkconfig.h" #include "sdkconfig.h"
#if CONFIG_BLE_LOG_ENABLED
#include "ble_log.h"
#endif
#include "nimble/nimble_port.h" #include "nimble/nimble_port.h"
#include "nimble/nimble_port_freertos.h" #include "nimble/nimble_port_freertos.h"
@@ -56,18 +60,33 @@ esp_err_t bluetooth_init(void)
{ {
esp_err_t ret; esp_err_t ret;
/* When controller log is disabled (or running in v1 mode), the
* automatic ble_log_init() inside esp_bt_controller_init() is skipped.
* Init manually here so HOST/ISO/AUDIO compressed logs aren't dropped
* during NimBLE bring-up. The function is idempotent.
*
* TODO: Remove this block (and the ble_log_flush() below) once
* ble_log_init() is decoupled from the controller log path and
* owns its own initialization independently. */
#if CONFIG_BLE_LOG_ENABLED && \
!(CONFIG_BT_LE_CONTROLLER_LOG_ENABLED && CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2)
if (!ble_log_init()) {
ESP_LOGE(TAG, "Failed to init ble_log");
return ESP_FAIL;
}
#endif
example_iso_sem = xSemaphoreCreateBinary(); example_iso_sem = xSemaphoreCreateBinary();
if (example_iso_sem == NULL) { if (example_iso_sem == NULL) {
ESP_LOGE(TAG, "Failed to create iso semaphore"); ESP_LOGE(TAG, "Failed to create iso semaphore");
return ESP_FAIL; ret = ESP_FAIL;
goto err_log;
} }
ret = nimble_port_init(); ret = nimble_port_init();
if (ret != ESP_OK) { if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to init nimble %d ", ret); ESP_LOGE(TAG, "Failed to init nimble %d ", ret);
vSemaphoreDelete(example_iso_sem); goto err_sem;
example_iso_sem = NULL;
return ret;
} }
/* Initialize the NimBLE host configuration */ /* Initialize the NimBLE host configuration */
@@ -89,5 +108,27 @@ esp_err_t bluetooth_init(void)
xSemaphoreTake(example_iso_sem, portMAX_DELAY); xSemaphoreTake(example_iso_sem, portMAX_DELAY);
/* Drain startup-phase log buffers and emit a FLUSH boundary so the
* parser resets stats here — the example's runtime logs start clean.
*
* TODO: Remove together with the manual ble_log_init() above once
* ble_log_init() is decoupled from the controller log path. */
#if CONFIG_BLE_LOG_ENABLED
ble_log_flush();
#endif
return ESP_OK; return ESP_OK;
err_sem:
vSemaphoreDelete(example_iso_sem);
example_iso_sem = NULL;
err_log:
/* Mirror the manual ble_log_init() block above — same Kconfig gate so
* we only deinit what we initialized; the controller-owned path is
* left alone. */
#if CONFIG_BLE_LOG_ENABLED && \
!(CONFIG_BT_LE_CONTROLLER_LOG_ENABLED && CONFIG_BT_LE_CONTROLLER_LOG_MODE_BLE_LOG_V2)
ble_log_deinit();
#endif
return ret;
} }