From cf49570bee47d681485b34f681e32667c8b7019f Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Tue, 4 Aug 2015 13:59:06 +0200 Subject: [PATCH] added sm_lookup_entry_t to memory pools --- platforms/arduino/btstack-config.h | 2 +- platforms/ez430-rf2560/btstack-config.h | 1 + .../msp-exp430f5438-cc2564b/btstack-config.h | 1 + .../msp430f5229lp-cc2564b/btstack-config.h | 1 + platforms/pic32-harmony/src/btstack-config.h | 1 + .../stm32-f103rb-nucleo/btstack-config.h | 1 + src/btstack_memory.c | 35 +++++++++++++++++++ src/btstack_memory.h | 7 ++-- tools/btstack_memory_generator.py | 5 +-- 9 files changed, 49 insertions(+), 5 deletions(-) diff --git a/platforms/arduino/btstack-config.h b/platforms/arduino/btstack-config.h index c7f5615c8..f9ebab96d 100644 --- a/platforms/arduino/btstack-config.h +++ b/platforms/arduino/btstack-config.h @@ -33,6 +33,6 @@ #define MAX_ATT_DB_SIZE 200 #define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_WHITELIST_ENTRIES 1 - +#define MAX_NO_SM_LOOKUP_ENTRIES 3 #endif \ No newline at end of file diff --git a/platforms/ez430-rf2560/btstack-config.h b/platforms/ez430-rf2560/btstack-config.h index 65124ea4d..85c79fd17 100644 --- a/platforms/ez430-rf2560/btstack-config.h +++ b/platforms/ez430-rf2560/btstack-config.h @@ -36,6 +36,7 @@ #define MAX_NO_DB_MEM_SERVICES 1 #define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_WHITELIST_ENTRIES 1 +#define MAX_NO_SM_LOOKUP_ENTRIES 3 #endif diff --git a/platforms/msp-exp430f5438-cc2564b/btstack-config.h b/platforms/msp-exp430f5438-cc2564b/btstack-config.h index 65124ea4d..85c79fd17 100644 --- a/platforms/msp-exp430f5438-cc2564b/btstack-config.h +++ b/platforms/msp-exp430f5438-cc2564b/btstack-config.h @@ -36,6 +36,7 @@ #define MAX_NO_DB_MEM_SERVICES 1 #define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_WHITELIST_ENTRIES 1 +#define MAX_NO_SM_LOOKUP_ENTRIES 3 #endif diff --git a/platforms/msp430f5229lp-cc2564b/btstack-config.h b/platforms/msp430f5229lp-cc2564b/btstack-config.h index 65124ea4d..85c79fd17 100644 --- a/platforms/msp430f5229lp-cc2564b/btstack-config.h +++ b/platforms/msp430f5229lp-cc2564b/btstack-config.h @@ -36,6 +36,7 @@ #define MAX_NO_DB_MEM_SERVICES 1 #define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_WHITELIST_ENTRIES 1 +#define MAX_NO_SM_LOOKUP_ENTRIES 3 #endif diff --git a/platforms/pic32-harmony/src/btstack-config.h b/platforms/pic32-harmony/src/btstack-config.h index 18c45e675..6d4fe27a0 100644 --- a/platforms/pic32-harmony/src/btstack-config.h +++ b/platforms/pic32-harmony/src/btstack-config.h @@ -33,5 +33,6 @@ #define MAX_NO_BNEP_CHANNELS 0 #define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_WHITELIST_ENTRIES 1 +#define MAX_NO_SM_LOOKUP_ENTRIES 3 #endif \ No newline at end of file diff --git a/platforms/stm32-f103rb-nucleo/btstack-config.h b/platforms/stm32-f103rb-nucleo/btstack-config.h index ee8e45a63..3617d31bc 100644 --- a/platforms/stm32-f103rb-nucleo/btstack-config.h +++ b/platforms/stm32-f103rb-nucleo/btstack-config.h @@ -33,5 +33,6 @@ #define MAX_NO_BNEP_CHANNELS 0 #define MAX_NO_HFP_CONNECTIONS 0 #define MAX_NO_WHITELIST_ENTRIES 1 +#define MAX_NO_SM_LOOKUP_ENTRIES 3 #endif \ No newline at end of file diff --git a/src/btstack_memory.c b/src/btstack_memory.c index f6f2667c5..7110fbe1a 100644 --- a/src/btstack_memory.c +++ b/src/btstack_memory.c @@ -539,6 +539,38 @@ void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry){ #endif +// MARK: sm_lookup_entry_t +#ifdef MAX_NO_SM_LOOKUP_ENTRIES +#if MAX_NO_SM_LOOKUP_ENTRIES > 0 +static sm_lookup_entry_t sm_lookup_entry_storage[MAX_NO_SM_LOOKUP_ENTRIES]; +static memory_pool_t sm_lookup_entry_pool; +sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ + return (sm_lookup_entry_t *) memory_pool_get(&sm_lookup_entry_pool); +} +void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ + memory_pool_free(&sm_lookup_entry_pool, sm_lookup_entry); +} +#else +sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ + return NULL; +} +void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ + // silence compiler warning about unused parameter in a portable way + (void) sm_lookup_entry; +}; +#endif +#elif defined(HAVE_MALLOC) +sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void){ + return (sm_lookup_entry_t*) malloc(sizeof(sm_lookup_entry_t)); +} +void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){ + free(sm_lookup_entry); +} +#else +#error "Neither HAVE_MALLOC nor MAX_NO_SM_LOOKUP_ENTRIES for struct sm_lookup_entry is defined. Please, edit the config file." +#endif + + #endif // init void btstack_memory_init(void){ @@ -588,5 +620,8 @@ void btstack_memory_init(void){ #if MAX_NO_WHITELIST_ENTRIES > 0 memory_pool_create(&whitelist_entry_pool, whitelist_entry_storage, MAX_NO_WHITELIST_ENTRIES, sizeof(whitelist_entry_t)); #endif +#if MAX_NO_SM_LOOKUP_ENTRIES > 0 + memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NO_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t)); +#endif #endif } diff --git a/src/btstack_memory.h b/src/btstack_memory.h index 73cbec47a..deccefd74 100644 --- a/src/btstack_memory.h +++ b/src/btstack_memory.h @@ -38,7 +38,7 @@ /* - * btstsack_memory.h + * btstack_memory.h * * @brief BTstack memory management via configurable memory pools * @@ -62,6 +62,7 @@ extern "C" { #ifdef HAVE_BLE #include "gatt_client.h" +#include "sm.h" #endif /* API_START */ @@ -110,13 +111,15 @@ hfp_connection_t * btstack_memory_hfp_connection_get(void); void btstack_memory_hfp_connection_free(hfp_connection_t *hfp_connection); #ifdef HAVE_BLE -// gatt_client, gatt_subclient, whitelist_entry +// gatt_client, gatt_subclient, whitelist_entry, sm_lookup_entry gatt_client_t * btstack_memory_gatt_client_get(void); void btstack_memory_gatt_client_free(gatt_client_t *gatt_client); gatt_subclient_t * btstack_memory_gatt_subclient_get(void); void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient); whitelist_entry_t * btstack_memory_whitelist_entry_get(void); void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry); +sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void); +void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry); #endif #if defined __cplusplus diff --git a/tools/btstack_memory_generator.py b/tools/btstack_memory_generator.py index 4a8f3bae1..862ff4b24 100755 --- a/tools/btstack_memory_generator.py +++ b/tools/btstack_memory_generator.py @@ -41,7 +41,7 @@ copyright = """/* hfile_header_begin = """ /* - * btstsack_memory.h + * btstack_memory.h * * @brief BTstack memory management via configurable memory pools * @@ -65,6 +65,7 @@ extern "C" { #ifdef HAVE_BLE #include "gatt_client.h" +#include "sm.h" #endif /* API_START */ @@ -156,7 +157,7 @@ def replacePlaceholder(template, struct_name): return snippet list_of_structs = [ ["hci_connection"], ["l2cap_service", "l2cap_channel"], ["rfcomm_multiplexer", "rfcomm_service", "rfcomm_channel"], ["db_mem_device_name", "db_mem_device_link_key", "db_mem_service"], ["bnep_service", "bnep_channel"], ["hfp_connection"]] -list_of_le_structs = [["gatt_client", "gatt_subclient","whitelist_entry"]] +list_of_le_structs = [["gatt_client", "gatt_subclient", "whitelist_entry", "sm_lookup_entry"]] file_name = "../src/btstack_memory"