bt: Remove SPP default send buffer size option and add parameters to configure send buffer size in esp_spp_enhance_init()

This commit is contained in:
xiongweichao 2022-11-17 10:46:52 +08:00 committed by BOT
parent c2c9b090c7
commit 654e198464
9 changed files with 22 additions and 24 deletions

View File

@ -61,15 +61,6 @@ config BT_SPP_ENABLED
help help
This enables the Serial Port Profile This enables the Serial Port Profile
config BT_SPP_SEND_BUF_DEFAULT
int "SPP default send buffer size"
depends on BT_SPP_ENABLED
range 100 10000
default 4000
help
Sets the default send buffer size for new SPP channels. Setting a smaller
default SNDBUF size can save some memory, but may decrease performance.
config BT_L2CAP_ENABLED config BT_L2CAP_ENABLED
bool "BT L2CAP" bool "BT L2CAP"
depends on BT_CLASSIC_ENABLED depends on BT_CLASSIC_ENABLED

View File

@ -38,6 +38,7 @@ esp_err_t esp_spp_init(esp_spp_mode_t mode)
esp_spp_cfg_t bt_spp_cfg = { esp_spp_cfg_t bt_spp_cfg = {
.mode = mode, .mode = mode,
.enable_l2cap_ertm = true, .enable_l2cap_ertm = true,
.tx_buffer_size = ESP_SPP_MAX_TX_BUFFER_SIZE,
}; };
return esp_spp_enhanced_init(&bt_spp_cfg); return esp_spp_enhanced_init(&bt_spp_cfg);
@ -49,12 +50,19 @@ esp_err_t esp_spp_enhanced_init(const esp_spp_cfg_t *cfg)
btc_spp_args_t arg; btc_spp_args_t arg;
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED); ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
if (cfg->mode == ESP_SPP_MODE_VFS && (cfg->tx_buffer_size < ESP_SPP_MIN_TX_BUFFER_SIZE ||
cfg->tx_buffer_size > ESP_SPP_MAX_TX_BUFFER_SIZE)) {
LOG_WARN("Invalid tx buffer size");
return ESP_ERR_INVALID_ARG;
}
msg.sig = BTC_SIG_API_CALL; msg.sig = BTC_SIG_API_CALL;
msg.pid = BTC_PID_SPP; msg.pid = BTC_PID_SPP;
msg.act = BTC_SPP_ACT_INIT; msg.act = BTC_SPP_ACT_INIT;
arg.init.mode = cfg->mode; arg.init.mode = cfg->mode;
arg.init.enable_l2cap_ertm = cfg->enable_l2cap_ertm; arg.init.enable_l2cap_ertm = cfg->enable_l2cap_ertm;
arg.init.tx_buffer_size = cfg->tx_buffer_size;
return (btc_transfer_context(&msg, &arg, sizeof(btc_spp_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); return (btc_transfer_context(&msg, &arg, sizeof(btc_spp_args_t), NULL) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
} }

View File

@ -16,6 +16,8 @@ extern "C" {
#define ESP_SPP_MAX_MTU (3*330) /*!< SPP max MTU */ #define ESP_SPP_MAX_MTU (3*330) /*!< SPP max MTU */
#define ESP_SPP_MAX_SCN 31 /*!< SPP max SCN */ #define ESP_SPP_MAX_SCN 31 /*!< SPP max SCN */
#define ESP_SPP_MIN_TX_BUFFER_SIZE 100 /*!< SPP min tx buffer */
#define ESP_SPP_MAX_TX_BUFFER_SIZE (ESP_SPP_MAX_MTU * 10) /*!< SPP max tx buffer size */
/** /**
* @brief SPP default configuration * @brief SPP default configuration
@ -23,6 +25,7 @@ extern "C" {
#define BT_SPP_DEFAULT_CONFIG() { \ #define BT_SPP_DEFAULT_CONFIG() { \
.mode = ESP_SPP_MODE_VFS, \ .mode = ESP_SPP_MODE_VFS, \
.enable_l2cap_ertm = true, \ .enable_l2cap_ertm = true, \
.tx_buffer_size = ESP_SPP_MAX_TX_BUFFER_SIZE, \
} }
/* Security Setting Mask /* Security Setting Mask
@ -68,6 +71,7 @@ typedef enum {
typedef struct { typedef struct {
esp_spp_mode_t mode; /*!< Choose the mode of SPP, ESP_SPP_MODE_CB or ESP_SPP_MODE_VFS. */ esp_spp_mode_t mode; /*!< Choose the mode of SPP, ESP_SPP_MODE_CB or ESP_SPP_MODE_VFS. */
bool enable_l2cap_ertm; /*!< Enable/disable Logical Link Control and Adaptation Layer Protocol enhanced retransmission mode. */ bool enable_l2cap_ertm; /*!< Enable/disable Logical Link Control and Adaptation Layer Protocol enhanced retransmission mode. */
uint16_t tx_buffer_size; /*!< Tx buffer size for a new SPP channel. A smaller setting can save memory, but may incur a decrease in throughput. Only for ESP_SPP_MODE_VFS mode. */
} esp_spp_cfg_t; } esp_spp_cfg_t;
/** /**

View File

@ -37,6 +37,7 @@ typedef union {
struct init_arg { struct init_arg {
esp_spp_mode_t mode; esp_spp_mode_t mode;
bool enable_l2cap_ertm; bool enable_l2cap_ertm;
UINT16 tx_buffer_size;
} init; } init;
//BTC_SPP_ACT_UNINIT //BTC_SPP_ACT_UNINIT
struct uninit_arg { struct uninit_arg {

View File

@ -76,6 +76,7 @@ typedef struct {
} spp_slot_t; } spp_slot_t;
typedef struct { typedef struct {
uint16_t tx_buffer_size;
spp_slot_t *spp_slots[MAX_RFC_PORTS + 1]; spp_slot_t *spp_slots[MAX_RFC_PORTS + 1];
uint32_t spp_slot_id; uint32_t spp_slot_id;
esp_spp_mode_t spp_mode; esp_spp_mode_t spp_mode;
@ -162,7 +163,7 @@ static spp_slot_t *spp_malloc_slot(void)
goto err; goto err;
} }
} else { } else {
if (((*slot)->ringbuf_write = xRingbufferCreate(BTC_SPP_SEND_BUF_DEFAULT, RINGBUF_TYPE_BYTEBUF)) == NULL) { if (((*slot)->ringbuf_write = xRingbufferCreate(spp_local_param.tx_buffer_size, RINGBUF_TYPE_BYTEBUF)) == NULL) {
BTC_TRACE_ERROR("%s write ringbuffer create error!", __func__); BTC_TRACE_ERROR("%s write ringbuffer create error!", __func__);
err_no = 2; err_no = 2;
goto err; goto err;
@ -547,6 +548,7 @@ static void btc_spp_init(btc_spp_args_t *arg)
} }
spp_local_param.spp_mode = arg->init.mode; spp_local_param.spp_mode = arg->init.mode;
spp_local_param.spp_slot_id = 0; spp_local_param.spp_slot_id = 0;
spp_local_param.tx_buffer_size = arg->init.tx_buffer_size;
BTA_JvEnable((tBTA_JV_DM_CBACK *)btc_spp_dm_inter_cb); BTA_JvEnable((tBTA_JV_DM_CBACK *)btc_spp_dm_inter_cb);
BTA_JvRfcommConfig(arg->init.enable_l2cap_ertm); BTA_JvRfcommConfig(arg->init.enable_l2cap_ertm);
} while (0); } while (0);
@ -1102,7 +1104,7 @@ void btc_spp_cb_handler(btc_msg_t *msg)
slot->is_writing = false; slot->is_writing = false;
slot->write_data_len = 0; slot->write_data_len = 0;
vRingbufferGetInfo(slot->ringbuf_write, NULL, NULL, NULL, NULL, &items_waiting); vRingbufferGetInfo(slot->ringbuf_write, NULL, NULL, NULL, NULL, &items_waiting);
if (BTC_SPP_SEND_BUF_DEFAULT > items_waiting) { if (spp_local_param.tx_buffer_size > items_waiting) {
xEventGroupSetBits(spp_local_param.tx_event_group, SLOT_WRITE_BIT(serial)); xEventGroupSetBits(spp_local_param.tx_event_group, SLOT_WRITE_BIT(serial));
} }
if (items_waiting == 0) { if (items_waiting == 0) {
@ -1436,12 +1438,12 @@ static ssize_t spp_vfs_write(int fd, const void * data, size_t size)
items_waiting = 0; items_waiting = 0;
item_size = 0; item_size = 0;
vRingbufferGetInfo(slot->ringbuf_write, NULL, NULL, NULL, NULL, &items_waiting); vRingbufferGetInfo(slot->ringbuf_write, NULL, NULL, NULL, NULL, &items_waiting);
if (items_waiting < BTC_SPP_SEND_BUF_DEFAULT) { if (items_waiting < spp_local_param.tx_buffer_size) {
if ((BTC_SPP_SEND_BUF_DEFAULT - items_waiting) > size) { if ((spp_local_param.tx_buffer_size - items_waiting) > size) {
item_size = size; item_size = size;
done = xRingbufferSend(slot->ringbuf_write, (void *)data + sent, item_size, 0); done = xRingbufferSend(slot->ringbuf_write, (void *)data + sent, item_size, 0);
} else { } else {
item_size = BTC_SPP_SEND_BUF_DEFAULT - items_waiting; item_size = spp_local_param.tx_buffer_size - items_waiting;
done = xRingbufferSend(slot->ringbuf_write, (void *)data + sent, item_size, 0); done = xRingbufferSend(slot->ringbuf_write, (void *)data + sent, item_size, 0);
} }

View File

@ -296,12 +296,6 @@
#define UC_BT_HFP_WBS_ENABLE FALSE #define UC_BT_HFP_WBS_ENABLE FALSE
#endif #endif
#ifdef CONFIG_BT_SPP_SEND_BUF_DEFAULT
#define UC_BT_SPP_SEND_BUF_DEFAULT CONFIG_BT_SPP_SEND_BUF_DEFAULT
#else
#define UC_BT_SPP_SEND_BUF_DEFAULT 0
#endif
/********************************************************** /**********************************************************
* Memory reference * Memory reference
**********************************************************/ **********************************************************/

