]> granicus.if.org Git - esp-idf/commitdiff
component/bt: Added the bluedroid environment variable dynomic malloc support & suppo...
authorYulong <huangyulong@espressif.com>
Wed, 18 Oct 2017 07:34:43 +0000 (03:34 -0400)
committeryulong <huangyulong@espressif.com>
Wed, 24 Jan 2018 07:18:02 +0000 (15:18 +0800)
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.

38 files changed:
components/bt/Kconfig
components/bt/bluedroid/bta/ar/bta_ar.c
components/bt/bluedroid/bta/av/bta_av_main.c
components/bt/bluedroid/bta/dm/bta_dm_main.c
components/bt/bluedroid/bta/gatt/bta_gattc_main.c
components/bt/bluedroid/bta/gatt/bta_gatts_main.c
components/bt/bluedroid/bta/hh/bta_hh_main.c
components/bt/bluedroid/bta/include/bta_ar_int.h [moved from components/bt/bluedroid/bta/ar/bta_ar_int.h with 100% similarity]
components/bt/bluedroid/bta/include/bta_av_int.h [moved from components/bt/bluedroid/bta/av/bta_av_int.h with 100% similarity]
components/bt/bluedroid/bta/include/bta_dm_int.h [moved from components/bt/bluedroid/bta/dm/bta_dm_int.h with 99% similarity]
components/bt/bluedroid/bta/include/bta_gattc_int.h
components/bt/bluedroid/bta/include/bta_gatts_int.h
components/bt/bluedroid/bta/include/bta_hh_int.h [moved from components/bt/bluedroid/bta/hh/bta_hh_int.h with 100% similarity]
components/bt/bluedroid/bta/include/bta_sdp_int.h [moved from components/bt/bluedroid/bta/sdp/bta_sdp_int.h with 100% similarity]
components/bt/bluedroid/bta/sdp/bta_sdp.c
components/bt/bluedroid/bta/sys/bta_sys_main.c
components/bt/bluedroid/btc/core/btc_main.c
components/bt/bluedroid/btc/profile/std/gap/btc_gap_ble.c
components/bt/bluedroid/btc/profile/std/include/btc_gap_ble.h
components/bt/bluedroid/main/bte_init.c
components/bt/bluedroid/osi/allocator.c
components/bt/bluedroid/osi/include/allocator.h
components/bt/bluedroid/stack/a2dp/a2d_api.c
components/bt/bluedroid/stack/avct/avct_api.c
components/bt/bluedroid/stack/avdt/avdt_api.c
components/bt/bluedroid/stack/avrc/avrc_sdp.c
components/bt/bluedroid/stack/btm/btm_main.c
components/bt/bluedroid/stack/btu/btu_init.c
components/bt/bluedroid/stack/btu/btu_task.c
components/bt/bluedroid/stack/gatt/gatt_main.c
components/bt/bluedroid/stack/include/dyn_mem.h
components/bt/bluedroid/stack/include/smp_api.h
components/bt/bluedroid/stack/l2cap/l2c_main.c
components/bt/bluedroid/stack/rfcomm/port_api.c
components/bt/bluedroid/stack/rfcomm/rfc_port_if.c
components/bt/bluedroid/stack/sdp/sdp_main.c
components/bt/bluedroid/stack/smp/smp_api.c
components/bt/bluedroid/stack/smp/smp_main.c

index b311a1be726f68965acf5d03686a2a687fdbb234..ca408d4990aebff6bb741eb7cbf39c5b6bb1fc15 100644 (file)
@@ -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
index 9c672329e3350372f9fc821002de4267192d05c4..9323aa8aa32c66a8290cc5c0a1a27393810bb0de 100644 (file)
@@ -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
 
 /*******************************************************************************
index 5d5f441a63917c000a39ec10c9e2bebbd5f5d39b..f44186c6d6c6c7117cc916d8131222bd93fc3711 100644 (file)
@@ -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)
index 210331b40b7d0f9424328368be4eff5b9854f7b4..ed118adfb8c8ef1dff5f034f296574dbfefc8079 100644 (file)
@@ -25,6 +25,8 @@
 #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
 
 
@@ -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 */
+}
+
 
 /*******************************************************************************
 **
index 0551c0871b031c3973d2e9577b6b46e16dbb906e..f09b3d47fcc212b36af0e0b3a19e6de783bb2708 100644 (file)
@@ -29,6 +29,7 @@
 #include <string.h>
 
 #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 */
index dc0cb425c09df46fa1873b90c0f2ce208da7e7c1..2ca2da566b056b2d4b0c8f4e90efb5e4678eef1d 100644 (file)
@@ -29,6 +29,7 @@
 #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);
@@ -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 */
index aeee1061e01573bee445fec7bb59193ed849e7ce..0737d408051398ea2969869a8e863425343df42e 100644 (file)
@@ -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
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 6637912235fd449c1a8840fd57734adb9bf9195a..10f21726da1fe2bd9c20044bd5b148002e2b84f1 100644 (file)
@@ -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 );
 
index 59810b223cfee9fb5db47c00151d2a9442425dfb..c47668a659ee2e5dc7c6fa64aae350e3bc0f6c0b 100644 (file)
@@ -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 */
index 211929f207586f40514e88aa9ecb4dddf123fe00..9d04423f3d39497ea25c6c74c77ee10834adf8b3 100644 (file)
@@ -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 */
 
