xref: /btstack/src/btstack_memory.c (revision e045abde1a6a13bf648f6b025a3686f51624677e)
1a3b02b71Smatthias.ringwald /*
26b64433eSmatthias.ringwald  * Copyright (C) 2009-2012 by Matthias Ringwald
3a3b02b71Smatthias.ringwald  *
4a3b02b71Smatthias.ringwald  * Redistribution and use in source and binary forms, with or without
5a3b02b71Smatthias.ringwald  * modification, are permitted provided that the following conditions
6a3b02b71Smatthias.ringwald  * are met:
7a3b02b71Smatthias.ringwald  *
8a3b02b71Smatthias.ringwald  * 1. Redistributions of source code must retain the above copyright
9a3b02b71Smatthias.ringwald  *    notice, this list of conditions and the following disclaimer.
10a3b02b71Smatthias.ringwald  * 2. Redistributions in binary form must reproduce the above copyright
11a3b02b71Smatthias.ringwald  *    notice, this list of conditions and the following disclaimer in the
12a3b02b71Smatthias.ringwald  *    documentation and/or other materials provided with the distribution.
13a3b02b71Smatthias.ringwald  * 3. Neither the name of the copyright holders nor the names of
14a3b02b71Smatthias.ringwald  *    contributors may be used to endorse or promote products derived
15a3b02b71Smatthias.ringwald  *    from this software without specific prior written permission.
166b64433eSmatthias.ringwald  * 4. Any redistribution, use, or modification is done solely for
176b64433eSmatthias.ringwald  *    personal benefit and not for any commercial purpose or for
186b64433eSmatthias.ringwald  *    monetary gain.
19a3b02b71Smatthias.ringwald  *
20a3b02b71Smatthias.ringwald  * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS
21a3b02b71Smatthias.ringwald  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22a3b02b71Smatthias.ringwald  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23a3b02b71Smatthias.ringwald  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
24a3b02b71Smatthias.ringwald  * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25a3b02b71Smatthias.ringwald  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26a3b02b71Smatthias.ringwald  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
27a3b02b71Smatthias.ringwald  * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
28a3b02b71Smatthias.ringwald  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29a3b02b71Smatthias.ringwald  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
30a3b02b71Smatthias.ringwald  * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31a3b02b71Smatthias.ringwald  * SUCH DAMAGE.
32a3b02b71Smatthias.ringwald  *
336b64433eSmatthias.ringwald  * Please inquire about commercial licensing options at [email protected]
346b64433eSmatthias.ringwald  *
35a3b02b71Smatthias.ringwald  */
36a3b02b71Smatthias.ringwald 
37a3b02b71Smatthias.ringwald /*
38a3b02b71Smatthias.ringwald  *  btstsack_memory.h
39a3b02b71Smatthias.ringwald  *
40a3b02b71Smatthias.ringwald  *  @brief BTstack memory management via configurable memory pools
41a3b02b71Smatthias.ringwald  *
42e0e5e285Smatthias.ringwald  *  @note code semi-atuomatically generated by btstack_memory_generator.py
43a3b02b71Smatthias.ringwald  *
44a3b02b71Smatthias.ringwald  */
45a3b02b71Smatthias.ringwald 
46a3b02b71Smatthias.ringwald #include "btstack_memory.h"
47a3b02b71Smatthias.ringwald #include <btstack/memory_pool.h>
48a3b02b71Smatthias.ringwald 
49a3b02b71Smatthias.ringwald #include <stdlib.h>
50a3b02b71Smatthias.ringwald 
51c8901d41Smatthias.ringwald #include "config.h"
52a3b02b71Smatthias.ringwald #include "hci.h"
53a3b02b71Smatthias.ringwald #include "l2cap.h"
54a3b02b71Smatthias.ringwald #include "rfcomm.h"
55a3b02b71Smatthias.ringwald 
56a3b02b71Smatthias.ringwald // MARK: hci_connection_t
57a3b02b71Smatthias.ringwald #ifdef MAX_NO_HCI_CONNECTIONS
58c4d3f927Smatthias.ringwald #if MAX_NO_HCI_CONNECTIONS > 0
59a3b02b71Smatthias.ringwald static hci_connection_t hci_connection_storage[MAX_NO_HCI_CONNECTIONS];
60a3b02b71Smatthias.ringwald static memory_pool_t hci_connection_pool;
61a3b02b71Smatthias.ringwald void * btstack_memory_hci_connection_get(void){
62a3b02b71Smatthias.ringwald     return memory_pool_get(&hci_connection_pool);
63a3b02b71Smatthias.ringwald }
64a3b02b71Smatthias.ringwald void btstack_memory_hci_connection_free(void *hci_connection){
65a3b02b71Smatthias.ringwald     memory_pool_free(&hci_connection_pool, hci_connection);
66a3b02b71Smatthias.ringwald }
67c4d3f927Smatthias.ringwald #else
68c4d3f927Smatthias.ringwald void * btstack_memory_hci_connection_get(void){
69c4d3f927Smatthias.ringwald     return NULL;
70c4d3f927Smatthias.ringwald }
71c4d3f927Smatthias.ringwald void btstack_memory_hci_connection_free(void *hci_connection){
72c4d3f927Smatthias.ringwald };
73c4d3f927Smatthias.ringwald #endif
74a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
75a3b02b71Smatthias.ringwald void * btstack_memory_hci_connection_get(void){
76a3b02b71Smatthias.ringwald     return malloc(sizeof(hci_connection_t));
77a3b02b71Smatthias.ringwald }
78a3b02b71Smatthias.ringwald void  btstack_memory_hci_connection_free(void *hci_connection){
79a3b02b71Smatthias.ringwald     free(hci_connection);
80a3b02b71Smatthias.ringwald }
81*e045abdeSmatthias.ringwald #else
82*e045abdeSmatthias.ringwald #error "The struct hci_connection has neither HAVE_MALLOC nor MAX_NO_HCI_CONNECTIONS defined. Please, edit the config file."
83a3b02b71Smatthias.ringwald #endif
84a3b02b71Smatthias.ringwald 
85a3b02b71Smatthias.ringwald 
86a3b02b71Smatthias.ringwald // MARK: l2cap_service_t
87a3b02b71Smatthias.ringwald #ifdef MAX_NO_L2CAP_SERVICES
88c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_SERVICES > 0
89a3b02b71Smatthias.ringwald static l2cap_service_t l2cap_service_storage[MAX_NO_L2CAP_SERVICES];
90a3b02b71Smatthias.ringwald static memory_pool_t l2cap_service_pool;
91a3b02b71Smatthias.ringwald void * btstack_memory_l2cap_service_get(void){
92a3b02b71Smatthias.ringwald     return memory_pool_get(&l2cap_service_pool);
93a3b02b71Smatthias.ringwald }
94a3b02b71Smatthias.ringwald void btstack_memory_l2cap_service_free(void *l2cap_service){
95a3b02b71Smatthias.ringwald     memory_pool_free(&l2cap_service_pool, l2cap_service);
96a3b02b71Smatthias.ringwald }
97c4d3f927Smatthias.ringwald #else
98c4d3f927Smatthias.ringwald void * btstack_memory_l2cap_service_get(void){
99c4d3f927Smatthias.ringwald     return NULL;
100c4d3f927Smatthias.ringwald }
101c4d3f927Smatthias.ringwald void btstack_memory_l2cap_service_free(void *l2cap_service){
102c4d3f927Smatthias.ringwald };
103c4d3f927Smatthias.ringwald #endif
104a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
105a3b02b71Smatthias.ringwald void * btstack_memory_l2cap_service_get(void){
106a3b02b71Smatthias.ringwald     return malloc(sizeof(l2cap_service_t));
107a3b02b71Smatthias.ringwald }
108a3b02b71Smatthias.ringwald void  btstack_memory_l2cap_service_free(void *l2cap_service){
109a3b02b71Smatthias.ringwald     free(l2cap_service);
110a3b02b71Smatthias.ringwald }
111*e045abdeSmatthias.ringwald #else
112*e045abdeSmatthias.ringwald #error "The struct l2cap_service has neither HAVE_MALLOC nor MAX_NO_L2CAP_SERVICES defined. Please, edit the config file."
113a3b02b71Smatthias.ringwald #endif
114a3b02b71Smatthias.ringwald 
115a3b02b71Smatthias.ringwald 
116a3b02b71Smatthias.ringwald // MARK: l2cap_channel_t
117a3b02b71Smatthias.ringwald #ifdef MAX_NO_L2CAP_CHANNELS
118c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_CHANNELS > 0
119a3b02b71Smatthias.ringwald static l2cap_channel_t l2cap_channel_storage[MAX_NO_L2CAP_CHANNELS];
120a3b02b71Smatthias.ringwald static memory_pool_t l2cap_channel_pool;
121a3b02b71Smatthias.ringwald void * btstack_memory_l2cap_channel_get(void){
122a3b02b71Smatthias.ringwald     return memory_pool_get(&l2cap_channel_pool);
123a3b02b71Smatthias.ringwald }
124a3b02b71Smatthias.ringwald void btstack_memory_l2cap_channel_free(void *l2cap_channel){
125a3b02b71Smatthias.ringwald     memory_pool_free(&l2cap_channel_pool, l2cap_channel);
126a3b02b71Smatthias.ringwald }
127c4d3f927Smatthias.ringwald #else
128c4d3f927Smatthias.ringwald void * btstack_memory_l2cap_channel_get(void){
129c4d3f927Smatthias.ringwald     return NULL;
130c4d3f927Smatthias.ringwald }
131c4d3f927Smatthias.ringwald void btstack_memory_l2cap_channel_free(void *l2cap_channel){
132c4d3f927Smatthias.ringwald };
133c4d3f927Smatthias.ringwald #endif
134a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
135a3b02b71Smatthias.ringwald void * btstack_memory_l2cap_channel_get(void){
136a3b02b71Smatthias.ringwald     return malloc(sizeof(l2cap_channel_t));
137a3b02b71Smatthias.ringwald }
138a3b02b71Smatthias.ringwald void  btstack_memory_l2cap_channel_free(void *l2cap_channel){
139a3b02b71Smatthias.ringwald     free(l2cap_channel);
140a3b02b71Smatthias.ringwald }
141*e045abdeSmatthias.ringwald #else
142*e045abdeSmatthias.ringwald #error "The struct l2cap_channel has neither HAVE_MALLOC nor MAX_NO_L2CAP_CHANNELS defined. Please, edit the config file."
143a3b02b71Smatthias.ringwald #endif
144a3b02b71Smatthias.ringwald 
145a3b02b71Smatthias.ringwald 
146a3b02b71Smatthias.ringwald // MARK: rfcomm_multiplexer_t
147a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_MULTIPLEXERS
148c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_MULTIPLEXERS > 0
149a3b02b71Smatthias.ringwald static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NO_RFCOMM_MULTIPLEXERS];
150a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_multiplexer_pool;
151a3b02b71Smatthias.ringwald void * btstack_memory_rfcomm_multiplexer_get(void){
152a3b02b71Smatthias.ringwald     return memory_pool_get(&rfcomm_multiplexer_pool);
153a3b02b71Smatthias.ringwald }
154a3b02b71Smatthias.ringwald void btstack_memory_rfcomm_multiplexer_free(void *rfcomm_multiplexer){
155a3b02b71Smatthias.ringwald     memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
156a3b02b71Smatthias.ringwald }
157c4d3f927Smatthias.ringwald #else
158c4d3f927Smatthias.ringwald void * btstack_memory_rfcomm_multiplexer_get(void){
159c4d3f927Smatthias.ringwald     return NULL;
160c4d3f927Smatthias.ringwald }
161c4d3f927Smatthias.ringwald void btstack_memory_rfcomm_multiplexer_free(void *rfcomm_multiplexer){
162c4d3f927Smatthias.ringwald };
163c4d3f927Smatthias.ringwald #endif
164a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
165a3b02b71Smatthias.ringwald void * btstack_memory_rfcomm_multiplexer_get(void){
166a3b02b71Smatthias.ringwald     return malloc(sizeof(rfcomm_multiplexer_t));
167a3b02b71Smatthias.ringwald }
168a3b02b71Smatthias.ringwald void  btstack_memory_rfcomm_multiplexer_free(void *rfcomm_multiplexer){
169a3b02b71Smatthias.ringwald     free(rfcomm_multiplexer);
170a3b02b71Smatthias.ringwald }
171*e045abdeSmatthias.ringwald #else
172*e045abdeSmatthias.ringwald #error "The struct rfcomm_multiplexer has neither HAVE_MALLOC nor MAX_NO_RFCOMM_MULTIPLEXERS defined. Please, edit the config file."
173a3b02b71Smatthias.ringwald #endif
174a3b02b71Smatthias.ringwald 
175a3b02b71Smatthias.ringwald 
176a3b02b71Smatthias.ringwald // MARK: rfcomm_service_t
177a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_SERVICES
178c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_SERVICES > 0
179a3b02b71Smatthias.ringwald static rfcomm_service_t rfcomm_service_storage[MAX_NO_RFCOMM_SERVICES];
180a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_service_pool;
181a3b02b71Smatthias.ringwald void * btstack_memory_rfcomm_service_get(void){
182a3b02b71Smatthias.ringwald     return memory_pool_get(&rfcomm_service_pool);
183a3b02b71Smatthias.ringwald }
184a3b02b71Smatthias.ringwald void btstack_memory_rfcomm_service_free(void *rfcomm_service){
185a3b02b71Smatthias.ringwald     memory_pool_free(&rfcomm_service_pool, rfcomm_service);
186a3b02b71Smatthias.ringwald }
187c4d3f927Smatthias.ringwald #else
188c4d3f927Smatthias.ringwald void * btstack_memory_rfcomm_service_get(void){
189c4d3f927Smatthias.ringwald     return NULL;
190c4d3f927Smatthias.ringwald }
191c4d3f927Smatthias.ringwald void btstack_memory_rfcomm_service_free(void *rfcomm_service){
192c4d3f927Smatthias.ringwald };
193c4d3f927Smatthias.ringwald #endif
194a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
195a3b02b71Smatthias.ringwald void * btstack_memory_rfcomm_service_get(void){
196a3b02b71Smatthias.ringwald     return malloc(sizeof(rfcomm_service_t));
197a3b02b71Smatthias.ringwald }
198a3b02b71Smatthias.ringwald void  btstack_memory_rfcomm_service_free(void *rfcomm_service){
199a3b02b71Smatthias.ringwald     free(rfcomm_service);
200a3b02b71Smatthias.ringwald }
201*e045abdeSmatthias.ringwald #else
202*e045abdeSmatthias.ringwald #error "The struct rfcomm_service has neither HAVE_MALLOC nor MAX_NO_RFCOMM_SERVICES defined. Please, edit the config file."
203a3b02b71Smatthias.ringwald #endif
204a3b02b71Smatthias.ringwald 
205a3b02b71Smatthias.ringwald 
206a3b02b71Smatthias.ringwald // MARK: rfcomm_channel_t
207a3b02b71Smatthias.ringwald #ifdef MAX_NO_RFCOMM_CHANNELS
208c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_CHANNELS > 0
209a3b02b71Smatthias.ringwald static rfcomm_channel_t rfcomm_channel_storage[MAX_NO_RFCOMM_CHANNELS];
210a3b02b71Smatthias.ringwald static memory_pool_t rfcomm_channel_pool;
211a3b02b71Smatthias.ringwald void * btstack_memory_rfcomm_channel_get(void){
212a3b02b71Smatthias.ringwald     return memory_pool_get(&rfcomm_channel_pool);
213a3b02b71Smatthias.ringwald }
214a3b02b71Smatthias.ringwald void btstack_memory_rfcomm_channel_free(void *rfcomm_channel){
215a3b02b71Smatthias.ringwald     memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
216a3b02b71Smatthias.ringwald }
217c4d3f927Smatthias.ringwald #else
218c4d3f927Smatthias.ringwald void * btstack_memory_rfcomm_channel_get(void){
219c4d3f927Smatthias.ringwald     return NULL;
220c4d3f927Smatthias.ringwald }
221c4d3f927Smatthias.ringwald void btstack_memory_rfcomm_channel_free(void *rfcomm_channel){
222c4d3f927Smatthias.ringwald };
223c4d3f927Smatthias.ringwald #endif
224a3b02b71Smatthias.ringwald #elif defined(HAVE_MALLOC)
225a3b02b71Smatthias.ringwald void * btstack_memory_rfcomm_channel_get(void){
226a3b02b71Smatthias.ringwald     return malloc(sizeof(rfcomm_channel_t));
227a3b02b71Smatthias.ringwald }
228a3b02b71Smatthias.ringwald void  btstack_memory_rfcomm_channel_free(void *rfcomm_channel){
229a3b02b71Smatthias.ringwald     free(rfcomm_channel);
230a3b02b71Smatthias.ringwald }
231*e045abdeSmatthias.ringwald #else
232*e045abdeSmatthias.ringwald #error "The struct rfcomm_channel has neither HAVE_MALLOC nor MAX_NO_RFCOMM_CHANNELS defined. Please, edit the config file."
233a3b02b71Smatthias.ringwald #endif
234a3b02b71Smatthias.ringwald 
235e0e5e285Smatthias.ringwald 
236e0e5e285Smatthias.ringwald // MARK: db_mem_device_name_t
237e0e5e285Smatthias.ringwald #ifdef MAX_NO_DB_MEM_DEVICE_NAMES
238c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_NAMES > 0
239e0e5e285Smatthias.ringwald static db_mem_device_name_t db_mem_device_name_storage[MAX_NO_DB_MEM_DEVICE_NAMES];
240e0e5e285Smatthias.ringwald static memory_pool_t db_mem_device_name_pool;
241e0e5e285Smatthias.ringwald void * btstack_memory_db_mem_device_name_get(void){
242e0e5e285Smatthias.ringwald     return memory_pool_get(&db_mem_device_name_pool);
2431801b596Smatthias.ringwald }
244e0e5e285Smatthias.ringwald void btstack_memory_db_mem_device_name_free(void *db_mem_device_name){
245e0e5e285Smatthias.ringwald     memory_pool_free(&db_mem_device_name_pool, db_mem_device_name);
2461801b596Smatthias.ringwald }
247c4d3f927Smatthias.ringwald #else
248c4d3f927Smatthias.ringwald void * btstack_memory_db_mem_device_name_get(void){
249c4d3f927Smatthias.ringwald     return NULL;
250c4d3f927Smatthias.ringwald }
251c4d3f927Smatthias.ringwald void btstack_memory_db_mem_device_name_free(void *db_mem_device_name){
252c4d3f927Smatthias.ringwald };
253c4d3f927Smatthias.ringwald #endif
2541801b596Smatthias.ringwald #elif defined(HAVE_MALLOC)
255e0e5e285Smatthias.ringwald void * btstack_memory_db_mem_device_name_get(void){
256e0e5e285Smatthias.ringwald     return malloc(sizeof(db_mem_device_name_t));
2571801b596Smatthias.ringwald }
258e0e5e285Smatthias.ringwald void  btstack_memory_db_mem_device_name_free(void *db_mem_device_name){
259e0e5e285Smatthias.ringwald     free(db_mem_device_name);
260e0e5e285Smatthias.ringwald }
261*e045abdeSmatthias.ringwald #else
262*e045abdeSmatthias.ringwald #error "The struct db_mem_device_name has neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_NAMES defined. Please, edit the config file."
263e0e5e285Smatthias.ringwald #endif
264e0e5e285Smatthias.ringwald 
265e0e5e285Smatthias.ringwald 
266e0e5e285Smatthias.ringwald // MARK: db_mem_device_link_key_t
267e0e5e285Smatthias.ringwald #ifdef MAX_NO_DB_MEM_DEVICE_LINK_KEYS
268c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0
269e0e5e285Smatthias.ringwald static db_mem_device_link_key_t db_mem_device_link_key_storage[MAX_NO_DB_MEM_DEVICE_LINK_KEYS];
270e0e5e285Smatthias.ringwald static memory_pool_t db_mem_device_link_key_pool;
271e0e5e285Smatthias.ringwald void * btstack_memory_db_mem_device_link_key_get(void){
272e0e5e285Smatthias.ringwald     return memory_pool_get(&db_mem_device_link_key_pool);
273e0e5e285Smatthias.ringwald }
274e0e5e285Smatthias.ringwald void btstack_memory_db_mem_device_link_key_free(void *db_mem_device_link_key){
275e0e5e285Smatthias.ringwald     memory_pool_free(&db_mem_device_link_key_pool, db_mem_device_link_key);
276e0e5e285Smatthias.ringwald }
277c4d3f927Smatthias.ringwald #else
278c4d3f927Smatthias.ringwald void * btstack_memory_db_mem_device_link_key_get(void){
279c4d3f927Smatthias.ringwald     return NULL;
280c4d3f927Smatthias.ringwald }
281c4d3f927Smatthias.ringwald void btstack_memory_db_mem_device_link_key_free(void *db_mem_device_link_key){
282c4d3f927Smatthias.ringwald };
283c4d3f927Smatthias.ringwald #endif
284e0e5e285Smatthias.ringwald #elif defined(HAVE_MALLOC)
285e0e5e285Smatthias.ringwald void * btstack_memory_db_mem_device_link_key_get(void){
286e0e5e285Smatthias.ringwald     return malloc(sizeof(db_mem_device_link_key_t));
287e0e5e285Smatthias.ringwald }
288e0e5e285Smatthias.ringwald void  btstack_memory_db_mem_device_link_key_free(void *db_mem_device_link_key){
289e0e5e285Smatthias.ringwald     free(db_mem_device_link_key);
2901801b596Smatthias.ringwald }
291*e045abdeSmatthias.ringwald #else
292*e045abdeSmatthias.ringwald #error "The struct db_mem_device_link_key has neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_LINK_KEYS defined. Please, edit the config file."
2931801b596Smatthias.ringwald #endif
2941801b596Smatthias.ringwald 
2951801b596Smatthias.ringwald 
2961801b596Smatthias.ringwald // MARK: db_mem_service_t
2971801b596Smatthias.ringwald #ifdef MAX_NO_DB_MEM_SERVICES
298c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_SERVICES > 0
2991801b596Smatthias.ringwald static db_mem_service_t db_mem_service_storage[MAX_NO_DB_MEM_SERVICES];
3001801b596Smatthias.ringwald static memory_pool_t db_mem_service_pool;
3011801b596Smatthias.ringwald void * btstack_memory_db_mem_service_get(void){
3021801b596Smatthias.ringwald     return memory_pool_get(&db_mem_service_pool);
3031801b596Smatthias.ringwald }
3041801b596Smatthias.ringwald void btstack_memory_db_mem_service_free(void *db_mem_service){
3051801b596Smatthias.ringwald     memory_pool_free(&db_mem_service_pool, db_mem_service);
3061801b596Smatthias.ringwald }
307c4d3f927Smatthias.ringwald #else
308c4d3f927Smatthias.ringwald void * btstack_memory_db_mem_service_get(void){
309c4d3f927Smatthias.ringwald     return NULL;
310c4d3f927Smatthias.ringwald }
311c4d3f927Smatthias.ringwald void btstack_memory_db_mem_service_free(void *db_mem_service){
312c4d3f927Smatthias.ringwald };
313c4d3f927Smatthias.ringwald #endif
3141801b596Smatthias.ringwald #elif defined(HAVE_MALLOC)
3151801b596Smatthias.ringwald void * btstack_memory_db_mem_service_get(void){
3161801b596Smatthias.ringwald     return malloc(sizeof(db_mem_service_t));
3171801b596Smatthias.ringwald }
3181801b596Smatthias.ringwald void  btstack_memory_db_mem_service_free(void *db_mem_service){
3191801b596Smatthias.ringwald     free(db_mem_service);
3201801b596Smatthias.ringwald }
321*e045abdeSmatthias.ringwald #else
322*e045abdeSmatthias.ringwald #error "The struct db_mem_service has neither HAVE_MALLOC nor MAX_NO_DB_MEM_SERVICES defined. Please, edit the config file."
3231801b596Smatthias.ringwald #endif
3241801b596Smatthias.ringwald 
325a3b02b71Smatthias.ringwald // init
326a3b02b71Smatthias.ringwald void btstack_memory_init(void){
327c4d3f927Smatthias.ringwald #if MAX_NO_HCI_CONNECTIONS > 0
328a3b02b71Smatthias.ringwald     memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t));
329a3b02b71Smatthias.ringwald #endif
330c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_SERVICES > 0
331a3b02b71Smatthias.ringwald     memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t));
332a3b02b71Smatthias.ringwald #endif
333c4d3f927Smatthias.ringwald #if MAX_NO_L2CAP_CHANNELS > 0
334a3b02b71Smatthias.ringwald     memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
335a3b02b71Smatthias.ringwald #endif
336c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_MULTIPLEXERS > 0
337a3b02b71Smatthias.ringwald     memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
338a3b02b71Smatthias.ringwald #endif
339c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_SERVICES > 0
340a3b02b71Smatthias.ringwald     memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
341a3b02b71Smatthias.ringwald #endif
342c4d3f927Smatthias.ringwald #if MAX_NO_RFCOMM_CHANNELS > 0
343a3b02b71Smatthias.ringwald     memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
344a3b02b71Smatthias.ringwald #endif
345c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_NAMES > 0
346e0e5e285Smatthias.ringwald     memory_pool_create(&db_mem_device_name_pool, db_mem_device_name_storage, MAX_NO_DB_MEM_DEVICE_NAMES, sizeof(db_mem_device_name_t));
347e0e5e285Smatthias.ringwald #endif
348c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0
349e0e5e285Smatthias.ringwald     memory_pool_create(&db_mem_device_link_key_pool, db_mem_device_link_key_storage, MAX_NO_DB_MEM_DEVICE_LINK_KEYS, sizeof(db_mem_device_link_key_t));
3501801b596Smatthias.ringwald #endif
351c4d3f927Smatthias.ringwald #if MAX_NO_DB_MEM_SERVICES > 0
3521801b596Smatthias.ringwald     memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t));
3531801b596Smatthias.ringwald #endif
354a3b02b71Smatthias.ringwald }
355*e045abdeSmatthias.ringwald 
356