Skip to content

Commit 322eb33

Browse files
author
Zhou Xiao
committed
fix(ble): copy acl data by omdata buffer copy
1 parent f2b6070 commit 322eb33

File tree

4 files changed

+64
-19
lines changed

4 files changed

+64
-19
lines changed

components/bt/common/ble_log/ble_log_spi_out.c

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@
8989
SPI_OUT_HCI_QUEUE_SIZE +\
9090
SPI_OUT_MESH_QUEUE_SIZE)
9191

92+
#if SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER
93+
#include "os/os_mbuf.h"
94+
#endif /* SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
95+
9296
// Private typedefs
9397
typedef struct {
9498
// CRITICAL: 0 for available, 1 for need queue (ISR), 2 for in queue
@@ -156,6 +160,7 @@ enum {
156160
LL_LOG_FLAG_ISR,
157161
LL_LOG_FLAG_HCI,
158162
LL_LOG_FLAG_RAW,
163+
LL_LOG_FLAG_OMDATA,
159164
LL_LOG_FLAG_HCI_UPSTREAM,
160165
};
161166

@@ -205,7 +210,7 @@ static inline void spi_out_log_cb_append_trans(spi_out_log_cb_t *log_cb);
205210
static inline void spi_out_log_cb_flush_trans(spi_out_log_cb_t *log_cb);
206211
static bool spi_out_log_cb_write(spi_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len,
207212
const uint8_t *addr_append, uint16_t len_append, uint8_t source,
208-
bool with_checksum);
213+
bool with_checksum, bool omdata);
209214
static void spi_out_log_cb_write_loss(spi_out_log_cb_t *log_cb);
210215
static void spi_out_log_cb_dump(spi_out_log_cb_t *log_cb);
211216

@@ -582,7 +587,7 @@ IRAM_ATTR static inline void spi_out_log_cb_flush_trans(spi_out_log_cb_t *log_cb
582587
// Return value: Need append
583588
IRAM_ATTR static bool spi_out_log_cb_write(spi_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len,
584589
const uint8_t *addr_append, uint16_t len_append, uint8_t source,
585-
bool with_checksum)
590+
bool with_checksum, bool omdata)
586591
{
587592
spi_out_trans_cb_t *trans_cb = log_cb->trans_cb[log_cb->trans_cb_idx];
588593

@@ -598,7 +603,16 @@ IRAM_ATTR static bool spi_out_log_cb_write(spi_out_log_cb_t *log_cb, const uint8
598603
memcpy(buf, (const uint8_t *)&head, SPI_OUT_FRAME_HEAD_LEN);
599604
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN, addr, len);
600605
if (len_append && addr_append) {
601-
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append);
606+
#if SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER
607+
if (omdata) {
608+
os_mbuf_copydata((struct os_mbuf *)addr_append, 0,
609+
len_append, buf + SPI_OUT_FRAME_HEAD_LEN + len);
610+
}
611+
else
612+
#endif /* SPI_OUT_LL_ENABLED && CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
613+
{
614+
memcpy(buf + SPI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append);
615+
}
602616
}
603617

604618
uint32_t checksum = 0;
@@ -628,7 +642,7 @@ IRAM_ATTR static void spi_out_log_cb_write_loss(spi_out_log_cb_t *log_cb)
628642
.lost_bytes_cnt = log_cb->lost_bytes_cnt,
629643
};
630644
spi_out_log_cb_write(log_cb, (const uint8_t *)&payload, sizeof(loss_payload_t),
631-
NULL, 0, BLE_LOG_SPI_OUT_SOURCE_LOSS, true);
645+
NULL, 0, BLE_LOG_SPI_OUT_SOURCE_LOSS, true, false);
632646

