Skip to content

Commit b9dbc2e

Browse files
author
Zhou Xiao
committed
feat(ble): refactored ble log module with layered design
1 parent ee92f13 commit b9dbc2e

21 files changed

+2745
-0
lines changed

components/bt/CMakeLists.txt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,42 @@ if(CONFIG_BT_ENABLED)
140140
"common/ble_log/ble_log_uhci_out.c"
141141
)
142142

143+
# BLE Log Module
144+
if(CONFIG_BLE_LOG_ENABLED)
145+
# Core source files
146+
list(APPEND srcs
147+
common/ble_log/src/ble_log.c
148+
common/ble_log/src/ble_log_lbm.c
149+
common/ble_log/src/ble_log_rt.c
150+
common/ble_log/src/ble_log_util.c
151+
)
152+
153+
# Includes
154+
list(APPEND include_dirs
155+
common/ble_log/include
156+
)
157+
158+
# Private includes
159+
list(APPEND priv_include_dirs
160+
common/ble_log/src/internal_include
161+
common/ble_log/src/internal_include/prph
162+
)
163+
164+
# Timestamp synchronization extension
165+
if(CONFIG_BLE_LOG_TS_ENABLED)
166+
list(APPEND srcs common/ble_log/src/ble_log_ts.c)
167+
endif()
168+
169+
# Peripheral interface implementation
170+
if(CONFIG_BLE_LOG_PRPH_DUMMY)
171+
list(APPEND srcs common/ble_log/src/prph/ble_log_prph_dummy.c)
172+
elseif(CONFIG_BLE_LOG_PRPH_SPI_MASTER_DMA)
173+
list(APPEND srcs common/ble_log/src/prph/ble_log_prph_spi_master_dma.c)
174+
elseif(CONFIG_BLE_LOG_PRPH_UART_DMA)
175+
list(APPEND srcs common/ble_log/src/prph/ble_log_prph_uart_dma.c)
176+
endif()
177+
endif()
178+
143179
# Host Bluedroid
144180
if(CONFIG_BT_BLUEDROID_ENABLED)
145181