index f079d2f92853179c121489814c92d6b5a0374340..61cbbd62e5d27d7ec6c379c059bccbd2d865e020 100644 (file)
@@ -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 */
index 48eec5f11293effc19d131d48ed73e8046dcbf58..e435cea9027c04ce6b8c9095677390a94cf3d101 100644 (file)
@@ -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
 }
 
 /*******************************************************************************
index 2317074c8e7194122fec9bfa7332f447d1fb6ee8..fd8b037b26d1eca79e19d72ddb934bf42deaa04b 100644 (file)
 #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();
     btc_config_clean_up();
     osi_alarm_deinit();
index a18f42785da2288817668b7903eafc93d4aa3c22..8c8e4dde6d0c7ed4bc8cb00bba179c8309576095 100644 (file)
@@ -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);
+}
index 8074c1b9b420712aa203c3c629c9188d75417b09..ba744702b295edec58b905e02af4c88e63ce7f79 100644 (file)
@@ -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__ */
index 9996129bc58be231469044d8815c88e4c6d0b6b6..6d317fd4ea72dc2b58f6eaa77a33a88ba2bc1907 100644 (file)
@@ -26,6 +26,7 @@
 #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"
@@ -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
index b96c288413a8bc4989411d3c59506e5df76a0f88..a6c2b8ea397f4e45ae9bd77fdbf8621ad3f8a1b7 100644 (file)
@@ -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)
index b217cef9a4166cef17a6b9470242de9a847a2b55..707901f43fd73bde71dbe7ffe3879dd096175064 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <stddef.h>
 #include <stdlib.h>
+#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_ */
index 5f403cc6d3f6bf55a4f5921031b00368e4eab63d..8c144b8ba3a528f1f6295700bf054ba7a967ee98 100644 (file)
@@ -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;
index 3ff678b93851831a59ba9a59177acf1fccb14c8f..2d86ba8915d49c00c3fa4efd446c27e4040377b3 100644 (file)
@@ -38,6 +38,8 @@
 /* Control block for AVCT */
 #if AVCT_DYNAMIC_MEMORY == FALSE
 tAVCT_CB avct_cb;
+#else 
+tAVCT_CB *avct_cb_ptr;
 #endif
 
 /*******************************************************************************
index d9147032e260e6f14e87b1c64a7c485317e37fa7..5167af13f0ff0b90373d81d7b04b252104329ad3 100644 (file)
@@ -39,6 +39,8 @@
 /* Control block for AVDT */
 #if AVDT_DYNAMIC_MEMORY == FALSE
 tAVDT_CB avdt_cb;
+#else
+tAVDT_CB *avdt_cb_ptr;
 #endif
 
 /*******************************************************************************
index 4904c533d9edebbc693a488949fbb5ae7c4219ee..cdec74c87103daf407df35ee4df62a13f5cf3307 100644 (file)
@@ -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)
index a2ee6ca3d64bdefaf9635bd2973750335544c196..043e7fd01d97deb5887068c4bde2b9d4e37d9765 100644 (file)
@@ -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
 }
index a3ffd0e70241878881c2785f62768e9321c46148..60381c183049c108b3495aa49e2e4e096c905ec5 100644 (file)
@@ -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);
index fc908ba588f315db20b64f39e5f71876ff39ec05..f3a738359ce6a676f76ae1852ff0f71ed55c8a6b 100644 (file)
@@ -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;
index 5ebd2ec0b532e620a73fee05d75110369c275abc..cf5c0e3ad274b91602e32720210f359998809f32 100644 (file)
@@ -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
 
index 2654316cba0a705ad6563f634dcc72aaaf7fe0b1..223ae9f901054dd98a897eab7b9fbc6f187d6c7e 100644 (file)
 #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.
index cb043fdfa058bb58065eaa9ee54a5e323ddbdc1e..193cfe33b15a8e8ed55d452f45a5f7e97a99f358 100644 (file)
@@ -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
index a4c5c7e5a9b59488d582baa269dc7de1cdb6f9b5..d52bc12286f3556be5e7a749746243364ca0afa1 100644 (file)
@@ -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 
 }
 
 /*******************************************************************************
index 0cf9e0951034f875a6f18b4aa977ece956c053e0..db84fe59842850fc05909aea5a53036002f189ae 100644 (file)
@@ -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;
index 632f82bb2e44a8d9739cf11024c3bf292c46fed6..d30b9a536d6570df3229e369d8319f6ccaf5a8e7 100644 (file)
@@ -36,6 +36,8 @@
 
 #if RFC_DYNAMIC_MEMORY == FALSE
 tRFC_CB rfc_cb;
+#else
+tRFC_CB *rfc_cb_ptr;
 #endif
 
 /*******************************************************************************
index 114eb8b2ef4a7ad7d5816cfaa182e06ef809ef77..db6a7a3d6c9af0b5215ce46c1479fa1733f7ab06 100644 (file)
@@ -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));
 
index 316f2ba2da567594e2a0b3b7fb5c495f94fb316b..54f676a719ba6f4dad4e147fad8fdf397dfddcd2 100644 (file)
@@ -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 */
+}
+
 
 /*******************************************************************************
 **
index b94ce37e4049da300a80dd3957824a38a38344f2..1bb0fcb470bbb8b0c6bfe630ede32e466dd9693e 100644 (file)
@@ -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