Просмотр исходного кода

Nimble: Added return value (success / failure ) to nimble_port_init

Rahul Tank 3 лет назад
Родитель
Сommit
826495a145
23 измененных файлов с 144 добавлено и 49 удалено
  1. 1 1
      components/bt/host/nimble/nimble
  2. 15 2
      components/bt/porting/nimble/include/nimble/nimble_port.h
  3. 5 1
      components/protocomm/src/transports/protocomm_nimble.c
  4. 8 1
      examples/bluetooth/esp_ble_mesh/common_components/example_init/ble_mesh_example_init.c
  5. 3 1
      examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c
  6. 6 1
      examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c
  7. 7 1
      examples/bluetooth/nimble/ble_periodic_adv/main/main.c
  8. 6 1
      examples/bluetooth/nimble/ble_periodic_sync/main/main.c
  9. 6 1
      examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c
  10. 6 1
      examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c
  11. 5 1
      examples/bluetooth/nimble/ble_spp/spp_client/main/main.c
  12. 5 1
      examples/bluetooth/nimble/ble_spp/spp_server/main/main.c
  13. 12 2
      examples/bluetooth/nimble/blecent/main/main.c
  14. 6 1
      examples/bluetooth/nimble/blehr/main/main.c
  15. 5 1
      examples/bluetooth/nimble/blemesh/main/app_mesh.c
  16. 5 1
      examples/bluetooth/nimble/bleprph/main/main.c
  17. 5 1
      examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c
  18. 5 1
      examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c
  19. 6 1
      examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c
  20. 1 1
      examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c
  21. 18 12
      examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c
  22. 8 14
      examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h
  23. 0 1
      tools/ci/check_copyright_ignore.txt

+ 1 - 1
components/bt/host/nimble/nimble

@@ -1 +1 @@
-Subproject commit 2412a15acc9cf250f25f541b21ef0edeb1d22fae
+Subproject commit f30278d3ab70d79791243bf329471043b309719c

+ 15 - 2
components/bt/porting/nimble/include/nimble/nimble_port.h

@@ -35,8 +35,21 @@
 extern "C" {
 #endif
 
-void nimble_port_init(void);
-void nimble_port_deinit(void);
+/**
+* @brief nimble_port_init - Initialize controller and NimBLE host stack
+*
+* @return esp_err_t   - ESP_OK ( if success)
+*                       Error code in case of failure
+*/
+esp_err_t nimble_port_init(void);
+
+/**
+* @brief nimble_port_deinit - Deinitialize controller and NimBLE host stack
+*
+* @return esp_err_t   - ESP_OK ( if success)
+*                       Error code in case of failure
+*/
+esp_err_t nimble_port_deinit(void);
 
 void nimble_port_run(void);
 int nimble_port_stop(void);

+ 5 - 1
components/protocomm/src/transports/protocomm_nimble.c

@@ -494,7 +494,11 @@ static int simple_ble_start(const simple_ble_cfg_t *cfg)
     int rc;
     ESP_LOGD(TAG, "Free memory at start of simple_ble_init %" PRIu32, esp_get_free_heap_size());
 
-    nimble_port_init();
+    rc = nimble_port_init();
+    if (rc != ESP_OK) {
+        ESP_LOGE(TAG, "Failed to init nimble %d ", rc);
+        return rc;
+    }
 
     /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = simple_ble_on_reset;

+ 8 - 1
examples/bluetooth/esp_ble_mesh/common_components/example_init/ble_mesh_example_init.c

@@ -132,13 +132,20 @@ void mesh_host_task(void *param)
 
 esp_err_t bluetooth_init(void)
 {
+    esp_err_t ret;
+
     mesh_sem = xSemaphoreCreateBinary();
     if (mesh_sem == NULL) {
         ESP_LOGE(TAG, "Failed to create mesh semaphore");
         return ESP_FAIL;
     }
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        ESP_LOGE(TAG, "Failed to init nimble %d ", ret);
+        return ret;
+    }
+
     /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = mesh_on_reset;
     ble_hs_cfg.sync_cb = mesh_on_sync;

+ 3 - 1
examples/bluetooth/nimble/ble_l2cap_coc/coc_blecent/main/main.c

@@ -506,7 +506,9 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    assert(ret == 0);
+
     /* Configure the host. */
     ble_hs_cfg.reset_cb = blecent_on_reset;
     ble_hs_cfg.sync_cb = blecent_on_sync;

+ 6 - 1
examples/bluetooth/nimble/ble_l2cap_coc/coc_bleprph/main/main.c

@@ -435,7 +435,12 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        ESP_LOGE(tag, "Failed to init nimble %d ", ret);
+        return;
+    }
+
     /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = bleprph_on_reset;
     ble_hs_cfg.sync_cb = bleprph_on_sync;

+ 7 - 1
examples/bluetooth/nimble/ble_periodic_adv/main/main.c

@@ -188,7 +188,13 @@ app_main(void)
         ret = nvs_flash_init();
     }
     ESP_ERROR_CHECK(ret);