633647
log_cb->lost_frame_cnt = 0;
634648
log_cb->lost_bytes_cnt = 0;
@@ -756,9 +770,9 @@ static void spi_out_write_hex(spi_out_log_cb_t *log_cb, uint8_t source,
756770
if (with_ts) {
757771
uint32_t os_ts = pdTICKS_TO_MS(xTaskGetTickCount());
758772
need_append |= spi_out_log_cb_write(log_cb, (const uint8_t *)&os_ts,
759-
sizeof(uint32_t), addr, len, source, true);
773+
sizeof(uint32_t), addr, len, source, true, false);
760774
} else {
761-
need_append |= spi_out_log_cb_write(log_cb, addr, len, NULL, 0, source, true);
775+
need_append |= spi_out_log_cb_write(log_cb, addr, len, NULL, 0, source, true, false);
762776
}
763777
}
764778
if (need_append) {
@@ -1157,11 +1171,12 @@ IRAM_ATTR void ble_log_spi_out_ll_write(uint32_t len, const uint8_t *addr, uint3
11571171
log_cb = ll_task_log_cb;
11581172
source = BLE_LOG_SPI_OUT_SOURCE_ESP;
11591173
}
1174+
bool omdata = flag & BIT(LL_LOG_FLAG_OMDATA);
11601175

11611176
bool need_append;
11621177
if (spi_out_log_cb_check_trans(log_cb, (uint16_t)(len + len_append), &need_append)) {
11631178
need_append |= spi_out_log_cb_write(log_cb, addr, (uint16_t)len, addr_append,
1164-
(uint16_t)len_append, source, true);
1179+
(uint16_t)len_append, source, true, omdata);
11651180
}
11661181
if (need_append) {
11671182
if (in_isr) {
@@ -1288,7 +1303,7 @@ IRAM_ATTR void ble_log_spi_out_le_audio_write(const uint8_t *addr, uint16_t len)
12881303
bool need_append;
12891304
if (spi_out_log_cb_check_trans(log_cb, len, &need_append)) {
12901305
need_append |= spi_out_log_cb_write(log_cb, addr, len, NULL, 0,
1291-
BLE_LOG_SPI_OUT_SOURCE_LE_AUDIO, false);
1306+
BLE_LOG_SPI_OUT_SOURCE_LE_AUDIO, false, false);
12921307
}
12931308
if (need_append) {
12941309
spi_out_log_cb_append_trans(log_cb);

components/bt/common/ble_log/ble_log_uhci_out.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
#define UHCI_OUT_LL_QUEUE_SIZE (3 * UHCI_OUT_PING_PONG_BUF_CNT)
4040
#define UHCI_OUT_QUEUE_SIZE (UHCI_OUT_USER_QUEUE_SIZE + UHCI_OUT_LL_QUEUE_SIZE)
4141

42+
#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER
43+
#include "os/os_mbuf.h"
44+
#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
45+
4246
// Private typedefs
4347
typedef struct {
4448
// This flag is for multithreading, must be a word, do not modify
@@ -95,7 +99,8 @@ enum {
9599
LL_LOG_FLAG_ISR,
96100
LL_LOG_FLAG_HCI,
97101
LL_LOG_FLAG_RAW,
98-
LL_LOG_FLAG_SYNC
102+
LL_LOG_FLAG_OMDATA,
103+
LL_LOG_FLAG_HCI_UPSTREAM,
99104
};
100105

101106
enum {
@@ -136,7 +141,7 @@ static inline bool uhci_out_log_cb_check_trans(uhci_out_log_cb_t *log_cb, uint16
136141
static inline void uhci_out_log_cb_append_trans(uhci_out_log_cb_t *log_cb);
137142
static inline void uhci_out_log_cb_flush_trans(uhci_out_log_cb_t *log_cb);
138143
static bool uhci_out_log_cb_write(uhci_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len,
139-
const uint8_t *addr_append, uint16_t len_append, uint8_t source);
144+
const uint8_t *addr_append, uint16_t len_append, uint8_t source, bool omdata);
140145
static void uhci_out_log_cb_write_loss(uhci_out_log_cb_t *log_cb);
141146
static void uhci_out_log_cb_dump(uhci_out_log_cb_t *log_cb);
142147

@@ -318,7 +323,7 @@ IRAM_ATTR static inline void uhci_out_log_cb_flush_trans(uhci_out_log_cb_t *log_
318323

319324
// Return value: Need append
320325
IRAM_ATTR static bool uhci_out_log_cb_write(uhci_out_log_cb_t *log_cb, const uint8_t *addr, uint16_t len,
321-
const uint8_t *addr_append, uint16_t len_append, uint8_t source)
326+
const uint8_t *addr_append, uint16_t len_append, uint8_t source, bool omdata)
322327
{
323328
uhci_out_trans_cb_t *trans_cb = log_cb->trans_cb[log_cb->trans_cb_idx];
324329

@@ -334,7 +339,16 @@ IRAM_ATTR static bool uhci_out_log_cb_write(uhci_out_log_cb_t *log_cb, const uin
334339
memcpy(buf, (const uint8_t *)&head, UHCI_OUT_FRAME_HEAD_LEN);
335340
memcpy(buf + UHCI_OUT_FRAME_HEAD_LEN, addr, len);
336341
if (len_append && addr_append) {
337-
memcpy(buf + UHCI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append);
342+
#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER
343+
if (omdata) {
344+
os_mbuf_copydata((struct os_mbuf *)addr_append, 0,
345+
len_append, buf + UHCI_OUT_FRAME_HEAD_LEN + len);
346+
}
347+
else
348+
#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
349+
{
350+
memcpy(buf + UHCI_OUT_FRAME_HEAD_LEN + len, addr_append, len_append);
351+
}
338352
}
339353

340354
uint32_t checksum = 0;
@@ -365,7 +379,7 @@ IRAM_ATTR static void uhci_out_log_cb_write_loss(uhci_out_log_cb_t *log_cb)
365379
.lost_bytes_cnt = log_cb->lost_bytes_cnt,
366380
};
367381
uhci_out_log_cb_write(log_cb, (const uint8_t *)&payload, sizeof(loss_payload_t),
368-
NULL, 0, BLE_LOG_UHCI_OUT_SOURCE_LOSS);
382+
NULL, 0, BLE_LOG_UHCI_OUT_SOURCE_LOSS, false);
369383

370384
log_cb->lost_frame_cnt = 0;
371385
log_cb->lost_bytes_cnt = 0;
@@ -676,12 +690,13 @@ IRAM_ATTR void ble_log_uhci_out_ll_write(uint32_t len, const uint8_t *addr, uint
676690
log_cb = ll_task_log_cb;
677691
source = BLE_LOG_UHCI_OUT_SOURCE_ESP;
678692
}
693+
bool omdata = flag & BIT(LL_LOG_FLAG_OMDATA);
679694

680695
bool need_append;
681696
uint16_t frame_len = len + len_append + UHCI_OUT_FRAME_OVERHEAD;
682697
if (uhci_out_log_cb_check_trans(log_cb, frame_len, &need_append)) {
683698
need_append |= uhci_out_log_cb_write(log_cb, addr, len, addr_append,
684-
len_append, source);
699+
len_append, source, omdata);
685700
}
686701

687702
ll_last_write_ts = in_isr?\

components/bt/common/ble_log/src/ble_log_lbm.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
#include "ble_log_lbm.h"
1313
#include "ble_log_rt.h"
1414

15+
#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER
16+
#include "os/os_mbuf.h"
17+
#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
18+
1519
/* VARIABLE */
1620
BLE_LOG_STATIC volatile uint32_t lbm_ref_count = 0;
1721
BLE_LOG_STATIC bool lbm_inited = false;
@@ -25,7 +29,7 @@ BLE_LOG_STATIC void ble_log_lbm_release(ble_log_lbm_t *lbm);
2529
BLE_LOG_STATIC
2630
void ble_log_lbm_write_trans(ble_log_prph_trans_t **trans, ble_log_src_t src_code,
2731
const uint8_t *addr, uint16_t len,
28-
const uint8_t *addr_append, uint16_t len_append);
32+
const uint8_t *addr_append, uint16_t len_append, bool omdata);
2933
#if CONFIG_BLE_LOG_ENH_STAT_ENABLED
3034
BLE_LOG_STATIC void ble_log_stat_mgr_update(ble_log_src_t src_code, uint32_t len, bool lost);
3135
#endif /* CONFIG_BLE_LOG_ENH_STAT_ENABLED */
@@ -84,7 +88,7 @@ void ble_log_lbm_release(ble_log_lbm_t *lbm)
8488
BLE_LOG_IRAM_ATTR BLE_LOG_STATIC
8589
void ble_log_lbm_write_trans(ble_log_prph_trans_t **trans, ble_log_src_t src_code,
8690
const uint8_t *addr, uint16_t len,
87-
const uint8_t *addr_append, uint16_t len_append)
91+
const uint8_t *addr_append, uint16_t len_append, bool omdata)
8892
{
8993
/* Preparation before writing */
9094
uint8_t *buf = (*trans)->buf + (*trans)->pos;
@@ -102,7 +106,16 @@ void ble_log_lbm_write_trans(ble_log_prph_trans_t **trans, ble_log_src_t src_cod
102106
BLE_LOG_MEMCPY(buf + BLE_LOG_FRAME_HEAD_LEN, addr, len);
103107
}
104108
if (len_append) {
105-
BLE_LOG_MEMCPY(buf + BLE_LOG_FRAME_HEAD_LEN + len, addr_append, len_append);
109+
#if CONFIG_SOC_ESP_NIMBLE_CONTROLLER
110+
if (omdata) {
111+
os_mbuf_copydata((struct os_mbuf *)addr_append, 0,
112+
len_append, buf + BLE_LOG_FRAME_HEAD_LEN + len);
113+
}
114+
else
115+
#endif /* CONFIG_SOC_ESP_NIMBLE_CONTROLLER */
116+
{
117+
BLE_LOG_MEMCPY(buf + BLE_LOG_FRAME_HEAD_LEN + len, addr_append, len_append);
118+
}
106119
}
107120

108121
/* Data integrity check */
@@ -429,7 +442,7 @@ bool ble_log_write_hex(ble_log_src_t src_code, const uint8_t *addr, size_t len)
429442
xTaskGetTickCountFromISR():
430443
xTaskGetTickCount());
431444
ble_log_lbm_write_trans(trans, src_code, (const uint8_t *)&os_ts,
432-
sizeof(uint32_t), addr, len);
445+
sizeof(uint32_t), addr, len, false);
433446

