diff --git a/components/bt/Kconfig b/components/bt/Kconfig index b311a1be72..ca408d4990 100644 --- a/components/bt/Kconfig +++ b/components/bt/Kconfig @@ -173,6 +173,20 @@ config BT_ACL_CONNECTIONS 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 diff --git a/components/bt/bluedroid/bta/ar/bta_ar.c b/components/bt/bluedroid/bta/ar/bta_ar.c index 9c672329e3..9323aa8aa3 100644 --- a/components/bt/bluedroid/bta/ar/bta_ar.c +++ b/components/bt/bluedroid/bta/ar/bta_ar.c @@ -32,6 +32,8 @@ /* AV control block */ #if BTA_DYNAMIC_MEMORY == FALSE tBTA_AR_CB bta_ar_cb; +#else +tBTA_AR_CB *bta_ar_cb_ptr; #endif /******************************************************************************* diff --git a/components/bt/bluedroid/bta/av/bta_av_main.c b/components/bt/bluedroid/bta/av/bta_av_main.c index 5d5f441a63..f44186c6d6 100644 --- a/components/bt/bluedroid/bta/av/bta_av_main.c +++ b/components/bt/bluedroid/bta/av/bta_av_main.c @@ -194,6 +194,8 @@ const tBTA_AV_NSM_ACT bta_av_nsm_act[] = { /* 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) diff --git a/components/bt/bluedroid/bta/dm/bta_dm_main.c b/components/bt/bluedroid/bta/dm/bta_dm_main.c index 210331b40b..ed118adfb8 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/bluedroid/bta/dm/bta_dm_main.c @@ -25,6 +25,8 @@ #include "bta_api.h" #include "bta_sys.h" #include "bta_dm_int.h" +#include "allocator.h" +#include /***************************************************************************** @@ -35,6 +37,10 @@ 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 @@ -346,6 +352,18 @@ void bta_dm_sm_disable( ) 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 */ +} + /******************************************************************************* ** diff --git a/components/bt/bluedroid/bta/gatt/bta_gattc_main.c b/components/bt/bluedroid/bta/gatt/bta_gattc_main.c index 0551c0871b..f09b3d47fc 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gattc_main.c +++ b/components/bt/bluedroid/bta/gatt/bta_gattc_main.c @@ -29,6 +29,7 @@ #include #include "bta_gattc_int.h" +#include "allocator.h" /***************************************************************************** @@ -237,6 +238,8 @@ const tBTA_GATTC_ST_TBL bta_gattc_st_tbl[] = { /* 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 @@ -493,4 +496,12 @@ static char *gattc_state_code(tBTA_GATTC_STATE state_code) } #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 */ diff --git a/components/bt/bluedroid/bta/gatt/bta_gatts_main.c b/components/bt/bluedroid/bta/gatt/bta_gatts_main.c index dc0cb425c0..2ca2da566b 100644 --- a/components/bt/bluedroid/bta/gatt/bta_gatts_main.c +++ b/components/bt/bluedroid/bta/gatt/bta_gatts_main.c @@ -29,6 +29,7 @@ #include #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); @@ -46,6 +47,8 @@ const tBTA_GATTS_SRVC_ACT bta_gatts_srvc_build_act[] = { /* GATTS control block */ #if BTA_DYNAMIC_MEMORY == FALSE tBTA_GATTS_CB bta_gatts_cb; +#else +tBTA_GATTS_CB *bta_gatts_cb_ptr; #endif /******************************************************************************* @@ -135,4 +138,12 @@ BOOLEAN bta_gatts_hdl_event(BT_HDR *p_msg) 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 */ diff --git a/components/bt/bluedroid/bta/hh/bta_hh_main.c b/components/bt/bluedroid/bta/hh/bta_hh_main.c index aeee1061e0..0737d40805 100644 --- a/components/bt/bluedroid/bta/hh/bta_hh_main.c +++ b/components/bt/bluedroid/bta/hh/bta_hh_main.c @@ -245,6 +245,8 @@ const tBTA_HH_ST_TBL bta_hh_st_tbl[] = { *****************************************************************************/ #if BTA_DYNAMIC_MEMORY == FALSE tBTA_HH_CB bta_hh_cb; +#else +tBTA_HH_CB *bta_hh_cb_ptr; #endif /***************************************************************************** ** Static functions diff --git a/components/bt/bluedroid/bta/ar/bta_ar_int.h b/components/bt/bluedroid/bta/include/bta_ar_int.h similarity index 100% rename from components/bt/bluedroid/bta/ar/bta_ar_int.h rename to components/bt/bluedroid/bta/include/bta_ar_int.h diff --git a/components/bt/bluedroid/bta/av/bta_av_int.h b/components/bt/bluedroid/bta/include/bta_av_int.h similarity index 100% rename from components/bt/bluedroid/bta/av/bta_av_int.h rename to components/bt/bluedroid/bta/include/bta_av_int.h diff --git a/components/bt/bluedroid/bta/dm/bta_dm_int.h b/components/bt/bluedroid/bta/include/bta_dm_int.h similarity index 99% rename from components/bt/bluedroid/bta/dm/bta_dm_int.h rename to components/bt/bluedroid/bta/include/bta_dm_int.h index 6637912235..10f21726da 100644 --- a/components/bt/bluedroid/bta/dm/bta_dm_int.h +++ b/components/bt/bluedroid/bta/include/bta_dm_int.h @@ -1130,6 +1130,7 @@ extern tBTA_DM_DI_CB *bta_dm_di_cb_ptr; 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 ); diff --git a/components/bt/bluedroid/bta/include/bta_gattc_int.h b/components/bt/bluedroid/bta/include/bta_gattc_int.h index 59810b223c..c47668a659 100644 --- a/components/bt/bluedroid/bta/include/bta_gattc_int.h +++ b/components/bt/bluedroid/bta/include/bta_gattc_int.h @@ -514,5 +514,6 @@ extern BOOLEAN bta_gattc_conn_dealloc(BD_ADDR remote_bda); 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 */ diff --git a/components/bt/bluedroid/bta/include/bta_gatts_int.h b/components/bt/bluedroid/bta/include/bta_gatts_int.h index 211929f207..9d04423f3d 100644 --- a/components/bt/bluedroid/bta/include/bta_gatts_int.h +++ b/components/bt/bluedroid/bta/include/bta_gatts_int.h @@ -249,7 +249,7 @@ extern UINT8 bta_gatts_find_app_rcb_idx_by_app_if(tBTA_GATTS_CB *p_cb, tBTA_GATT 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 */ diff --git a/components/bt/bluedroid/bta/hh/bta_hh_int.h b/components/bt/bluedroid/bta/include/bta_hh_int.h similarity index 100% rename from components/bt/bluedroid/bta/hh/bta_hh_int.h rename to components/bt/bluedroid/bta/include/bta_hh_int.h diff --git a/components/bt/bluedroid/bta/sdp/bta_sdp_int.h b/components/bt/bluedroid/bta/include/bta_sdp_int.h similarity index 100% rename from components/bt/bluedroid/bta/sdp/bta_sdp_int.h rename to components/bt/bluedroid/bta/include/bta_sdp_int.h diff --git a/components/bt/bluedroid/bta/sdp/bta_sdp.c b/components/bt/bluedroid/bta/sdp/bta_sdp.c index f079d2f928..61cbbd62e5 100644 --- a/components/bt/bluedroid/bta/sdp/bta_sdp.c +++ b/components/bt/bluedroid/bta/sdp/bta_sdp.c @@ -37,6 +37,8 @@ #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 */ diff --git a/components/bt/bluedroid/bta/sys/bta_sys_main.c b/components/bt/bluedroid/bta/sys/bta_sys_main.c index 48eec5f112..e435cea902 100644 --- a/components/bt/bluedroid/bta/sys/bta_sys_main.c +++ b/components/bt/bluedroid/bta/sys/bta_sys_main.c @@ -48,6 +48,8 @@ /* 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; @@ -190,6 +192,9 @@ void bta_sys_free(void) { 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 } /******************************************************************************* diff --git a/components/bt/bluedroid/btc/core/btc_main.c b/components/bt/bluedroid/btc/core/btc_main.c index 84473b58eb..f37801e699 100644 --- a/components/bt/bluedroid/btc/core/btc_main.c +++ b/components/bt/bluedroid/btc/core/btc_main.c @@ -21,6 +21,10 @@ #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]; @@ -67,6 +71,14 @@ static void btc_init_bluetooth(void) 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(); #if (SMP_INCLUDED) btc_config_clean_up(); diff --git a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c index a18f42785d..8c8e4dde6d 100644 --- a/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -1164,3 +1164,9 @@ void btc_gap_callback_init(void) 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); +} diff --git a/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h index 8074c1b9b4..ba744702b2 100644 --- a/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -160,5 +160,6 @@ void btc_gap_ble_arg_deep_free(btc_msg_t *msg); 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__ */ diff --git a/components/bt/bluedroid/main/bte_init.c b/components/bt/bluedroid/main/bte_init.c index 9996129bc5..6d317fd4ea 100644 --- a/components/bt/bluedroid/main/bte_init.c +++ b/components/bt/bluedroid/main/bte_init.c @@ -26,6 +26,7 @@ #include "bt_target.h" #include + /* Stack Configuation Related Init Definaton * TODO: Now Just Unmask these defination until stack layer is OK */ @@ -59,6 +60,14 @@ #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 @@ -78,8 +87,13 @@ #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" @@ -119,9 +133,9 @@ tBTA_JV_CB *bta_jv_cb_ptr = NULL; #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 /***************************************************************************** @@ -169,6 +183,20 @@ void BTE_InitStack(void) 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 @@ -183,29 +211,66 @@ void BTE_InitStack(void) //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 diff --git a/components/bt/bluedroid/osi/allocator.c b/components/bt/bluedroid/osi/allocator.c index b96c288413..a6c2b8ea39 100644 --- a/components/bt/bluedroid/osi/allocator.c +++ b/components/bt/bluedroid/osi/allocator.c @@ -132,26 +132,40 @@ void *osi_malloc_func(size_t size) { #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) diff --git a/components/bt/bluedroid/osi/include/allocator.h b/components/bt/bluedroid/osi/include/allocator.h index b217cef9a4..707901f43f 100644 --- a/components/bt/bluedroid/osi/include/allocator.h +++ b/components/bt/bluedroid/osi/include/allocator.h @@ -21,6 +21,7 @@ #include #include +#include "esp_heap_caps.h" #include "sdkconfig.h" typedef void *(*alloc_fn)(size_t size); @@ -48,11 +49,13 @@ void osi_mem_dbg_record(void *p, int size, const char *func, int line); 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; \ }) @@ -60,12 +63,64 @@ void osi_mem_dbg_show(void); #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); \ @@ -75,10 +130,24 @@ do { \ #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_ */ diff --git a/components/bt/bluedroid/stack/a2dp/a2d_api.c b/components/bt/bluedroid/stack/a2dp/a2d_api.c index 5f403cc6d3..8c144b8ba3 100644 --- a/components/bt/bluedroid/stack/a2dp/a2d_api.c +++ b/components/bt/bluedroid/stack/a2dp/a2d_api.c @@ -27,6 +27,7 @@ #include "a2d_api.h" #include "a2d_int.h" #include "avdt_api.h" +#include "allocator.h" #if (defined(A2D_INCLUDED) && A2D_INCLUDED == TRUE) @@ -35,6 +36,8 @@ *****************************************************************************/ #if A2D_DYNAMIC_MEMORY == FALSE tA2D_CB a2d_cb; +#else +tA2D_CB *a2d_cb_ptr; #endif @@ -374,6 +377,9 @@ UINT8 A2D_BitsSet(UINT8 num) *******************************************************************************/ 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; diff --git a/components/bt/bluedroid/stack/avct/avct_api.c b/components/bt/bluedroid/stack/avct/avct_api.c index 3ff678b938..2d86ba8915 100644 --- a/components/bt/bluedroid/stack/avct/avct_api.c +++ b/components/bt/bluedroid/stack/avct/avct_api.c @@ -38,6 +38,8 @@ /* Control block for AVCT */ #if AVCT_DYNAMIC_MEMORY == FALSE tAVCT_CB avct_cb; +#else +tAVCT_CB *avct_cb_ptr; #endif /******************************************************************************* diff --git a/components/bt/bluedroid/stack/avdt/avdt_api.c b/components/bt/bluedroid/stack/avdt/avdt_api.c index d9147032e2..5167af13f0 100644 --- a/components/bt/bluedroid/stack/avdt/avdt_api.c +++ b/components/bt/bluedroid/stack/avdt/avdt_api.c @@ -39,6 +39,8 @@ /* Control block for AVDT */ #if AVDT_DYNAMIC_MEMORY == FALSE tAVDT_CB avdt_cb; +#else +tAVDT_CB *avdt_cb_ptr; #endif /******************************************************************************* diff --git a/components/bt/bluedroid/stack/avrc/avrc_sdp.c b/components/bt/bluedroid/stack/avrc/avrc_sdp.c index 4904c533d9..cdec74c871 100644 --- a/components/bt/bluedroid/stack/avrc/avrc_sdp.c +++ b/components/bt/bluedroid/stack/avrc/avrc_sdp.c @@ -25,6 +25,7 @@ #include "bt_target.h" #include "avrc_api.h" #include "avrc_int.h" +#include "allocator.h" #if (defined(AVRC_INCLUDED) && AVRC_INCLUDED == TRUE) @@ -41,6 +42,8 @@ *****************************************************************************/ #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 */ @@ -342,6 +345,9 @@ UINT8 AVRC_SetTraceLevel (UINT8 new_level) *******************************************************************************/ 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) diff --git a/components/bt/bluedroid/stack/btm/btm_main.c b/components/bt/bluedroid/stack/btm/btm_main.c index a2ee6ca3d6..043e7fd01d 100644 --- a/components/bt/bluedroid/stack/btm/btm_main.c +++ b/components/bt/bluedroid/stack/btm/btm_main.c @@ -33,6 +33,8 @@ */ #if BTM_DYNAMIC_MEMORY == FALSE tBTM_CB btm_cb; +#else +tBTM_CB *btm_cb_ptr; #endif /******************************************************************************* @@ -49,9 +51,11 @@ tBTM_CB btm_cb; *******************************************************************************/ 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); @@ -87,4 +91,7 @@ void btm_free(void) { 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 } diff --git a/components/bt/bluedroid/stack/btu/btu_init.c b/components/bt/bluedroid/stack/btu/btu_init.c index a3ffd0e702..60381c1830 100644 --- a/components/bt/bluedroid/stack/btu/btu_init.c +++ b/components/bt/bluedroid/stack/btu/btu_init.c @@ -119,12 +119,15 @@ void btu_free_core(void) 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 } /***************************************************************************** @@ -141,6 +144,9 @@ void btu_free_core(void) ******************************************************************************/ 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; @@ -182,6 +188,9 @@ error_exit:; 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); diff --git a/components/bt/bluedroid/stack/btu/btu_task.c b/components/bt/bluedroid/stack/btu/btu_task.c index fc908ba588..f3a738359c 100644 --- a/components/bt/bluedroid/stack/btu/btu_task.c +++ b/components/bt/bluedroid/stack/btu/btu_task.c @@ -91,6 +91,8 @@ extern void BTE_InitStack(void); */ #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; diff --git a/components/bt/bluedroid/stack/gatt/gatt_main.c b/components/bt/bluedroid/stack/gatt/gatt_main.c index 5ebd2ec0b5..cf5c0e3ad2 100644 --- a/components/bt/bluedroid/stack/gatt/gatt_main.c +++ b/components/bt/bluedroid/stack/gatt/gatt_main.c @@ -77,6 +77,8 @@ static const tL2CAP_APPL_INFO dyn_info = { #if GATT_DYNAMIC_MEMORY == FALSE tGATT_CB gatt_cb; +#else +tGATT_CB *gatt_cb_ptr; #endif tGATT_DEFAULT gatt_default; @@ -94,9 +96,9 @@ 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)); @@ -152,7 +154,7 @@ void gatt_init (void) ** Returns void ** *******************************************************************************/ -#if (GATTS_INCLUDED == TRUE) +#if (GATT_INCLUDED == TRUE) void gatt_free(void) { int i; @@ -171,14 +173,20 @@ void gatt_free(void) 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 diff --git a/components/bt/bluedroid/stack/include/dyn_mem.h b/components/bt/bluedroid/stack/include/dyn_mem.h index 2654316cba..223ae9f901 100644 --- a/components/bt/bluedroid/stack/include/dyn_mem.h +++ b/components/bt/bluedroid/stack/include/dyn_mem.h @@ -19,7 +19,40 @@ #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 @@ -45,35 +78,9 @@ #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. diff --git a/components/bt/bluedroid/stack/include/smp_api.h b/components/bt/bluedroid/stack/include/smp_api.h index cb043fdfa0..193cfe33b1 100644 --- a/components/bt/bluedroid/stack/include/smp_api.h +++ b/components/bt/bluedroid/stack/include/smp_api.h @@ -303,6 +303,18 @@ extern "C" *******************************************************************************/ 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 diff --git a/components/bt/bluedroid/stack/l2cap/l2c_main.c b/components/bt/bluedroid/stack/l2cap/l2c_main.c index a4c5c7e5a9..d52bc12286 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_main.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_main.c @@ -48,6 +48,8 @@ static void process_l2cap_cmd (tL2C_LCB *p_lcb, UINT8 *p, UINT16 pkt_len); /********************************************************************************/ #if L2C_DYNAMIC_MEMORY == FALSE tL2C_CB l2cb; +#else +tL2C_CB *l2c_cb_ptr; #endif /******************************************************************************* @@ -815,7 +817,9 @@ void l2c_process_held_packets(BOOLEAN timed_out) 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; @@ -874,6 +878,9 @@ void l2c_free(void) { list_free(l2cb.rcv_pending_q); l2cb.rcv_pending_q = NULL; +#if L2C_DYNAMIC_MEMORY + FREE_AND_RESET(l2c_cb_ptr); +#endif } /******************************************************************************* diff --git a/components/bt/bluedroid/stack/rfcomm/port_api.c b/components/bt/bluedroid/stack/rfcomm/port_api.c index 0cf9e09510..db84fe5984 100644 --- a/components/bt/bluedroid/stack/rfcomm/port_api.c +++ b/components/bt/bluedroid/stack/rfcomm/port_api.c @@ -1731,6 +1731,9 @@ int PORT_Test (UINT16 handle, UINT8 *p_data, UINT16 len) *******************************************************************************/ 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; diff --git a/components/bt/bluedroid/stack/rfcomm/rfc_port_if.c b/components/bt/bluedroid/stack/rfcomm/rfc_port_if.c index 632f82bb2e..d30b9a536d 100644 --- a/components/bt/bluedroid/stack/rfcomm/rfc_port_if.c +++ b/components/bt/bluedroid/stack/rfcomm/rfc_port_if.c @@ -36,6 +36,8 @@ #if RFC_DYNAMIC_MEMORY == FALSE tRFC_CB rfc_cb; +#else +tRFC_CB *rfc_cb_ptr; #endif /******************************************************************************* diff --git a/components/bt/bluedroid/stack/sdp/sdp_main.c b/components/bt/bluedroid/stack/sdp/sdp_main.c index 114eb8b2ef..db6a7a3d6c 100644 --- a/components/bt/bluedroid/stack/sdp/sdp_main.c +++ b/components/bt/bluedroid/stack/sdp/sdp_main.c @@ -47,6 +47,8 @@ /********************************************************************************/ #if SDP_DYNAMIC_MEMORY == FALSE tSDP_CB sdp_cb; +#else +tSDP_CB *sdp_cb_ptr; #endif /********************************************************************************/ @@ -79,6 +81,9 @@ static void sdp_disconnect_cfm (UINT16 l2cap_cid, UINT16 result); *******************************************************************************/ 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)); diff --git a/components/bt/bluedroid/stack/smp/smp_api.c b/components/bt/bluedroid/stack/smp/smp_api.c index 316f2ba2da..54f676a719 100644 --- a/components/bt/bluedroid/stack/smp/smp_api.c +++ b/components/bt/bluedroid/stack/smp/smp_api.c @@ -36,6 +36,7 @@ #include "btu.h" #include "p_256_ecc_pp.h" +#include "allocator.h" /******************************************************************************* ** @@ -48,6 +49,9 @@ *******************************************************************************/ 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) @@ -62,6 +66,14 @@ void SMP_Init(void) 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 */ +} + /******************************************************************************* ** diff --git a/components/bt/bluedroid/stack/smp/smp_main.c b/components/bt/bluedroid/stack/smp/smp_main.c index b94ce37e40..1bb0fcb470 100644 --- a/components/bt/bluedroid/stack/smp/smp_main.c +++ b/components/bt/bluedroid/stack/smp/smp_main.c @@ -676,6 +676,8 @@ static const tSMP_ENTRY_TBL smp_entry_table[] = { #if SMP_DYNAMIC_MEMORY == FALSE tSMP_CB smp_cb; +#else +tSMP_CB *smp_cb_ptr; #endif #define SMP_ALL_TBL_MASK 0x80