-    nimble_port_init();
+
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        ESP_LOGE(tag, "Failed to init nimble %d ", ret);
+        return;
+    }
+
     /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = periodic_adv_on_reset;
     ble_hs_cfg.sync_cb = periodic_adv_on_sync;

+ 6 - 1
examples/bluetooth/nimble/ble_periodic_sync/main/main.c

@@ -184,7 +184,12 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret);
+        return;
+    }
+
     /* Configure the host. */
     ble_hs_cfg.reset_cb = periodic_sync_on_reset;
     ble_hs_cfg.sync_cb = periodic_sync_on_sync;

+ 6 - 1
examples/bluetooth/nimble/ble_phy/phy_cent/main/main.c

@@ -477,7 +477,12 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret);
+        return;
+    }
+
     /* Configure the host. */
     ble_hs_cfg.reset_cb = blecent_on_reset;
     ble_hs_cfg.sync_cb = blecent_on_sync;

+ 6 - 1
examples/bluetooth/nimble/ble_phy/phy_prph/main/main.c

@@ -396,7 +396,12 @@ app_main(void)
 
     //ESP_ERROR_CHECK(esp_nimble_hci_and_controller_init());
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret);
+        return;
+    }
+
     /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = bleprph_on_reset;
     ble_hs_cfg.sync_cb = bleprph_on_sync;

+ 5 - 1
examples/bluetooth/nimble/ble_spp/spp_client/main/main.c

@@ -414,7 +414,11 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret);
+        return;
+    }
 
     /* Initialize UART driver and start uart task */
     ble_spp_uart_init();

+ 5 - 1
examples/bluetooth/nimble/ble_spp/spp_server/main/main.c

@@ -406,7 +406,11 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret);
+        return;
+    }
 
     /* Initialize connection_handle array */
     for (int i = 0; i <= CONFIG_BT_NIMBLE_MAX_CONNECTIONS; i++) {

+ 12 - 2
examples/bluetooth/nimble/blecent/main/main.c

@@ -615,7 +615,12 @@ static void stack_init_deinit(void)
 
         ESP_LOGI(tag, "Init host");
 
-        nimble_port_init();
+        rc = nimble_port_init();
+        if (rc != ESP_OK) {
+            ESP_LOGI(tag, "Failed to init nimble %d ", rc);
+            break;
+        }
+
         nimble_port_freertos_init(blecent_host_task);
 
         ESP_LOGI(tag, "Waiting for 1 second");
@@ -635,7 +640,12 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        ESP_LOGE(tag, "Failed to init nimble %d ", ret);
+        return;
+    }
+
     /* Configure the host. */
     ble_hs_cfg.reset_cb = blecent_on_reset;
     ble_hs_cfg.sync_cb = blecent_on_sync;

+ 6 - 1
examples/bluetooth/nimble/blehr/main/main.c

@@ -280,7 +280,12 @@ void app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        MODLOG_DFLT(ERROR, "Failed to init nimble %d \n", ret);
+        return;
+    }
+
     /* Initialize the NimBLE host configuration */
     ble_hs_cfg.sync_cb = blehr_on_sync;
     ble_hs_cfg.reset_cb = blehr_on_reset;

+ 5 - 1
examples/bluetooth/nimble/blemesh/main/app_mesh.c

@@ -451,7 +451,11 @@ void app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        ESP_LOGE(tag, "Failed to init nimble %d ", ret);
+        return;
+    }
 
     ble_svc_gap_init();
     ble_svc_gatt_init();

+ 5 - 1
examples/bluetooth/nimble/bleprph/main/main.c

@@ -496,7 +496,11 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        ESP_LOGE(tag, "Failed to init nimble %d ", ret);
+        return;
+    }
     /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = bleprph_on_reset;
     ble_hs_cfg.sync_cb = bleprph_on_sync;

+ 5 - 1
examples/bluetooth/nimble/bleprph_wifi_coex/main/main.c

@@ -539,7 +539,11 @@ app_main(void)
     wifi_init_sta();
     do_ping_cmd();
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        ESP_LOGE(TAG, "Failed to init nimble %d ", ret);
+        return;
+    }
     /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = bleprph_on_reset;
     ble_hs_cfg.sync_cb = bleprph_on_sync;

+ 5 - 1
examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c

@@ -723,7 +723,11 @@ app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        ESP_LOGE(tag, "Failed to init nimble %d ", ret);
+        return;
+    }
 
     /* Configure the host. */
     ble_hs_cfg.reset_cb = blecent_on_reset;

+ 6 - 1
examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c

@@ -371,7 +371,12 @@ void app_main(void)
     }
     ESP_ERROR_CHECK(ret);
 
-    nimble_port_init();
+    ret = nimble_port_init();
+    if (ret != ESP_OK) {
+        ESP_LOGE(tag, "Failed to init nimble %d ", ret);
+        return;
+    }
+
     /* Initialize the NimBLE host configuration */
     ble_hs_cfg.sync_cb = gatts_on_sync;
     ble_hs_cfg.reset_cb = gatts_on_reset;

