component/bt: Added the Macro for the classic BT support.
component/bt: added the bluedroid deinit method.
component/bt: allow more classic BT global variables to use dynamic allocation scheme
1. allocate memory for AVDT, AVCT control blocks when dynamic memory is used
2. allow SBC decoder buffer to use dynamic allocation scheme
component/bt: Remove the wrong changes in bt/Kconfig & Added the GATTS_INCLUDED in the gatt_free function when gatt service close.
component/bt: Shorten the abbreviation BT_ALLOCATION_FROM_SPIRAM_FIRST and BT_BLE_DYNAMIC_ENV_MEMORY two macros.
help
Maximum BT/BLE connection count
+config BT_ALLOCATION_FROM_SPIRAM_FIRST
+ bool "BT/BLE will first malloc the memory from the PSRAM"
+ depends on BLUEDROID_ENABLED
+ default n
+ help
+ This select can save the internal RAM if there have the PSRAM
+
+config BT_BLE_DYNAMIC_ENV_MEMORY
+ bool "Use dynamic memory allocation in BT/BLE stack"
+ depends on BLUEDROID_ENABLED
+ default n
+ help
+ This select can make the allocation of memory will become more flexible
+
config SMP_ENABLE
bool
depends on BLUEDROID_ENABLED
/* AV control block */
#if BTA_DYNAMIC_MEMORY == FALSE
tBTA_AR_CB bta_ar_cb;
+#else
+tBTA_AR_CB *bta_ar_cb_ptr;
#endif
/*******************************************************************************
/* AV control block */
#if BTA_DYNAMIC_MEMORY == FALSE
tBTA_AV_CB bta_av_cb;
+#else
+tBTA_AV_CB *bta_av_cb_ptr;
#endif
#if (defined(BTA_AV_DEBUG) && BTA_AV_DEBUG == TRUE)
#include "bta_api.h"
#include "bta_sys.h"
#include "bta_dm_int.h"
+#include "allocator.h"
+#include <string.h>
/*****************************************************************************
tBTA_DM_CB bta_dm_cb;
tBTA_DM_SEARCH_CB bta_dm_search_cb;
tBTA_DM_DI_CB bta_dm_di_cb;
+#else
+tBTA_DM_CB *bta_dm_cb_ptr;
+tBTA_DM_SEARCH_CB *bta_dm_search_cb_ptr;
+tBTA_DM_DI_CB *bta_dm_di_cb_ptr;
#endif
bta_sys_deregister( BTA_ID_DM );
}
+void bta_dm_sm_deinit(void)
+{
+ memset(&bta_dm_cb, 0, sizeof(tBTA_DM_CB));
+ memset(&bta_dm_search_cb, 0, sizeof(tBTA_DM_SEARCH_CB));
+ memset(&bta_dm_di_cb, 0, sizeof(tBTA_DM_DI_CB));
+#if BTA_DYNAMIC_MEMORY
+ FREE_AND_RESET(bta_dm_cb_ptr);
+ FREE_AND_RESET(bta_dm_search_cb_ptr);
+ FREE_AND_RESET(bta_dm_di_cb_ptr);
+#endif /* #if BTA_DYNAMIC_MEMORY */
+}
+
/*******************************************************************************
**
#include <string.h>
#include "bta_gattc_int.h"
+#include "allocator.h"
/*****************************************************************************
/* GATTC control block */
#if BTA_DYNAMIC_MEMORY == FALSE
tBTA_GATTC_CB bta_gattc_cb;
+#else
+tBTA_GATTC_CB *bta_gattc_cb_ptr;
#endif
#if BTA_GATT_DEBUG == TRUE
}
#endif /* Debug Functions */
+
+void bta_gattc_deinit(void)
+{
+#if BTA_DYNAMIC_MEMORY
+ memset(bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB));
+ FREE_AND_RESET(bta_gattc_cb_ptr);
+#endif /* #if BTA_DYNAMIC_MEMORY */
+}
#endif /* GATTC_INCLUDED == TRUE && BLE_INCLUDED == TRUE */
#include <string.h>
#include "bta_gatts_int.h"
+#include "allocator.h"
/* type for service building action functions */
typedef void (*tBTA_GATTS_SRVC_ACT)(tBTA_GATTS_SRVC_CB *p_rcb, tBTA_GATTS_DATA *p_data);
/* GATTS control block */
#if BTA_DYNAMIC_MEMORY == FALSE
tBTA_GATTS_CB bta_gatts_cb;
+#else
+tBTA_GATTS_CB *bta_gatts_cb_ptr;
#endif
/*******************************************************************************
return (TRUE);
}
+void bta_gatts_deinit(void)
+{
+ memset(&bta_gatts_cb, 0, sizeof(tBTA_GATTS_CB));
+#if BTA_DYNAMIC_MEMORY
+ FREE_AND_RESET(bta_gatts_cb_ptr);
+#endif /* #if BTA_DYNAMIC_MEMORY */
+}
+
#endif /* GATTS_INCLUDED */
*****************************************************************************/
#if BTA_DYNAMIC_MEMORY == FALSE
tBTA_HH_CB bta_hh_cb;
+#else
+tBTA_HH_CB *bta_hh_cb_ptr;
#endif
/*****************************************************************************
** Static functions
extern BOOLEAN bta_dm_sm_execute(BT_HDR *p_msg);
extern void bta_dm_sm_disable( void );
+extern void bta_dm_sm_deinit(void);
extern BOOLEAN bta_dm_search_sm_execute(BT_HDR *p_msg);
extern void bta_dm_search_sm_disable( void );
extern bool bta_gattc_cache_load(tBTA_GATTC_CLCB *p_clcb);
extern void bta_gattc_cache_reset(BD_ADDR server_bda);
+extern void bta_gattc_deinit(void);
#endif /* BTA_GATTC_INT_H */
extern UINT8 bta_gatts_alloc_srvc_cb(tBTA_GATTS_CB *p_cb, UINT8 rcb_idx);
extern tBTA_GATTS_SRVC_CB *bta_gatts_find_srvc_cb_by_srvc_id(tBTA_GATTS_CB *p_cb, UINT16 service_id);
extern tBTA_GATTS_SRVC_CB *bta_gatts_find_srvc_cb_by_attr_id(tBTA_GATTS_CB *p_cb, UINT16 attr_id);
-
+extern void bta_gatts_deinit(void);
#endif /* BTA_GATTS_INT_H */
#if BTA_DYNAMIC_MEMORY == FALSE
tBTA_SDP_CB bta_sdp_cb;
+#else
+tBTA_SDP_CB *bta_sdp_cb_ptr;
#endif
/* state machine action enumeration list */
/* system manager control block definition */
#if BTA_DYNAMIC_MEMORY == FALSE
tBTA_SYS_CB bta_sys_cb;
+#else
+tBTA_SYS_CB *bta_sys_cb_ptr;
#endif
static hash_map_t *bta_alarm_hash_map;
{
hash_map_free(bta_alarm_hash_map);
osi_mutex_free(&bta_alarm_lock);
+#if BTA_DYNAMIC_MEMORY
+ FREE_AND_RESET(bta_sys_cb_ptr);
+#endif
}
/*******************************************************************************
#include "alarm.h"
#include "btc_ble_storage.h"
#include "bta_gatt_common.h"
+#include "btc_gap_ble.h"
+#include "bta_gattc_int.h"
+#include "bta_gatts_int.h"
+#include "bta_dm_int.h"
static future_t *main_future[BTC_MAIN_FUTURE_NUM];
static void btc_deinit_bluetooth(void)
{
+ btc_gap_ble_deinit();
+ bta_dm_sm_deinit();
+#if (GATTC_INCLUDED)
+ bta_gattc_deinit();
+#endif /* #if (GATTC_INCLUDED) */
+#if (GATTS_INCLUDED)
+ bta_gatts_deinit();
+#endif /* #if (GATTS_INCLUDED) */
bte_main_shutdown();
btc_config_clean_up();
osi_alarm_deinit();
BTM_BleRegiseterConnParamCallback(btc_update_conn_param_callback);
}
+
+void btc_gap_ble_deinit(void)
+{
+ btc_cleanup_adv_data(&gl_bta_adv_data);
+ btc_cleanup_adv_data(&gl_bta_scan_rsp_data);
+}
void btc_gap_ble_cb_deep_free(btc_msg_t *msg);
void btc_gap_ble_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src);
void btc_gap_callback_init(void);
+void btc_gap_ble_deinit(void);
#endif /* __BTC_GAP_BLE_H__ */
#include "bt_target.h"
#include <string.h>
+
/* Stack Configuation Related Init Definaton
* TODO: Now Just Unmask these defination until stack layer is OK
*/
#include "a2d_api.h"
#endif
+#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE)
+#include "avdt_int.h"
+#endif
+
+#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE)
+#include "avct_int.h"
+#endif
+
#if (defined(HID_HOST_INCLUDED) && HID_HOST_INCLUDED == TRUE)
#include "hidh_api.h"
#endif
#if BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE
#include "bta_api.h"
#include "bta_sys.h"
+#include "allocator.h"
+
+//#include "bta_ag_int.h"
-#include "bta_ag_int.h"
+#if BTA_SDP_INCLUDED == TRUE
+#include "bta_sdp_int.h"
+#endif
#if BTA_HS_INCLUDED == TRUE
#include "bta_hs_int.h"
#include "bta_sys_int.h"
// control block for patch ram downloading
-#include "bta_prm_int.h"
+//#include "bta_prm_int.h"
-#endif // BTA_INCLUDED
+#endif // BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE
/*****************************************************************************
AVRC_Init();
#endif
+#if (defined(AVDT_INCLUDED) && AVDT_INCLUDED == TRUE && AVDT_DYNAMIC_MEMORY == TRUE)
+ if ((avdt_cb_ptr = (tAVDT_CB *)osi_malloc(sizeof(tAVDT_CB))) == NULL) {
+ return;
+ }
+ memset((void *)avdt_cb_ptr, 0, sizeof(tAVDT_CB));
+#endif
+
+#if (defined(AVCT_INCLUDED) && AVCT_INCLUDED == TRUE && AVCT_DYNAMIC_MEMORY == TRUE)
+ if ((avct_cb_ptr = (tAVCT_CB *)osi_malloc(sizeof(tAVCT_CB))) == NULL) {
+ return;
+ }
+ memset((void *)avct_cb_ptr, 0, sizeof(tAVCT_CB));
+#endif
+
#if (defined(GAP_INCLUDED) && GAP_INCLUDED == TRUE)
GAP_Init();
#endif
//BTA Modules
#if (BTA_INCLUDED == TRUE && BTA_DYNAMIC_MEMORY == TRUE)
+ if ((bta_sys_cb_ptr = (tBTA_SYS_CB *)osi_malloc(sizeof(tBTA_SYS_CB))) == NULL) {
+ return;
+ }
+ if ((bta_dm_cb_ptr = (tBTA_DM_CB *)osi_malloc(sizeof(tBTA_DM_CB))) == NULL) {
+ return;
+ }
+ if ((bta_dm_search_cb_ptr = (tBTA_DM_SEARCH_CB *)osi_malloc(sizeof(tBTA_DM_SEARCH_CB))) == NULL) {
+ return;
+ }
+ if ((bta_dm_di_cb_ptr = (tBTA_DM_DI_CB *)osi_malloc(sizeof(tBTA_DM_DI_CB))) == NULL) {
+ return;
+ }
memset((void *)bta_sys_cb_ptr, 0, sizeof(tBTA_SYS_CB));
memset((void *)bta_dm_cb_ptr, 0, sizeof(tBTA_DM_CB));
memset((void *)bta_dm_search_cb_ptr, 0, sizeof(tBTA_DM_SEARCH_CB));
memset((void *)bta_dm_di_cb_ptr, 0, sizeof(tBTA_DM_DI_CB));
- memset((void *)bta_prm_cb_ptr, 0, sizeof(tBTA_PRM_CB));
- memset((void *)bta_ag_cb_ptr, 0, sizeof(tBTA_AG_CB));
+ //memset((void *)bta_prm_cb_ptr, 0, sizeof(tBTA_PRM_CB));
+ //memset((void *)bta_ag_cb_ptr, 0, sizeof(tBTA_AG_CB));
#if BTA_HS_INCLUDED == TRUE
memset((void *)bta_hs_cb_ptr, 0, sizeof(tBTA_HS_CB));
#endif
+#if BTA_SDP_INCLUDED == TRUE
+ if ((bta_sdp_cb_ptr = (tBTA_SDP_CB *)osi_malloc(sizeof(tBTA_SDP_CB))) == NULL) {
+ return;
+ }
+ memset((void *)bta_sdp_cb_ptr, 0, sizeof(tBTA_SDP_CB));
+#endif
#if BTA_AR_INCLUDED==TRUE
+ if ((bta_ar_cb_ptr = (tBTA_AR_CB *)osi_malloc(sizeof(tBTA_AR_CB))) == NULL) {
+ return;
+ }
memset((void *)bta_ar_cb_ptr, 0, sizeof(tBTA_AR_CB));
#endif
#if BTA_AV_INCLUDED==TRUE
+ if ((bta_av_cb_ptr = (tBTA_AV_CB *)osi_malloc(sizeof(tBTA_AV_CB))) == NULL) {
+ return;
+ }
memset((void *)bta_av_cb_ptr, 0, sizeof(tBTA_AV_CB));
#endif
#if BTA_HH_INCLUDED==TRUE
+ if ((bta_hh_cb_ptr = (tBTA_HH_CB *)osi_malloc(sizeof(tBTA_HH_CB))) == NULL) {
+ return;
+ }
memset((void *)bta_hh_cb_ptr, 0, sizeof(tBTA_HH_CB));
#endif
#if BTA_HL_INCLUDED==TRUE
memset((void *)bta_hl_cb_ptr, 0, sizeof(tBTA_HL_CB));
#endif
-#if BTA_GATT_INCLUDED==TRUE
+#if GATTC_INCLUDED==TRUE
+ if ((bta_gattc_cb_ptr = (tBTA_GATTC_CB *)osi_malloc(sizeof(tBTA_GATTC_CB))) == NULL) {
+ return;
+ }
+ memset((void *)bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB));
+#endif
+#if GATTS_INCLUDED == TRUE
+ if ((bta_gatts_cb_ptr = (tBTA_GATTS_CB *)osi_malloc(sizeof(tBTA_GATTS_CB))) == NULL) {
+ return;
+ }
memset((void *)bta_gattc_cb_ptr, 0, sizeof(tBTA_GATTC_CB));
+ //
memset((void *)bta_gatts_cb_ptr, 0, sizeof(tBTA_GATTS_CB));
#endif
#if BTA_PAN_INCLUDED==TRUE
{
#ifdef CONFIG_BLUEDROID_MEM_DEBUG
void *p;
-
+#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
+ p = heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
+#else
p = malloc(size);
+#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
osi_mem_dbg_record(p, size, __func__, __LINE__);
return p;
+#else
+#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
+ return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
#else
return malloc(size);
-#endif
+#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
+#endif /* #ifdef CONFIG_BLUEDROID_MEM_DEBUG */
}
void *osi_calloc_func(size_t size)
{
#ifdef CONFIG_BLUEDROID_MEM_DEBUG
void *p;
-
+#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
+ p = heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
+#else
p = calloc(1, size);
+#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
osi_mem_dbg_record(p, size, __func__, __LINE__);
return p;
+#else
+#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
+ return heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL);
#else
return calloc(1, size);
-#endif
+#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
+#endif /* #ifdef CONFIG_BLUEDROID_MEM_DEBUG */
}
void osi_free_func(void *ptr)
#include <stddef.h>
#include <stdlib.h>
+#include "esp_heap_caps.h"
#include "sdkconfig.h"
typedef void *(*alloc_fn)(size_t size);
void osi_mem_dbg_clean(void *p, const char *func, int line);
void osi_mem_dbg_show(void);
+#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
#define osi_malloc(size) \
({ \
void *p; \
- \
- p = malloc((size)); \
+ p = heap_caps_malloc_prefer(size, 2, \
+ MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
+ MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
osi_mem_dbg_record(p, size, __func__, __LINE__); \
(void *)p; \
})
#define osi_calloc(size) \
({ \
void *p; \
- \
+ p = heap_caps_calloc_prefer(1, size, 2, \
+ MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
+ MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
+ osi_mem_dbg_record(p, size, __func__, __LINE__); \
+ (void *)p; \
+})
+
+#else
+
+#define osi_malloc(size) \
+({ \
+ void *p; \
+ p = malloc((size)); \
+ osi_mem_dbg_record(p, size, __func__, __LINE__); \
+ (void *)p; \
+})
+
+#define osi_calloc(size) \
+({ \
+ void *p; \
p = calloc(1, (size)); \
osi_mem_dbg_record(p, size, __func__, __LINE__); \
(void *)p; \
})
+#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
+
+
+#if 0
+#define osi_malloc(size) \
+do { \
+ void *p; \
+ \
+#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST \
+ p = heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
+#else \
+ p = malloc((size)); \
+#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ \
+ osi_mem_dbg_record(p, size, __func__, __LINE__); \
+ (void *)p; \
+}while(0)
+
+#define osi_calloc(size) \
+do { \
+ void *p; \
+ \
+#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST \
+ p = heap_caps_calloc_prefer(1, size, 2, \
+ MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, \
+ MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL); \
+#else \
+ p = calloc(1, (size)); \
+#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */ \
+ osi_mem_dbg_record(p, size, __func__, __LINE__); \
+ (void *)p; \
+} while(0)
+#endif
+
#define osi_free(ptr) \
do { \
void *tmp_point = (void *)(ptr); \
#else
+#if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST
+#define osi_malloc(size) heap_caps_malloc_prefer(size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
+#define osi_calloc(size) heap_caps_calloc_prefer(1, size, 2, MALLOC_CAP_DEFAULT|MALLOC_CAP_SPIRAM, MALLOC_CAP_DEFAULT|MALLOC_CAP_INTERNAL)
+#else
#define osi_malloc(size) malloc((size))
#define osi_calloc(size) calloc(1, (size))
+#endif /* #if CONFIG_BT_ALLOCATION_FROM_SPIRAM_FIRST */
#define osi_free(p) free((p))
#endif /* CONFIG_BLUEDROID_MEM_DEBUG */
+#define FREE_AND_RESET(a) \
+do { \
+ if (a) { \
+ osi_free(a); \
+ a = NULL; \
+ } \
+}while (0)
+
+
#endif /* _ALLOCATOR_H_ */
#include "a2d_api.h"
#include "a2d_int.h"
#include "avdt_api.h"
+#include "allocator.h"
#if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE)
*****************************************************************************/
#if A2D_DYNAMIC_MEMORY == FALSE
tA2D_CB a2d_cb;
+#else
+tA2D_CB *a2d_cb_ptr;
#endif
*******************************************************************************/
void A2D_Init(void)
{
+#if (A2D_DYNAMIC_MEMORY)
+ a2d_cb_ptr = (tA2D_CB *)osi_malloc(sizeof(tA2D_CB));
+#endif /* #if (A2D_DYNAMIC_MEMORY) */
memset(&a2d_cb, 0, sizeof(tA2D_CB));
a2d_cb.avdt_sdp_ver = AVDT_VERSION;
/* Control block for AVCT */
#if AVCT_DYNAMIC_MEMORY == FALSE
tAVCT_CB avct_cb;
+#else
+tAVCT_CB *avct_cb_ptr;
#endif
/*******************************************************************************
/* Control block for AVDT */
#if AVDT_DYNAMIC_MEMORY == FALSE
tAVDT_CB avdt_cb;
+#else
+tAVDT_CB *avdt_cb_ptr;
#endif
/*******************************************************************************
#include "bt_target.h"
#include "avrc_api.h"
#include "avrc_int.h"
+#include "allocator.h"
#if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE)
*****************************************************************************/
#if AVRC_DYNAMIC_MEMORY == FALSE
tAVRC_CB avrc_cb;
+#else
+tAVRC_CB *avrc_cb_ptr;
#endif
/* update AVRC_NUM_PROTO_ELEMS if this constant is changed */
*******************************************************************************/
void AVRC_Init(void)
{
+#if AVRC_DYNAMIC_MEMORY
+ avrc_cb_ptr = (tAVRC_CB *)osi_malloc(sizeof(tAVRC_CB));
+#endif /* #if AVRC_DYNAMIC_MEMORY */
memset(&avrc_cb, 0, sizeof(tAVRC_CB));
#if defined(AVRC_INITIAL_TRACE_LEVEL)
*/
#if BTM_DYNAMIC_MEMORY == FALSE
tBTM_CB btm_cb;
+#else
+tBTM_CB *btm_cb_ptr;
#endif
/*******************************************************************************
*******************************************************************************/
void btm_init (void)
{
+#if BTM_DYNAMIC_MEMORY
+ btm_cb_ptr = (tBTM_CB *)osi_malloc(sizeof(tBTM_CB));
+#endif /* #if BTM_DYNAMIC_MEMORY */
/* All fields are cleared; nonzero fields are reinitialized in appropriate function */
memset(&btm_cb, 0, sizeof(tBTM_CB));
-
btm_cb.page_queue = fixed_queue_new(SIZE_MAX);
btm_cb.sec_pending_q = fixed_queue_new(SIZE_MAX);
{
fixed_queue_free(btm_cb.page_queue, osi_free_func);
fixed_queue_free(btm_cb.sec_pending_q, osi_free_func);
+#if BTM_DYNAMIC_MEMORY
+ FREE_AND_RESET(btm_cb_ptr);
+#endif
}
l2c_free();
#if BLE_INCLUDED == TRUE
-#if (defined(GATTS_INCLUDED) && GATTS_INCLUDED == true)
+#if (defined(GATT_INCLUDED) && GATT_INCLUDED == true)
gatt_free();
#endif
btm_ble_free();
#endif
btm_free();
+#if SMP_INCLUDED == TRUE
+ SMP_Free();
+#endif
}
/*****************************************************************************
******************************************************************************/
void BTU_StartUp(void)
{
+#if BTU_DYNAMIC_MEMORY
+ btu_cb_ptr = (tBTU_CB *)osi_malloc(sizeof(tBTU_CB));
+#endif /* #if BTU_DYNAMIC_MEMORY */
memset (&btu_cb, 0, sizeof (tBTU_CB));
btu_cb.trace_level = HCI_INITIAL_TRACE_LEVEL;
void BTU_ShutDown(void)
{
+#if BTU_DYNAMIC_MEMORY
+ FREE_AND_RESET(btu_cb_ptr);
+#endif
btu_task_shut_down();
hash_map_free(btu_general_alarm_hash_map);
*/
#if BTU_DYNAMIC_MEMORY == FALSE
tBTU_CB btu_cb;
+#else
+tBTU_CB *btu_cb_ptr;
#endif
extern hash_map_t *btu_general_alarm_hash_map;
#if GATT_DYNAMIC_MEMORY == FALSE
tGATT_CB gatt_cb;
+#else
+tGATT_CB *gatt_cb_ptr;
#endif
tGATT_DEFAULT gatt_default;
void gatt_init (void)
{
tL2CAP_FIXED_CHNL_REG fixed_reg;
-
- GATT_TRACE_DEBUG("gatt_init()");
-
+#if GATT_DYNAMIC_MEMORY
+ gatt_cb_ptr = (tGATT_CB *)osi_malloc(sizeof(tGATT_CB));
+#endif /* #if GATT_DYNAMIC_MEMORY */
memset (&gatt_cb, 0, sizeof(tGATT_CB));
memset (&fixed_reg, 0, sizeof(tL2CAP_FIXED_CHNL_REG));
** Returns void
**
*******************************************************************************/
-#if (GATTS_INCLUDED == TRUE)
+#if (GATT_INCLUDED == TRUE)
void gatt_free(void)
{
int i;
fixed_queue_free(gatt_cb.tcb[i].pending_ind_q, NULL);
gatt_cb.tcb[i].pending_ind_q = NULL;
-
+#if (GATTS_INCLUDED == TRUE)
fixed_queue_free(gatt_cb.tcb[i].sr_cmd.multi_rsp_q, NULL);
gatt_cb.tcb[i].sr_cmd.multi_rsp_q = NULL;
+#endif /* #if (GATTS_INCLUDED == TRUE) */
}
+#if (GATTS_INCLUDED == TRUE)
for (i = 0; i < GATT_MAX_SR_PROFILES; i++) {
gatt_free_hdl_buffer(&gatt_cb.hdl_list[i]);
}
+#endif /* #if (GATTS_INCLUDED == TRUE) */
+#if GATT_DYNAMIC_MEMORY
+ FREE_AND_RESET(gatt_cb_ptr);
+#endif /* #if GATT_DYNAMIC_MEMORY */
}
#endif ///GATTS_INCLUDED == TRUE
#define DYN_MEM_H
#include "sdkconfig.h"
-#if CONFIG_CLASSIC_BT_ENABLED
+#if CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY
+#define BTU_DYNAMIC_MEMORY TRUE
+#define BTM_DYNAMIC_MEMORY TRUE
+#define L2C_DYNAMIC_MEMORY TRUE
+#define GATT_DYNAMIC_MEMORY TRUE
+#define SMP_DYNAMIC_MEMORY TRUE
+#define BTA_DYNAMIC_MEMORY TRUE
+#define SDP_DYNAMIC_MEMORY TRUE
+#define RFC_DYNAMIC_MEMORY TRUE
+#define TCS_DYNAMIC_MEMORY TRUE
+#define BNEP_DYNAMIC_MEMORY TRUE
+#define AVDT_DYNAMIC_MEMORY TRUE
+#define AVCT_DYNAMIC_MEMORY TRUE
+#define MCA_DYNAMIC_MEMORY TRUE
+#define A2D_DYNAMIC_MEMORY TRUE
+#define VDP_DYNAMIC_MEMORY TRUE
+#define AVRC_DYNAMIC_MEMORY TRUE
+#define BIP_DYNAMIC_MEMORY TRUE
+#define BPP_DYNAMIC_MEMORY TRUE
+#define CTP_DYNAMIC_MEMORY TRUE
+#define FTP_DYNAMIC_MEMORY TRUE
+#define HCRP_DYNAMIC_MEMORY TRUE
+#define HFP_DYNAMIC_MEMORY TRUE
+#define HID_DYNAMIC_MEMORY TRUE
+#define HSP2_DYNAMIC_MEMORY TRUE
+#define ICP_DYNAMIC_MEMORY TRUE
+#define OPP_DYNAMIC_MEMORY TRUE
+#define PAN_DYNAMIC_MEMORY TRUE
+#define SPP_DYNAMIC_MEMORY TRUE
+#define SLIP_DYNAMIC_MEMORY TRUE
+#define LLCP_DYNAMIC_MEMORY TRUE
+#define BTC_SBC_DEC_DYNAMIC_MEMORY TRUE
+
+#else /* #if CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY */
#define SDP_DYNAMIC_MEMORY FALSE
#define RFC_DYNAMIC_MEMORY FALSE
#define SPP_DYNAMIC_MEMORY FALSE
#define SLIP_DYNAMIC_MEMORY FALSE
#define LLCP_DYNAMIC_MEMORY FALSE
+#define BTC_SBC_DEC_DYNAMIC_MEMORY FALSE
-#else /* #if CONFIG_CLASSIC_BT_ENABLED */
-
-#define SDP_DYNAMIC_MEMORY TRUE
-#define RFC_DYNAMIC_MEMORY TRUE
-#define TCS_DYNAMIC_MEMORY TRUE
-#define BNEP_DYNAMIC_MEMORY TRUE
-#define AVDT_DYNAMIC_MEMORY TRUE
-#define AVCT_DYNAMIC_MEMORY TRUE
-#define MCA_DYNAMIC_MEMORY TRUE
-#define A2D_DYNAMIC_MEMORY TRUE
-#define VDP_DYNAMIC_MEMORY TRUE
-#define AVRC_DYNAMIC_MEMORY TRUE
-#define BIP_DYNAMIC_MEMORY TRUE
-#define BPP_DYNAMIC_MEMORY TRUE
-#define CTP_DYNAMIC_MEMORY TRUE
-#define FTP_DYNAMIC_MEMORY TRUE
-#define HCRP_DYNAMIC_MEMORY TRUE
-#define HFP_DYNAMIC_MEMORY TRUE
-#define HID_DYNAMIC_MEMORY TRUE
-#define HSP2_DYNAMIC_MEMORY TRUE
-#define ICP_DYNAMIC_MEMORY TRUE
-#define OPP_DYNAMIC_MEMORY TRUE
-#define PAN_DYNAMIC_MEMORY TRUE
-#define SPP_DYNAMIC_MEMORY TRUE
-#define SLIP_DYNAMIC_MEMORY TRUE
-#define LLCP_DYNAMIC_MEMORY TRUE
-
-#endif /* #if CONFIG_CLASSIC_BT_ENABLED */
+#endif /* #if CONFIG_BT_BLE_DYNAMIC_ENV_MEMORY */
/****************************************************************************
** Define memory usage for each CORE component (if not defined in bdroid_buildcfg.h)
** The default for each component is to use static memory allocations.
*******************************************************************************/
extern void SMP_Init(void);
+/*******************************************************************************
+**
+** Function SMP_Free
+**
+** Description This function de initializes the SMP unit.
+**
+** Returns void
+**
+*******************************************************************************/
+extern void SMP_Free(void);
+
+
/*******************************************************************************
**
** Function SMP_SetTraceLevel
/********************************************************************************/
#if L2C_DYNAMIC_MEMORY == FALSE
tL2C_CB l2cb;
+#else
+tL2C_CB *l2c_cb_ptr;
#endif
/*******************************************************************************
void l2c_init (void)
{
INT16 xx;
-
+#if L2C_DYNAMIC_MEMORY
+ l2c_cb_ptr = (tL2C_CB *)osi_malloc(sizeof(tL2C_CB));
+#endif /* #if L2C_DYNAMIC_MEMORY */
memset (&l2cb, 0, sizeof (tL2C_CB));
/* the psm is increased by 2 before being used */
l2cb.dyn_psm = 0xFFF;
{
list_free(l2cb.rcv_pending_q);
l2cb.rcv_pending_q = NULL;
+#if L2C_DYNAMIC_MEMORY
+ FREE_AND_RESET(l2c_cb_ptr);
+#endif
}
/*******************************************************************************
*******************************************************************************/
void RFCOMM_Init (void)
{
+#if (RFC_DYNAMIC_MEMORY)
+ rfc_cb_ptr = (tRFC_CB *)osi_malloc(sizeof(tRFC_CB));
+#endif /* #if (RFC_DYNAMIC_MEMORY) */
memset (&rfc_cb, 0, sizeof (tRFC_CB)); /* Init RFCOMM control block */
rfc_cb.rfc.last_mux = MAX_BD_CONNECTIONS;
#if RFC_DYNAMIC_MEMORY == FALSE
tRFC_CB rfc_cb;
+#else
+tRFC_CB *rfc_cb_ptr;
#endif
/*******************************************************************************
/********************************************************************************/
#if SDP_DYNAMIC_MEMORY == FALSE
tSDP_CB sdp_cb;
+#else
+tSDP_CB *sdp_cb_ptr;
#endif
/********************************************************************************/
*******************************************************************************/
void sdp_init (void)
{
+#if SDP_DYNAMIC_MEMORY
+ sdp_cb_ptr = (tSDP_CB *)osi_malloc(sizeof(tSDP_CB));
+#endif /* #if SDP_DYNAMIC_MEMORY */
/* Clears all structures and local SDP database (if Server is enabled) */
memset (&sdp_cb, 0, sizeof (tSDP_CB));
#include "btu.h"
#include "p_256_ecc_pp.h"
+#include "allocator.h"
/*******************************************************************************
**
*******************************************************************************/
void SMP_Init(void)
{
+#if SMP_DYNAMIC_MEMORY
+ smp_cb_ptr = (tSMP_CB *)osi_malloc(sizeof(tSMP_CB));
+#endif
memset(&smp_cb, 0, sizeof(tSMP_CB));
#if defined(SMP_INITIAL_TRACE_LEVEL)
p_256_init_curve(KEY_LENGTH_DWORDS_P256);
}
+void SMP_Free(void)
+{
+ memset(&smp_cb, 0, sizeof(tSMP_CB));
+#if SMP_DYNAMIC_MEMORY
+ FREE_AND_RESET(smp_cb_ptr);
+#endif /* #if SMP_DYNAMIC_MEMORY */
+}
+
/*******************************************************************************
**
#if SMP_DYNAMIC_MEMORY == FALSE
tSMP_CB smp_cb;
+#else
+tSMP_CB *smp_cb_ptr;
#endif
#define SMP_ALL_TBL_MASK 0x80