@@ -967,6 +1003,13 @@ if(CONFIG_BT_ENABLED)
9671003
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=uart_write_bytes")
9681004
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=uart_write_bytes_with_break")
9691005
endif()
1006+
if(DEFINED CONFIG_BLE_LOG_PRPH_UART_DMA_PORT)
1007+
if(CONFIG_BLE_LOG_PRPH_UART_DMA_PORT EQUAL 0)
1008+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=uart_tx_chars")
1009+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=uart_write_bytes")
1010+
target_link_libraries(${COMPONENT_LIB} INTERFACE "-Wl,--wrap=uart_write_bytes_with_break")
1011+
endif()
1012+
endif()
9701013
if(CONFIG_IDF_TARGET_ESP32C6)
9711014
add_prebuilt_library(libble_app
9721015
"${CMAKE_CURRENT_LIST_DIR}/controller/lib_esp32c6/esp32c6-bt-lib/esp32c6/libble_app.a"

components/bt/common/Kconfig.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ config BT_ALARM_MAX_NUM
66
This option decides the maximum number of alarms which
77
could be used by Bluetooth host.
88

9+
menu "BLE Log"
10+
source "$IDF_PATH/components/bt/common/ble_log/Kconfig.in"
11+
endmenu
12+
913
config BT_BLE_LOG_SPI_OUT_ENABLED
1014
bool "Output ble logs to SPI bus (Experimental)"
1115
default n
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
config BLE_LOG_ENABLED
2+
bool "Enable BLE Log Module (Experimental)"
3+
default n
4+
help
5+
Enable BLE Log Module
6+
7+
if BLE_LOG_ENABLED
8+
config BLE_LOG_LBM_TRANS_SIZE
9+
int "Buffer size for each peripheral transport"
10+
default 512
11+
help
12+
There're 2 log buffer managers (LBMs) with compare-and-swap
13+
(CAS) protection, 1 LBM with FreeRTOS mutex protection, 1 LBM
14+
without protection for critical section. Each LBM is managing
15+
2 ping-pong buffers, which means there will be 4 * 2 *
16+
BLE_LOG_LBM_TRANS_SIZE bytes buffer allocated
17+
18+
config BLE_LOG_LBM_ATOMIC_LOCK_TASK_CNT
19+
int "Count of log buffer managers with atomic lock protection for task context"
20+
default 2
21+
help
22+
BLE Log module will search for an LBM with atomic lock protection first; if
23+
all LBMs with atomic lock protection are unavailable, BLE Log module will
24+
try to use the LBM with spin lock protection. So the more LBMs with atomic
25+
lock protection are created, the better the logging performance will be.
26+
27+
config BLE_LOG_LBM_ATOMIC_LOCK_ISR_CNT
28+
int "Count of log buffer managers with atomic lock protection for ISR context"
29+
default 1
30+
help
31+
BLE Log module will search for an LBM with atomic lock protection first; if
32+
all LBMs with atomic lock protection are unavailable, BLE Log module will
33+
try to use the LBM with spin lock protection. So the more LBMs with atomic
34+
lock protection are created, the more ISRs can nest.
35+
36+
config BLE_LOG_LL_ENABLED
37+
bool "Enable BLE Log for Link Layer"
38+
depends on BT_CONTROLLER_ENABLED
39+
default y
40+
select BT_LE_CONTROLLER_LOG_ENABLED
41+
select BT_LE_CONTROLLER_LOG_MODE_BLE_LOG
42+
help
43+
Enable BLE Log for Link Layer
44+
45+
config BLE_LOG_LBM_LL_TRANS_SIZE
46+
int "Buffer size for each peripheral transport of Link Layer LBM"
47+
depends on BLE_LOG_LL_ENABLED
48+
default 1024
49+
help
50+
There're 2 Link Layer dedicated log buffer managers (LBMs) with
51+
compare-and-swap (CAS) protection. Each LBM is managing 2 ping-
52+
pong buffers, which means there will be additional 2 * 2 *
53+
BLE_LOG_LBM_LL_TRANS_SIZE bytes buffer allocated
54+
55+
config BLE_LOG_PAYLOAD_CHECKSUM_ENABLED
56+
bool "Enable payload checksum for BLE Log data integrity check"
57+
default y
58+
help
59+
Checksum is the default method for BLE Log data integrity check,
60+
but for targets with slow CPU speed, it may cause significant system
61+
performance decrease; a compromise could be made to balance the
62+
realtime performance and log data integrity, which is calculating the
63+
checksum of frame head and payload all together by default, or only
64+
calculate the checksum of frame head to minimize performance decrease
65+
66+
config BLE_LOG_ENH_STAT_ENABLED
67+
bool "Enable enhanced statistics for BLE Log"
68+
default n
69+
help
70+
Enable enhanced statistics for written/lost frame/bytes count, which may
71+
cost additional ~100kB memory
72+
73+
config BLE_LOG_TS_ENABLED
74+
bool "Enable BLE Log Timestamp Synchronization (TS)"
75+
default n
76+
help
77+
Enable BLE Log TS with external logging module
78+
79+
config BLE_LOG_SYNC_IO_NUM
80+
int "GPIO number for Timestamp Synchronization (TS) toggle output"
81+
depends on BLE_LOG_TS_ENABLED
82+
default 0
83+
help
84+
GPIO number for TS toggle output
85+
86+
choice BLE_LOG_PRPH_CHOICE
87+
prompt "BLE Log peripheral choice"
88+
default BLE_LOG_PRPH_DUMMY
89+
help
90+
Choose BLE Log peripheral
91+
92+
config BLE_LOG_PRPH_DUMMY
93+
bool "Dummy transport"
94+
help
95+
Dummy transport (dump only)
96+
97+
config BLE_LOG_PRPH_SPI_MASTER_DMA
98+
bool "Utilize SPI master DMA driver as transport"
99+
help
100+
Utilize SPI master DMA driver as transport
101+
102+
config BLE_LOG_PRPH_UART_DMA
103+
bool "Utilize UART DMA driver as transport"
104+
help
105+
Utilize UART DMA driver as transport
106+
endchoice
107+
108+
if BLE_LOG_PRPH_SPI_MASTER_DMA
109+
config BLE_LOG_PRPH_SPI_MASTER_DMA_MOSI_IO_NUM
110+
int "GPIO number of MOSI port for SPI master DMA transport"
111+
default 0
112+
help
113+
GPIO number of MOSI port for SPI master DMA transport
114+
115+
config BLE_LOG_PRPH_SPI_MASTER_DMA_SCLK_IO_NUM
116+
int "GPIO number of SCLK port for SPI master DMA transport"
117+
default 0
118+
help
119+
GPIO number of SCLK port for SPI master DMA transport
120+
121+
config BLE_LOG_PRPH_SPI_MASTER_DMA_CS_IO_NUM
122+
int "GPIO number of CS port for SPI master DMA transport"
123+
default 0
124+
help
125+
GPIO number of CS port for SPI master DMA transport
126+
endif
127+
128+
if BLE_LOG_PRPH_UART_DMA
129+
config BLE_LOG_PRPH_UART_DMA_PORT
130+
int "UART port number for UART DMA transport"
131+
default 0
132+
help
133+
UART port number for UART DMA
134+
135+
config BLE_LOG_PRPH_UART_DMA_BAUD_RATE
136+
int "Baud rate of UART port for UART DMA transport"
137+
default 921600
138+
help
139+
Determine the baud rate of UART port
140+
141+
config BLE_LOG_PRPH_UART_DMA_TX_IO_NUM
142+
int "GPIO number for UART TX"
143+
default 0
144+
help
145+
GPIO number for UART TX
146+
endif
147+
endif

0 commit comments

Comments
 (0)