434447
/* Release */
435448
ble_log_lbm_release(lbm);
@@ -467,6 +480,7 @@ void ble_log_write_hex_ll(uint32_t len, const uint8_t *addr,
467480
src_code = BLE_LOG_SRC_LL_TASK;
468481
use_ll_task = true;
469482
}
483+
bool omdata = flag & BIT(BLE_LOG_LL_FLAG_OMDATA);
470484

471485
if (!lbm_enabled) {
472486
goto exit;
@@ -489,7 +503,7 @@ void ble_log_write_hex_ll(uint32_t len, const uint8_t *addr,
489503
}
490504

491505
/* Write transport */
492-
ble_log_lbm_write_trans(trans, src_code, addr, len, addr_append, len_append);
506+
ble_log_lbm_write_trans(trans, src_code, addr, len, addr_append, len_append, omdata);
493507

494508
ble_log_lbm_release(lbm);
495509
BLE_LOG_REF_COUNT_RELEASE(&lbm_ref_count);

components/bt/common/ble_log/src/internal_include/ble_log_lbm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ enum {
158158
BLE_LOG_LL_FLAG_ISR,
159159
BLE_LOG_LL_FLAG_HCI,
160160
BLE_LOG_LL_FLAG_RAW,
161+
BLE_LOG_LL_FLAG_OMDATA,
161162
BLE_LOG_LL_FLAG_HCI_UPSTREAM,
162163
};
163164
#endif /* CONFIG_BLE_LOG_LL_ENABLED */

0 commit comments

Comments
 (0)