View File

@ -351,10 +351,6 @@
#define SBC_ENC_INCLUDED FALSE #define SBC_ENC_INCLUDED FALSE
#endif #endif
#ifndef BTC_SPP_SEND_BUF_DEFAULT
#define BTC_SPP_SEND_BUF_DEFAULT UC_BT_SPP_SEND_BUF_DEFAULT
#endif
/****************************************************************************** /******************************************************************************
** **
** BTA-layer components ** BTA-layer components

View File

@ -245,6 +245,7 @@ void app_main(void)
esp_spp_cfg_t bt_spp_cfg = { esp_spp_cfg_t bt_spp_cfg = {
.mode = esp_spp_mode, .mode = esp_spp_mode,
.enable_l2cap_ertm = esp_spp_enable_l2cap_ertm, .enable_l2cap_ertm = esp_spp_enable_l2cap_ertm,
.tx_buffer_size = 0, /* Only used for ESP_SPP_MODE_VFS mode */
}; };
if ((ret = esp_spp_enhanced_init(&bt_spp_cfg)) != ESP_OK) { if ((ret = esp_spp_enhanced_init(&bt_spp_cfg)) != ESP_OK) {
ESP_LOGE(SPP_TAG, "%s spp init failed: %s\n", __func__, esp_err_to_name(ret)); ESP_LOGE(SPP_TAG, "%s spp init failed: %s\n", __func__, esp_err_to_name(ret));

View File

@ -388,6 +388,7 @@ void app_main(void)
esp_spp_cfg_t bt_spp_cfg = { esp_spp_cfg_t bt_spp_cfg = {
.mode = esp_spp_mode, .mode = esp_spp_mode,
.enable_l2cap_ertm = esp_spp_enable_l2cap_ertm, .enable_l2cap_ertm = esp_spp_enable_l2cap_ertm,
.tx_buffer_size = 0, /* Only used for ESP_SPP_MODE_VFS mode */
}; };
if ((ret = esp_spp_enhanced_init(&bt_spp_cfg)) != ESP_OK) { if ((ret = esp_spp_enhanced_init(&bt_spp_cfg)) != ESP_OK) {
ESP_LOGE(SPP_TAG, "%s spp init failed: %s\n", __func__, esp_err_to_name(ret)); ESP_LOGE(SPP_TAG, "%s spp init failed: %s\n", __func__, esp_err_to_name(ret));