From b6ac006a5ae8713f93c95a2195e82842f44eb762 Mon Sep 17 00:00:00 2001 From: Matthias Ringwald Date: Thu, 5 May 2022 17:11:51 +0200 Subject: [PATCH] btstack_memory: add hci_iso_stream --- src/btstack_memory.c | 66 ++++++++++++++++++++++++++++++++ src/btstack_memory.h | 5 +++ tool/btstack_memory_generator.py | 12 ++++-- 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/src/btstack_memory.c b/src/btstack_memory.c index 92e6b9daa..dd82d7b90 100644 --- a/src/btstack_memory.c +++ b/src/btstack_memory.c @@ -1959,6 +1959,66 @@ void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet){ #endif +#endif +#ifdef ENABLE_LE_ISOCHRONOUS_STREAMS + +// MARK: hci_iso_stream_t +#if !defined(HAVE_MALLOC) && !defined(MAX_NR_HCI_ISO_STREAMS) + #if defined(MAX_NO_HCI_ISO_STREAMS) + #error "Deprecated MAX_NO_HCI_ISO_STREAMS defined instead of MAX_NR_HCI_ISO_STREAMS. Please update your btstack_config.h to use MAX_NR_HCI_ISO_STREAMS." + #else + #define MAX_NR_HCI_ISO_STREAMS 0 + #endif +#endif + +#ifdef MAX_NR_HCI_ISO_STREAMS +#if MAX_NR_HCI_ISO_STREAMS > 0 +static hci_iso_stream_t hci_iso_stream_storage[MAX_NR_HCI_ISO_STREAMS]; +static btstack_memory_pool_t hci_iso_stream_pool; +hci_iso_stream_t * btstack_memory_hci_iso_stream_get(void){ + void * buffer = btstack_memory_pool_get(&hci_iso_stream_pool); + if (buffer){ + memset(buffer, 0, sizeof(hci_iso_stream_t)); + } + return (hci_iso_stream_t *) buffer; +} +void btstack_memory_hci_iso_stream_free(hci_iso_stream_t *hci_iso_stream){ + btstack_memory_pool_free(&hci_iso_stream_pool, hci_iso_stream); +} +#else +hci_iso_stream_t * btstack_memory_hci_iso_stream_get(void){ + return NULL; +} +void btstack_memory_hci_iso_stream_free(hci_iso_stream_t *hci_iso_stream){ + UNUSED(hci_iso_stream); +}; +#endif +#elif defined(HAVE_MALLOC) + +typedef struct { + btstack_memory_buffer_t tracking; + hci_iso_stream_t data; +} btstack_memory_hci_iso_stream_t; + +hci_iso_stream_t * btstack_memory_hci_iso_stream_get(void){ + btstack_memory_hci_iso_stream_t * buffer = (btstack_memory_hci_iso_stream_t *) malloc(sizeof(btstack_memory_hci_iso_stream_t)); + if (buffer){ + memset(buffer, 0, sizeof(btstack_memory_hci_iso_stream_t)); + btstack_memory_tracking_add(&buffer->tracking); + return &buffer->data; + } else { + return NULL; + } +} +void btstack_memory_hci_iso_stream_free(hci_iso_stream_t *hci_iso_stream){ + // reconstruct buffer start + btstack_memory_buffer_t * buffer = &((btstack_memory_buffer_t *) hci_iso_stream)[-1]; + btstack_memory_tracking_remove(buffer); + free(buffer); +} +#endif + + #endif // init @@ -2084,5 +2144,11 @@ void btstack_memory_init(void){ btstack_memory_pool_create(&mesh_subnet_pool, mesh_subnet_storage, MAX_NR_MESH_SUBNETS, sizeof(mesh_subnet_t)); #endif +#endif +#ifdef ENABLE_LE_ISOCHRONOUS_STREAMS +#if MAX_NR_HCI_ISO_STREAMS > 0 + btstack_memory_pool_create(&hci_iso_stream_pool, hci_iso_stream_storage, MAX_NR_HCI_ISO_STREAMS, sizeof(hci_iso_stream_t)); +#endif + #endif } diff --git a/src/btstack_memory.h b/src/btstack_memory.h index d68247a0b..3dbe02f35 100644 --- a/src/btstack_memory.h +++ b/src/btstack_memory.h @@ -186,6 +186,11 @@ void btstack_memory_mesh_virtual_address_free(mesh_virtual_address_t *mesh_vir mesh_subnet_t * btstack_memory_mesh_subnet_get(void); void btstack_memory_mesh_subnet_free(mesh_subnet_t *mesh_subnet); +#endif +#ifdef ENABLE_LE_ISOCHRONOUS_STREAMS +hci_iso_stream_t * btstack_memory_hci_iso_stream_get(void); +void btstack_memory_hci_iso_stream_free(hci_iso_stream_t *hci_iso_stream); + #endif #if defined __cplusplus diff --git a/tool/btstack_memory_generator.py b/tool/btstack_memory_generator.py index ca01be079..48949cd9b 100755 --- a/tool/btstack_memory_generator.py +++ b/tool/btstack_memory_generator.py @@ -297,6 +297,9 @@ list_of_le_structs = [ list_of_mesh_structs = [ ['mesh_network_pdu', 'mesh_segmented_pdu', 'mesh_upper_transport_pdu', 'mesh_network_key', 'mesh_transport_key', 'mesh_virtual_address', 'mesh_subnet'] ] +list_of_iso_structs = [ + ['hci_iso_stream'] +] def writeln(f, data): f.write(data + "\n") @@ -323,10 +326,11 @@ def add_struct(f, guard, template, structs): writeln(f, "#endif") def add_structs(f, template): - add_struct(f, "", template, list_of_structs) - add_struct(f, "ENABLE_CLASSIC", template, list_of_classic_structs) - add_struct(f, "ENABLE_BLE", template, list_of_le_structs) - add_struct(f, "ENABLE_MESH", template, list_of_mesh_structs) + add_struct(f, "", template, list_of_structs) + add_struct(f, "ENABLE_CLASSIC", template, list_of_classic_structs) + add_struct(f, "ENABLE_BLE", template, list_of_le_structs) + add_struct(f, "ENABLE_MESH", template, list_of_mesh_structs) + add_struct(f, "ENABLE_LE_ISOCHRONOUS_STREAMS", template, list_of_iso_structs) btstack_root = os.path.abspath(os.path.dirname(sys.argv[0]) + '/..') file_name = btstack_root + "/src/btstack_memory"