1
0
mirror of https://github.com/bluekitchen/btstack.git synced 2025-03-23 10:21:12 +00:00

btstack_memory: add hci_iso_stream

This commit is contained in:
Matthias Ringwald 2022-05-05 17:11:51 +02:00
parent a260944440
commit b6ac006a5a
3 changed files with 79 additions and 4 deletions

@ -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
}

@ -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

@ -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"