From 9830b8bb22516f15230d140b438484f70b485c3c Mon Sep 17 00:00:00 2001 From: Jin Cheng Date: Wed, 28 Feb 2024 15:10:59 +0800 Subject: [PATCH] feat(bt/bluedroid): Moved the memory allocation of HF AG control blocks to BTC module --- components/bt/common/btc/core/btc_task.c | 32 +++++++++++-------- .../btc/profile/std/hf_ag/btc_hf_ag.c | 16 ++-------- .../btc/profile/std/include/btc_hf_ag.h | 7 +++- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/components/bt/common/btc/core/btc_task.c b/components/bt/common/btc/core/btc_task.c index a93a51d0be..8abd25d4fb 100644 --- a/components/bt/common/btc/core/btc_task.c +++ b/components/bt/common/btc/core/btc_task.c @@ -1,16 +1,8 @@ -// Copyright 2015-2016 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: 2015-2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ #include #include @@ -331,6 +323,13 @@ static void btc_deinit_mem(void) { #endif #endif +#if BTC_HF_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE + if (hf_local_param_ptr) { + osi_free(hf_local_param_ptr); + hf_local_param_ptr = NULL; + } +#endif + #if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE if (hf_client_local_param_ptr) { osi_free(hf_client_local_param_ptr); @@ -386,6 +385,13 @@ static bt_status_t btc_init_mem(void) { #endif #endif +#if BTC_HF_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE + if ((hf_local_param_ptr = (hf_local_param_t *)osi_malloc(BTC_HF_NUM_CB * sizeof(hf_local_param_t))) == NULL) { + goto error_exit; + } + memset((void *)hf_local_param_ptr, 0, BTC_HF_NUM_CB * sizeof(hf_local_param_t)); +#endif + #if BTC_HF_CLIENT_INCLUDED == TRUE && HFP_DYNAMIC_MEMORY == TRUE if ((hf_client_local_param_ptr = (hf_client_local_param_t *)osi_malloc(sizeof(hf_client_local_param_t))) == NULL) { goto error_exit; diff --git a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c index 1dbaf01aa8..abcaa8e0c5 100644 --- a/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c +++ b/components/bt/host/bluedroid/btc/profile/std/hf_ag/btc_hf_ag.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -44,7 +44,7 @@ static UINT16 btc_max_hf_clients = BTC_HF_NUM_CB; #if HFP_DYNAMIC_MEMORY == FALSE static hf_local_param_t hf_local_param[BTC_HF_NUM_CB]; #else -static hf_local_param_t *hf_local_param = NULL; +hf_local_param_t *hf_local_param_ptr = NULL; #endif #if (BTM_WBS_INCLUDED == TRUE) @@ -292,18 +292,6 @@ bt_status_t btc_hf_init(bt_bdaddr_t *bd_addr) BTC_TRACE_DEBUG("%s - max_hf_clients=%d", __func__, btc_max_hf_clients); -#if HFP_DYNAMIC_MEMORY == TRUE - if (hf_local_param != NULL) { - return BT_STATUS_FAIL; - } - - if ((hf_local_param = (hf_local_param_t *)osi_malloc(BTC_HF_NUM_CB * sizeof(hf_local_param_t))) == NULL) { - APPL_TRACE_ERROR("%s malloc failed!", __func__); - return BT_STATUS_NOMEM; - } - memset((void *)hf_local_param, 0, BTC_HF_NUM_CB * sizeof(hf_local_param_t)); -#endif - /* Invoke the enable service API to the core to set the appropriate service_id * Internally, the HSP_SERVICE_ID shall also be enabled if HFP is enabled (phone) * othwerwise only HSP is enabled (tablet)*/ diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h index 085e442e05..2d2e25f39e 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_hf_ag.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -232,6 +232,11 @@ typedef struct esp_hf_outgoing_data_cb_t btc_hf_outgoing_data_cb; } hf_local_param_t; +#if HFP_DYNAMIC_MEMORY == TRUE +extern hf_local_param_t *hf_local_param_ptr; +#define hf_local_param (hf_local_param_ptr) +#endif + /******************************************************************************* ** BTC HF AG Handle Hub ********************************************************************************/