mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/ble_mesh_deinit_reinit_v5.1' into 'release/v5.1'
feat: ble mesh: improve ble mesh deinit when nimble enable(backport v5.1) See merge request espressif/esp-idf!28925
This commit is contained in:
commit
eca249f41a
@ -65,7 +65,9 @@ esp_err_t esp_ble_mesh_init(esp_ble_mesh_prov_t *prov, esp_ble_mesh_comp_t *comp
|
|||||||
esp_err_t esp_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param)
|
esp_err_t esp_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param)
|
||||||
{
|
{
|
||||||
btc_ble_mesh_prov_args_t arg = {0};
|
btc_ble_mesh_prov_args_t arg = {0};
|
||||||
|
SemaphoreHandle_t semaphore = NULL;
|
||||||
btc_msg_t msg = {0};
|
btc_msg_t msg = {0};
|
||||||
|
esp_err_t ret = ESP_OK;
|
||||||
|
|
||||||
if (param == NULL) {
|
if (param == NULL) {
|
||||||
return ESP_ERR_INVALID_ARG;
|
return ESP_ERR_INVALID_ARG;
|
||||||
@ -73,13 +75,36 @@ esp_err_t esp_ble_mesh_deinit(esp_ble_mesh_deinit_param_t *param)
|
|||||||
|
|
||||||
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
ESP_BLE_HOST_STATUS_CHECK(ESP_BLE_HOST_STATUS_ENABLED);
|
||||||
|
|
||||||
|
// Create a semaphore
|
||||||
|
if ((semaphore = xSemaphoreCreateCounting(1, 0)) == NULL) {
|
||||||
|
BT_ERR("Failed to create semaphore");
|
||||||
|
return ESP_ERR_NO_MEM;
|
||||||
|
}
|
||||||
|
|
||||||
arg.mesh_deinit.param.erase_flash = param->erase_flash;
|
arg.mesh_deinit.param.erase_flash = param->erase_flash;
|
||||||
|
/* Transport semaphore pointer to BTC layer, and will give the semaphore in the BTC task */
|
||||||
|
arg.mesh_deinit.semaphore = semaphore;
|
||||||
|
|
||||||
msg.sig = BTC_SIG_API_CALL;
|
msg.sig = BTC_SIG_API_CALL;
|
||||||
msg.pid = BTC_PID_PROV;
|
msg.pid = BTC_PID_PROV;
|
||||||
msg.act = BTC_BLE_MESH_ACT_DEINIT_MESH;
|
msg.act = BTC_BLE_MESH_ACT_DEINIT_MESH;
|
||||||
|
|
||||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL)
|
if (btc_transfer_context(&msg, &arg, sizeof(btc_ble_mesh_prov_args_t), NULL, NULL) != BT_STATUS_SUCCESS) {
|
||||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
vSemaphoreDelete(semaphore);
|
||||||
|
BT_ERR("Failed to start mesh deinit");
|
||||||
|
return ESP_FAIL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Take the Semaphore, wait BLE Mesh de-initialization to finish. */
|
||||||
|
xSemaphoreTake(semaphore, portMAX_DELAY);
|
||||||
|
/* Don't forget to delete the semaphore at the end. */
|
||||||
|
vSemaphoreDelete(semaphore);
|
||||||
|
|
||||||
|
ret = bt_mesh_host_deinit();
|
||||||
|
if (ret != ESP_OK) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ESP_OK;
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BLE_MESH_DEINIT */
|
#endif /* CONFIG_BLE_MESH_DEINIT */
|
||||||
|
@ -2268,6 +2268,8 @@ void btc_ble_mesh_prov_call_handler(btc_msg_t *msg)
|
|||||||
case BTC_BLE_MESH_ACT_DEINIT_MESH:
|
case BTC_BLE_MESH_ACT_DEINIT_MESH:
|
||||||
act = ESP_BLE_MESH_DEINIT_MESH_COMP_EVT;
|
act = ESP_BLE_MESH_DEINIT_MESH_COMP_EVT;
|
||||||
param.deinit_mesh_comp.err_code = bt_mesh_deinit((struct bt_mesh_deinit_param *)&arg->mesh_deinit.param);
|
param.deinit_mesh_comp.err_code = bt_mesh_deinit((struct bt_mesh_deinit_param *)&arg->mesh_deinit.param);
|
||||||
|
/* Give the semaphore when BLE Mesh de-initialization is finished. */
|
||||||
|
xSemaphoreGive(arg->mesh_deinit.semaphore);
|
||||||
break;
|
break;
|
||||||
#endif /* CONFIG_BLE_MESH_DEINIT */
|
#endif /* CONFIG_BLE_MESH_DEINIT */
|
||||||
default:
|
default:
|
||||||
|
@ -309,6 +309,7 @@ typedef union {
|
|||||||
} model_unsub_group_addr;
|
} model_unsub_group_addr;
|
||||||
struct ble_mesh_deinit_args {
|
struct ble_mesh_deinit_args {
|
||||||
esp_ble_mesh_deinit_param_t param;
|
esp_ble_mesh_deinit_param_t param;
|
||||||
|
SemaphoreHandle_t semaphore;
|
||||||
} mesh_deinit;
|
} mesh_deinit;
|
||||||
} btc_ble_mesh_prov_args_t;
|
} btc_ble_mesh_prov_args_t;
|
||||||
|
|
||||||
|
@ -99,6 +99,11 @@ int bt_mesh_host_init(void)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int bt_mesh_host_deinit(void)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void bt_mesh_hci_init(void)
|
void bt_mesh_hci_init(void)
|
||||||
{
|
{
|
||||||
const uint8_t *features = controller_get_interface()->get_features_ble()->as_array;
|
const uint8_t *features = controller_get_interface()->get_features_ble()->as_array;
|
||||||
|
@ -659,6 +659,7 @@ struct bt_mesh_gatt_attr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int bt_mesh_host_init(void);
|
int bt_mesh_host_init(void);
|
||||||
|
int bt_mesh_host_deinit(void);
|
||||||
|
|
||||||
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
int bt_le_adv_start(const struct bt_mesh_adv_param *param,
|
||||||
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
const struct bt_mesh_adv_data *ad, size_t ad_len,
|
||||||
|
@ -82,14 +82,15 @@ static uint8_t bt_mesh_gatts_addr[6];
|
|||||||
|
|
||||||
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
|
#endif /* defined(CONFIG_BLE_MESH_NODE) && CONFIG_BLE_MESH_NODE */
|
||||||
|
|
||||||
|
static bool g_host_init = false;
|
||||||
|
|
||||||
int bt_mesh_host_init(void)
|
int bt_mesh_host_init(void)
|
||||||
{
|
{
|
||||||
static bool init = false;
|
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (init == true) {
|
if (g_host_init == true) {
|
||||||
BT_WARN("Already initialized host for mesh!");
|
BT_WARN("Already initialized host for mesh!");
|
||||||
return 0;
|
return -EALREADY;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = btc_init();
|
rc = btc_init();
|
||||||
@ -103,7 +104,30 @@ int bt_mesh_host_init(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
osi_alarm_init();
|
osi_alarm_init();
|
||||||
init = true;
|
g_host_init = true;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int bt_mesh_host_deinit(void)
|
||||||
|
{
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
if (g_host_init == false) {
|
||||||
|
return -EALREADY;
|
||||||
|
}
|
||||||
|
|
||||||
|
osi_alarm_deinit();
|
||||||
|
|
||||||
|
rc = osi_alarm_delete_mux();
|
||||||
|
if (rc != 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
btc_deinit();
|
||||||
|
|
||||||
|
g_host_init = false;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user