+ 1 - 1
examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c

@@ -273,7 +273,7 @@ void app_main(void)
 #endif // CONFIG_EXAMPLE_CONNECT_WIFI
 
 #if CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED
-    esp_ble_helper_init();
+    ESP_ERROR_CHECK(esp_ble_helper_init());
 #endif
 
     xTaskCreate(&advanced_ota_example_task, "advanced_ota_example_task", 1024 * 8, NULL, 5, NULL);

+ 18 - 12
examples/system/ota/advanced_https_ota/main/ble_helper/ble_api.c

@@ -16,13 +16,11 @@
 #include "bluedroid_gatts.h"
 #endif
 
-#if CONFIG_BT_BLE_ENABLED
 static const char *TAG = "BLE_API";
-#endif
 
-void esp_ble_helper_init(void)
+esp_err_t esp_ble_helper_init(void)
 {
-    esp_err_t err;
+    esp_err_t err = ESP_OK;
 #if CONFIG_BT_BLE_ENABLED
     ESP_ERROR_CHECK(esp_bt_controller_mem_release(ESP_BT_MODE_CLASSIC_BT));
 
@@ -30,48 +28,54 @@ void esp_ble_helper_init(void)
     err = esp_bt_controller_init(&bt_cfg);
     if (err) {
         ESP_LOGE(TAG, "%s initialize controller failed: %s\n", __func__, esp_err_to_name(err));
-        return;
+        return err;
     }
 
     err = esp_bt_controller_enable(ESP_BT_MODE_BLE);
     if (err) {
         ESP_LOGE(TAG, "%s enable controller failed: %s\n", __func__, esp_err_to_name(err));
-        return;
+        return err;
     }
     err = esp_bluedroid_init();
     if (err) {
         ESP_LOGE(TAG, "%s init bluetooth failed: %s\n", __func__, esp_err_to_name(err));
-        return;
+        return err;
     }
     err = esp_bluedroid_enable();
     if (err) {
         ESP_LOGE(TAG, "%s enable bluetooth failed: %s\n", __func__, esp_err_to_name(err));
-        return;
+        return err;
     }
 
     err = esp_ble_gatts_register_callback(gatts_event_handler);
     if (err) {
         ESP_LOGE(TAG, "gatts register error, error code = %x", err);
-        return;
+        return err;
     }
     err = esp_ble_gap_register_callback(gap_event_handler);
     if (err) {
         ESP_LOGE(TAG, "gap register error, error code = %x", err);
-        return;
+        return err;
     }
     err = esp_ble_gatts_app_register(PROFILE_A_APP_ID);
     if (err) {
         ESP_LOGE(TAG, "gatts app register error, error code = %x", err);
-        return;
+        return err;
     }
     esp_err_t local_mtu_err = esp_ble_gatt_set_local_mtu(500);
     if (local_mtu_err) {
         ESP_LOGE(TAG, "set local  MTU failed, error code = %x", local_mtu_err);
+        return local_mtu_err;
     }
 
 #elif CONFIG_BT_NIMBLE_ENABLED
 
-    nimble_port_init();
+    err = nimble_port_init();
+    if (err != ESP_OK) {
+        ESP_LOGE(TAG, "Failed to init nimble %d ", err);
+        return err;
+    }
+
     /* Initialize the NimBLE host configuration. */
     ble_hs_cfg.reset_cb = bleprph_on_reset;
     ble_hs_cfg.sync_cb = bleprph_on_sync;
@@ -90,6 +94,8 @@ void esp_ble_helper_init(void)
     nimble_port_freertos_init(bleprph_host_task);
 
 #endif
+
+    return ESP_OK;
 }
 
 #endif

+ 8 - 14
examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h

@@ -1,25 +1,19 @@
-// Copyright 2021 Espressif Systems (Shanghai) PTE LTD
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
+/*
+ * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ */
 
 #pragma once
 
+#include "esp_err.h"
+
 #ifdef __cplusplus
 extern "C" {
 #endif
 
 #if CONFIG_BT_BLE_ENABLED || CONFIG_BT_NIMBLE_ENABLED
-void esp_ble_helper_init(void);
+esp_err_t esp_ble_helper_init(void);
 #endif
 
 

+ 0 - 1
tools/ci/check_copyright_ignore.txt

@@ -1625,7 +1625,6 @@ examples/system/ipc/ipc_isr/main/main.c
 examples/system/light_sleep/example_test.py
 examples/system/ota/advanced_https_ota/example_test.py
 examples/system/ota/advanced_https_ota/main/advanced_https_ota_example.c
-examples/system/ota/advanced_https_ota/main/ble_helper/include/ble_api.h
 examples/system/ota/native_ota_example/example_test.py
 examples/system/ota/native_ota_example/main/native_ota_example.c
 examples/system/ota/otatool/example_test.py