Bläddra i källkod

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

xiongweichao 3 år sedan
förälder
incheckning
c497d7d6c1

+ 0 - 9
components/bt/host/bluedroid/Kconfig.in

@@ -61,15 +61,6 @@ config BT_SPP_ENABLED
     help
         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
     bool "BT L2CAP"
     depends on BT_CLASSIC_ENABLED

+ 8 - 0
components/bt/host/bluedroid/api/esp_spp_api.c

@@ -38,6 +38,7 @@ esp_err_t esp_spp_init(esp_spp_mode_t mode)
     esp_spp_cfg_t bt_spp_cfg = {
         .mode = mode,
         .enable_l2cap_ertm = true,
+        .tx_buffer_size = ESP_SPP_MAX_TX_BUFFER_SIZE,
     };
 
     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;
     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.pid = BTC_PID_SPP;
     msg.act = BTC_SPP_ACT_INIT;
 
     arg.init.mode = cfg->mode;
     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);
 }

+ 4 - 0
components/bt/host/bluedroid/api/include/api/esp_spp_api.h

@@ -16,6 +16,8 @@ extern "C" {
 
 #define ESP_SPP_MAX_MTU                 (3*330)     /*!< SPP max MTU */
 #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
@@ -23,6 +25,7 @@ extern "C" {
 #define BT_SPP_DEFAULT_CONFIG() { \
     .mode = ESP_SPP_MODE_VFS, \
     .enable_l2cap_ertm = true, \
+    .tx_buffer_size = ESP_SPP_MAX_TX_BUFFER_SIZE, \
 }
 
 /* Security Setting Mask
@@ -68,6 +71,7 @@ typedef enum {
 typedef struct {
     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. */
+    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;
 
 /**

+ 1 - 0
components/bt/host/bluedroid/btc/profile/std/include/btc_spp.h

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

+ 7 - 5
components/bt/host/bluedroid/btc/profile/std/spp/btc_spp.c

@@ -76,6 +76,7 @@ typedef struct {
 } spp_slot_t;
 
 typedef struct {
+    uint16_t tx_buffer_size;
     spp_slot_t *spp_slots[MAX_RFC_PORTS + 1];
     uint32_t spp_slot_id;
     esp_spp_mode_t spp_mode;
@@ -162,7 +163,7 @@ static spp_slot_t *spp_malloc_slot(void)
                     goto err;
                 }
             } 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__);
                     err_no = 2;
                     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_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_JvRfcommConfig(arg->init.enable_l2cap_ertm);
     } while (0);
@@ -1102,7 +1104,7 @@ void btc_spp_cb_handler(btc_msg_t *msg)
                     slot->is_writing = false;
                     slot->write_data_len = 0;
                     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));
                     }
                     if (items_waiting == 0) {
@@ -1435,12 +1437,12 @@ static ssize_t spp_vfs_write(int fd, const void * data, size_t size)
             items_waiting = 0;
             item_size = 0;
             vRingbufferGetInfo(slot->ringbuf_write, NULL, NULL, NULL, NULL, &items_waiting);
-            if (items_waiting < BTC_SPP_SEND_BUF_DEFAULT) {
-                if ((BTC_SPP_SEND_BUF_DEFAULT - items_waiting) > size) {
+            if (items_waiting < spp_local_param.tx_buffer_size) {
+                if ((spp_local_param.tx_buffer_size - items_waiting) > size) {
                     item_size = size;
                     done = xRingbufferSend(slot->ringbuf_write, (void *)data + sent, item_size, 0);
                 } 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);
                 }
 

+ 0 - 6
components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h

@@ -296,12 +296,6 @@
 #define UC_BT_HFP_WBS_ENABLE                    FALSE
 #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
  **********************************************************/

+ 0 - 4
components/bt/host/bluedroid/common/include/common/bt_target.h

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

+ 1 - 0
examples/bluetooth/bluedroid/classic_bt/bt_spp_acceptor/main/main.c

@@ -245,6 +245,7 @@ void app_main(void)
     esp_spp_cfg_t bt_spp_cfg = {
         .mode = esp_spp_mode,
         .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) {
         ESP_LOGE(SPP_TAG, "%s spp init failed: %s\n", __func__, esp_err_to_name(ret));

+ 1 - 0
examples/bluetooth/bluedroid/classic_bt/bt_spp_initiator/main/main.c

@@ -388,6 +388,7 @@ void app_main(void)
     esp_spp_cfg_t bt_spp_cfg = {
         .mode = esp_spp_mode,
         .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) {
         ESP_LOGE(SPP_TAG, "%s spp init failed: %s\n", __func__, esp_err_to_name(ret));