1 |
|
---|
2 | /*
|
---|
3 | * Copyright (C) 2009 by BlueKitchen GmbH
|
---|
4 | *
|
---|
5 | * Redistribution and use in source and binary forms, with or without
|
---|
6 | * modification, are permitted provided that the following conditions
|
---|
7 | * are met:
|
---|
8 | *
|
---|
9 | * 1. Redistributions of source code must retain the above copyright
|
---|
10 | * notice, this list of conditions and the following disclaimer.
|
---|
11 | * 2. Redistributions in binary form must reproduce the above copyright
|
---|
12 | * notice, this list of conditions and the following disclaimer in the
|
---|
13 | * documentation and/or other materials provided with the distribution.
|
---|
14 | * 3. Neither the name of the copyright holders nor the names of
|
---|
15 | * contributors may be used to endorse or promote products derived
|
---|
16 | * from this software without specific prior written permission.
|
---|
17 | * 4. Any redistribution, use, or modification is done solely for
|
---|
18 | * personal benefit and not for any commercial purpose or for
|
---|
19 | * monetary gain.
|
---|
20 | *
|
---|
21 | * THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
|
---|
22 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
23 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
---|
24 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
|
---|
25 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
26 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
---|
27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
---|
28 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
---|
29 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
---|
30 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
|
---|
31 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
---|
32 | * SUCH DAMAGE.
|
---|
33 | *
|
---|
34 | * Please inquire about commercial licensing options at
|
---|
35 | * contact@bluekitchen-gmbh.com
|
---|
36 | *
|
---|
37 | */
|
---|
38 |
|
---|
39 |
|
---|
40 | /*
|
---|
41 | * btstsack_memory.h
|
---|
42 | *
|
---|
43 | * @brief BTstack memory management via configurable memory pools
|
---|
44 | *
|
---|
45 | * @note code semi-atuomatically generated by tools/btstack_memory_generator.py
|
---|
46 | *
|
---|
47 | */
|
---|
48 |
|
---|
49 | #include "btstack_memory.h"
|
---|
50 | #include <btstack/memory_pool.h>
|
---|
51 |
|
---|
52 | #include <stdlib.h>
|
---|
53 |
|
---|
54 | #include "btstack-config.h"
|
---|
55 | #include "hci.h"
|
---|
56 | #include "l2cap.h"
|
---|
57 | #include "rfcomm.h"
|
---|
58 |
|
---|
59 |
|
---|
60 | // MARK: hci_connection_t
|
---|
61 | #ifdef MAX_NO_HCI_CONNECTIONS
|
---|
62 | #if MAX_NO_HCI_CONNECTIONS > 0
|
---|
63 | static hci_connection_t hci_connection_storage[MAX_NO_HCI_CONNECTIONS];
|
---|
64 | static memory_pool_t hci_connection_pool;
|
---|
65 | hci_connection_t * btstack_memory_hci_connection_get(void){
|
---|
66 | return (hci_connection_t *) memory_pool_get(&hci_connection_pool);
|
---|
67 | }
|
---|
68 | void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
|
---|
69 | memory_pool_free(&hci_connection_pool, hci_connection);
|
---|
70 | }
|
---|
71 | #else
|
---|
72 | hci_connection_t * btstack_memory_hci_connection_get(void){
|
---|
73 | return NULL;
|
---|
74 | }
|
---|
75 | void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
|
---|
76 | // silence compiler warning about unused parameter in a portable way
|
---|
77 | (void) hci_connection;
|
---|
78 | };
|
---|
79 | #endif
|
---|
80 | #elif defined(HAVE_MALLOC)
|
---|
81 | hci_connection_t * btstack_memory_hci_connection_get(void){
|
---|
82 | return (hci_connection_t*) malloc(sizeof(hci_connection_t));
|
---|
83 | }
|
---|
84 | void btstack_memory_hci_connection_free(hci_connection_t *hci_connection){
|
---|
85 | free(hci_connection);
|
---|
86 | }
|
---|
87 | #else
|
---|
88 | #error "Neither HAVE_MALLOC nor MAX_NO_HCI_CONNECTIONS for struct hci_connection is defined. Please, edit the config file."
|
---|
89 | #endif
|
---|
90 |
|
---|
91 |
|
---|
92 |
|
---|
93 | // MARK: l2cap_service_t
|
---|
94 | #ifdef MAX_NO_L2CAP_SERVICES
|
---|
95 | #if MAX_NO_L2CAP_SERVICES > 0
|
---|
96 | static l2cap_service_t l2cap_service_storage[MAX_NO_L2CAP_SERVICES];
|
---|
97 | static memory_pool_t l2cap_service_pool;
|
---|
98 | l2cap_service_t * btstack_memory_l2cap_service_get(void){
|
---|
99 | return (l2cap_service_t *) memory_pool_get(&l2cap_service_pool);
|
---|
100 | }
|
---|
101 | void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
|
---|
102 | memory_pool_free(&l2cap_service_pool, l2cap_service);
|
---|
103 | }
|
---|
104 | #else
|
---|
105 | l2cap_service_t * btstack_memory_l2cap_service_get(void){
|
---|
106 | return NULL;
|
---|
107 | }
|
---|
108 | void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
|
---|
109 | // silence compiler warning about unused parameter in a portable way
|
---|
110 | (void) l2cap_service;
|
---|
111 | };
|
---|
112 | #endif
|
---|
113 | #elif defined(HAVE_MALLOC)
|
---|
114 | l2cap_service_t * btstack_memory_l2cap_service_get(void){
|
---|
115 | return (l2cap_service_t*) malloc(sizeof(l2cap_service_t));
|
---|
116 | }
|
---|
117 | void btstack_memory_l2cap_service_free(l2cap_service_t *l2cap_service){
|
---|
118 | free(l2cap_service);
|
---|
119 | }
|
---|
120 | #else
|
---|
121 | #error "Neither HAVE_MALLOC nor MAX_NO_L2CAP_SERVICES for struct l2cap_service is defined. Please, edit the config file."
|
---|
122 | #endif
|
---|
123 |
|
---|
124 |
|
---|
125 | // MARK: l2cap_channel_t
|
---|
126 | #ifdef MAX_NO_L2CAP_CHANNELS
|
---|
127 | #if MAX_NO_L2CAP_CHANNELS > 0
|
---|
128 | static l2cap_channel_t l2cap_channel_storage[MAX_NO_L2CAP_CHANNELS];
|
---|
129 | static memory_pool_t l2cap_channel_pool;
|
---|
130 | l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
|
---|
131 | return (l2cap_channel_t *) memory_pool_get(&l2cap_channel_pool);
|
---|
132 | }
|
---|
133 | void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
|
---|
134 | memory_pool_free(&l2cap_channel_pool, l2cap_channel);
|
---|
135 | }
|
---|
136 | #else
|
---|
137 | l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
|
---|
138 | return NULL;
|
---|
139 | }
|
---|
140 | void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
|
---|
141 | // silence compiler warning about unused parameter in a portable way
|
---|
142 | (void) l2cap_channel;
|
---|
143 | };
|
---|
144 | #endif
|
---|
145 | #elif defined(HAVE_MALLOC)
|
---|
146 | l2cap_channel_t * btstack_memory_l2cap_channel_get(void){
|
---|
147 | return (l2cap_channel_t*) malloc(sizeof(l2cap_channel_t));
|
---|
148 | }
|
---|
149 | void btstack_memory_l2cap_channel_free(l2cap_channel_t *l2cap_channel){
|
---|
150 | free(l2cap_channel);
|
---|
151 | }
|
---|
152 | #else
|
---|
153 | #error "Neither HAVE_MALLOC nor MAX_NO_L2CAP_CHANNELS for struct l2cap_channel is defined. Please, edit the config file."
|
---|
154 | #endif
|
---|
155 |
|
---|
156 |
|
---|
157 |
|
---|
158 | // MARK: rfcomm_multiplexer_t
|
---|
159 | #ifdef MAX_NO_RFCOMM_MULTIPLEXERS
|
---|
160 | #if MAX_NO_RFCOMM_MULTIPLEXERS > 0
|
---|
161 | static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NO_RFCOMM_MULTIPLEXERS];
|
---|
162 | static memory_pool_t rfcomm_multiplexer_pool;
|
---|
163 | rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
|
---|
164 | return (rfcomm_multiplexer_t *) memory_pool_get(&rfcomm_multiplexer_pool);
|
---|
165 | }
|
---|
166 | void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
|
---|
167 | memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer);
|
---|
168 | }
|
---|
169 | #else
|
---|
170 | rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
|
---|
171 | return NULL;
|
---|
172 | }
|
---|
173 | void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
|
---|
174 | // silence compiler warning about unused parameter in a portable way
|
---|
175 | (void) rfcomm_multiplexer;
|
---|
176 | };
|
---|
177 | #endif
|
---|
178 | #elif defined(HAVE_MALLOC)
|
---|
179 | rfcomm_multiplexer_t * btstack_memory_rfcomm_multiplexer_get(void){
|
---|
180 | return (rfcomm_multiplexer_t*) malloc(sizeof(rfcomm_multiplexer_t));
|
---|
181 | }
|
---|
182 | void btstack_memory_rfcomm_multiplexer_free(rfcomm_multiplexer_t *rfcomm_multiplexer){
|
---|
183 | free(rfcomm_multiplexer);
|
---|
184 | }
|
---|
185 | #else
|
---|
186 | #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_MULTIPLEXERS for struct rfcomm_multiplexer is defined. Please, edit the config file."
|
---|
187 | #endif
|
---|
188 |
|
---|
189 |
|
---|
190 | // MARK: rfcomm_service_t
|
---|
191 | #ifdef MAX_NO_RFCOMM_SERVICES
|
---|
192 | #if MAX_NO_RFCOMM_SERVICES > 0
|
---|
193 | static rfcomm_service_t rfcomm_service_storage[MAX_NO_RFCOMM_SERVICES];
|
---|
194 | static memory_pool_t rfcomm_service_pool;
|
---|
195 | rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
|
---|
196 | return (rfcomm_service_t *) memory_pool_get(&rfcomm_service_pool);
|
---|
197 | }
|
---|
198 | void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
|
---|
199 | memory_pool_free(&rfcomm_service_pool, rfcomm_service);
|
---|
200 | }
|
---|
201 | #else
|
---|
202 | rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
|
---|
203 | return NULL;
|
---|
204 | }
|
---|
205 | void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
|
---|
206 | // silence compiler warning about unused parameter in a portable way
|
---|
207 | (void) rfcomm_service;
|
---|
208 | };
|
---|
209 | #endif
|
---|
210 | #elif defined(HAVE_MALLOC)
|
---|
211 | rfcomm_service_t * btstack_memory_rfcomm_service_get(void){
|
---|
212 | return (rfcomm_service_t*) malloc(sizeof(rfcomm_service_t));
|
---|
213 | }
|
---|
214 | void btstack_memory_rfcomm_service_free(rfcomm_service_t *rfcomm_service){
|
---|
215 | free(rfcomm_service);
|
---|
216 | }
|
---|
217 | #else
|
---|
218 | #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_SERVICES for struct rfcomm_service is defined. Please, edit the config file."
|
---|
219 | #endif
|
---|
220 |
|
---|
221 |
|
---|
222 | // MARK: rfcomm_channel_t
|
---|
223 | #ifdef MAX_NO_RFCOMM_CHANNELS
|
---|
224 | #if MAX_NO_RFCOMM_CHANNELS > 0
|
---|
225 | static rfcomm_channel_t rfcomm_channel_storage[MAX_NO_RFCOMM_CHANNELS];
|
---|
226 | static memory_pool_t rfcomm_channel_pool;
|
---|
227 | rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
|
---|
228 | return (rfcomm_channel_t *) memory_pool_get(&rfcomm_channel_pool);
|
---|
229 | }
|
---|
230 | void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
|
---|
231 | memory_pool_free(&rfcomm_channel_pool, rfcomm_channel);
|
---|
232 | }
|
---|
233 | #else
|
---|
234 | rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
|
---|
235 | return NULL;
|
---|
236 | }
|
---|
237 | void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
|
---|
238 | // silence compiler warning about unused parameter in a portable way
|
---|
239 | (void) rfcomm_channel;
|
---|
240 | };
|
---|
241 | #endif
|
---|
242 | #elif defined(HAVE_MALLOC)
|
---|
243 | rfcomm_channel_t * btstack_memory_rfcomm_channel_get(void){
|
---|
244 | return (rfcomm_channel_t*) malloc(sizeof(rfcomm_channel_t));
|
---|
245 | }
|
---|
246 | void btstack_memory_rfcomm_channel_free(rfcomm_channel_t *rfcomm_channel){
|
---|
247 | free(rfcomm_channel);
|
---|
248 | }
|
---|
249 | #else
|
---|
250 | #error "Neither HAVE_MALLOC nor MAX_NO_RFCOMM_CHANNELS for struct rfcomm_channel is defined. Please, edit the config file."
|
---|
251 | #endif
|
---|
252 |
|
---|
253 |
|
---|
254 |
|
---|
255 | // MARK: db_mem_device_name_t
|
---|
256 | #ifdef MAX_NO_DB_MEM_DEVICE_NAMES
|
---|
257 | #if MAX_NO_DB_MEM_DEVICE_NAMES > 0
|
---|
258 | static db_mem_device_name_t db_mem_device_name_storage[MAX_NO_DB_MEM_DEVICE_NAMES];
|
---|
259 | static memory_pool_t db_mem_device_name_pool;
|
---|
260 | db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){
|
---|
261 | return (db_mem_device_name_t *) memory_pool_get(&db_mem_device_name_pool);
|
---|
262 | }
|
---|
263 | void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){
|
---|
264 | memory_pool_free(&db_mem_device_name_pool, db_mem_device_name);
|
---|
265 | }
|
---|
266 | #else
|
---|
267 | db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){
|
---|
268 | return NULL;
|
---|
269 | }
|
---|
270 | void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){
|
---|
271 | // silence compiler warning about unused parameter in a portable way
|
---|
272 | (void) db_mem_device_name;
|
---|
273 | };
|
---|
274 | #endif
|
---|
275 | #elif defined(HAVE_MALLOC)
|
---|
276 | db_mem_device_name_t * btstack_memory_db_mem_device_name_get(void){
|
---|
277 | return (db_mem_device_name_t*) malloc(sizeof(db_mem_device_name_t));
|
---|
278 | }
|
---|
279 | void btstack_memory_db_mem_device_name_free(db_mem_device_name_t *db_mem_device_name){
|
---|
280 | free(db_mem_device_name);
|
---|
281 | }
|
---|
282 | #else
|
---|
283 | #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_NAMES for struct db_mem_device_name is defined. Please, edit the config file."
|
---|
284 | #endif
|
---|
285 |
|
---|
286 |
|
---|
287 | // MARK: db_mem_device_link_key_t
|
---|
288 | #ifdef MAX_NO_DB_MEM_DEVICE_LINK_KEYS
|
---|
289 | #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0
|
---|
290 | static db_mem_device_link_key_t db_mem_device_link_key_storage[MAX_NO_DB_MEM_DEVICE_LINK_KEYS];
|
---|
291 | static memory_pool_t db_mem_device_link_key_pool;
|
---|
292 | db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){
|
---|
293 | return (db_mem_device_link_key_t *) memory_pool_get(&db_mem_device_link_key_pool);
|
---|
294 | }
|
---|
295 | void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){
|
---|
296 | memory_pool_free(&db_mem_device_link_key_pool, db_mem_device_link_key);
|
---|
297 | }
|
---|
298 | #else
|
---|
299 | db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){
|
---|
300 | return NULL;
|
---|
301 | }
|
---|
302 | void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){
|
---|
303 | // silence compiler warning about unused parameter in a portable way
|
---|
304 | (void) db_mem_device_link_key;
|
---|
305 | };
|
---|
306 | #endif
|
---|
307 | #elif defined(HAVE_MALLOC)
|
---|
308 | db_mem_device_link_key_t * btstack_memory_db_mem_device_link_key_get(void){
|
---|
309 | return (db_mem_device_link_key_t*) malloc(sizeof(db_mem_device_link_key_t));
|
---|
310 | }
|
---|
311 | void btstack_memory_db_mem_device_link_key_free(db_mem_device_link_key_t *db_mem_device_link_key){
|
---|
312 | free(db_mem_device_link_key);
|
---|
313 | }
|
---|
314 | #else
|
---|
315 | #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_DEVICE_LINK_KEYS for struct db_mem_device_link_key is defined. Please, edit the config file."
|
---|
316 | #endif
|
---|
317 |
|
---|
318 |
|
---|
319 | // MARK: db_mem_service_t
|
---|
320 | #ifdef MAX_NO_DB_MEM_SERVICES
|
---|
321 | #if MAX_NO_DB_MEM_SERVICES > 0
|
---|
322 | static db_mem_service_t db_mem_service_storage[MAX_NO_DB_MEM_SERVICES];
|
---|
323 | static memory_pool_t db_mem_service_pool;
|
---|
324 | db_mem_service_t * btstack_memory_db_mem_service_get(void){
|
---|
325 | return (db_mem_service_t *) memory_pool_get(&db_mem_service_pool);
|
---|
326 | }
|
---|
327 | void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){
|
---|
328 | memory_pool_free(&db_mem_service_pool, db_mem_service);
|
---|
329 | }
|
---|
330 | #else
|
---|
331 | db_mem_service_t * btstack_memory_db_mem_service_get(void){
|
---|
332 | return NULL;
|
---|
333 | }
|
---|
334 | void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){
|
---|
335 | // silence compiler warning about unused parameter in a portable way
|
---|
336 | (void) db_mem_service;
|
---|
337 | };
|
---|
338 | #endif
|
---|
339 | #elif defined(HAVE_MALLOC)
|
---|
340 | db_mem_service_t * btstack_memory_db_mem_service_get(void){
|
---|
341 | return (db_mem_service_t*) malloc(sizeof(db_mem_service_t));
|
---|
342 | }
|
---|
343 | void btstack_memory_db_mem_service_free(db_mem_service_t *db_mem_service){
|
---|
344 | free(db_mem_service);
|
---|
345 | }
|
---|
346 | #else
|
---|
347 | #error "Neither HAVE_MALLOC nor MAX_NO_DB_MEM_SERVICES for struct db_mem_service is defined. Please, edit the config file."
|
---|
348 | #endif
|
---|
349 |
|
---|
350 |
|
---|
351 |
|
---|
352 | // MARK: bnep_service_t
|
---|
353 | #ifdef MAX_NO_BNEP_SERVICES
|
---|
354 | #if MAX_NO_BNEP_SERVICES > 0
|
---|
355 | static bnep_service_t bnep_service_storage[MAX_NO_BNEP_SERVICES];
|
---|
356 | static memory_pool_t bnep_service_pool;
|
---|
357 | bnep_service_t * btstack_memory_bnep_service_get(void){
|
---|
358 | return (bnep_service_t *) memory_pool_get(&bnep_service_pool);
|
---|
359 | }
|
---|
360 | void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
|
---|
361 | memory_pool_free(&bnep_service_pool, bnep_service);
|
---|
362 | }
|
---|
363 | #else
|
---|
364 | bnep_service_t * btstack_memory_bnep_service_get(void){
|
---|
365 | return NULL;
|
---|
366 | }
|
---|
367 | void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
|
---|
368 | // silence compiler warning about unused parameter in a portable way
|
---|
369 | (void) bnep_service;
|
---|
370 | };
|
---|
371 | #endif
|
---|
372 | #elif defined(HAVE_MALLOC)
|
---|
373 | bnep_service_t * btstack_memory_bnep_service_get(void){
|
---|
374 | return (bnep_service_t*) malloc(sizeof(bnep_service_t));
|
---|
375 | }
|
---|
376 | void btstack_memory_bnep_service_free(bnep_service_t *bnep_service){
|
---|
377 | free(bnep_service);
|
---|
378 | }
|
---|
379 | #else
|
---|
380 | #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_SERVICES for struct bnep_service is defined. Please, edit the config file."
|
---|
381 | #endif
|
---|
382 |
|
---|
383 |
|
---|
384 | // MARK: bnep_channel_t
|
---|
385 | #ifdef MAX_NO_BNEP_CHANNELS
|
---|
386 | #if MAX_NO_BNEP_CHANNELS > 0
|
---|
387 | static bnep_channel_t bnep_channel_storage[MAX_NO_BNEP_CHANNELS];
|
---|
388 | static memory_pool_t bnep_channel_pool;
|
---|
389 | bnep_channel_t * btstack_memory_bnep_channel_get(void){
|
---|
390 | return (bnep_channel_t *) memory_pool_get(&bnep_channel_pool);
|
---|
391 | }
|
---|
392 | void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
|
---|
393 | memory_pool_free(&bnep_channel_pool, bnep_channel);
|
---|
394 | }
|
---|
395 | #else
|
---|
396 | bnep_channel_t * btstack_memory_bnep_channel_get(void){
|
---|
397 | return NULL;
|
---|
398 | }
|
---|
399 | void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
|
---|
400 | // silence compiler warning about unused parameter in a portable way
|
---|
401 | (void) bnep_channel;
|
---|
402 | };
|
---|
403 | #endif
|
---|
404 | #elif defined(HAVE_MALLOC)
|
---|
405 | bnep_channel_t * btstack_memory_bnep_channel_get(void){
|
---|
406 | return (bnep_channel_t*) malloc(sizeof(bnep_channel_t));
|
---|
407 | }
|
---|
408 | void btstack_memory_bnep_channel_free(bnep_channel_t *bnep_channel){
|
---|
409 | free(bnep_channel);
|
---|
410 | }
|
---|
411 | #else
|
---|
412 | #error "Neither HAVE_MALLOC nor MAX_NO_BNEP_CHANNELS for struct bnep_channel is defined. Please, edit the config file."
|
---|
413 | #endif
|
---|
414 |
|
---|
415 |
|
---|
416 | #ifdef HAVE_BLE
|
---|
417 |
|
---|
418 | // MARK: gatt_client_t
|
---|
419 | #ifdef MAX_NO_GATT_CLIENTS
|
---|
420 | #if MAX_NO_GATT_CLIENTS > 0
|
---|
421 | static gatt_client_t gatt_client_storage[MAX_NO_GATT_CLIENTS];
|
---|
422 | static memory_pool_t gatt_client_pool;
|
---|
423 | gatt_client_t * btstack_memory_gatt_client_get(void){
|
---|
424 | return (gatt_client_t *) memory_pool_get(&gatt_client_pool);
|
---|
425 | }
|
---|
426 | void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
|
---|
427 | memory_pool_free(&gatt_client_pool, gatt_client);
|
---|
428 | }
|
---|
429 | #else
|
---|
430 | gatt_client_t * btstack_memory_gatt_client_get(void){
|
---|
431 | return NULL;
|
---|
432 | }
|
---|
433 | void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
|
---|
434 | // silence compiler warning about unused parameter in a portable way
|
---|
435 | (void) gatt_client;
|
---|
436 | };
|
---|
437 | #endif
|
---|
438 | #elif defined(HAVE_MALLOC)
|
---|
439 | gatt_client_t * btstack_memory_gatt_client_get(void){
|
---|
440 | return (gatt_client_t*) malloc(sizeof(gatt_client_t));
|
---|
441 | }
|
---|
442 | void btstack_memory_gatt_client_free(gatt_client_t *gatt_client){
|
---|
443 | free(gatt_client);
|
---|
444 | }
|
---|
445 | #else
|
---|
446 | #error "Neither HAVE_MALLOC nor MAX_NO_GATT_CLIENTS for struct gatt_client is defined. Please, edit the config file."
|
---|
447 | #endif
|
---|
448 |
|
---|
449 |
|
---|
450 | // MARK: gatt_subclient_t
|
---|
451 | #ifdef MAX_NO_GATT_SUBCLIENTS
|
---|
452 | #if MAX_NO_GATT_SUBCLIENTS > 0
|
---|
453 | static gatt_subclient_t gatt_subclient_storage[MAX_NO_GATT_SUBCLIENTS];
|
---|
454 | static memory_pool_t gatt_subclient_pool;
|
---|
455 | gatt_subclient_t * btstack_memory_gatt_subclient_get(void){
|
---|
456 | return (gatt_subclient_t *) memory_pool_get(&gatt_subclient_pool);
|
---|
457 | }
|
---|
458 | void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){
|
---|
459 | memory_pool_free(&gatt_subclient_pool, gatt_subclient);
|
---|
460 | }
|
---|
461 | #else
|
---|
462 | gatt_subclient_t * btstack_memory_gatt_subclient_get(void){
|
---|
463 | return NULL;
|
---|
464 | }
|
---|
465 | void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){
|
---|
466 | // silence compiler warning about unused parameter in a portable way
|
---|
467 | (void) gatt_subclient;
|
---|
468 | };
|
---|
469 | #endif
|
---|
470 | #elif defined(HAVE_MALLOC)
|
---|
471 | gatt_subclient_t * btstack_memory_gatt_subclient_get(void){
|
---|
472 | return (gatt_subclient_t*) malloc(sizeof(gatt_subclient_t));
|
---|
473 | }
|
---|
474 | void btstack_memory_gatt_subclient_free(gatt_subclient_t *gatt_subclient){
|
---|
475 | free(gatt_subclient);
|
---|
476 | }
|
---|
477 | #else
|
---|
478 | #error "Neither HAVE_MALLOC nor MAX_NO_GATT_SUBCLIENTS for struct gatt_subclient is defined. Please, edit the config file."
|
---|
479 | #endif
|
---|
480 |
|
---|
481 |
|
---|
482 | #endif
|
---|
483 | // init
|
---|
484 | void btstack_memory_init(void){
|
---|
485 | #if MAX_NO_HCI_CONNECTIONS > 0
|
---|
486 | memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t));
|
---|
487 | #endif
|
---|
488 | #if MAX_NO_L2CAP_SERVICES > 0
|
---|
489 | memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t));
|
---|
490 | #endif
|
---|
491 | #if MAX_NO_L2CAP_CHANNELS > 0
|
---|
492 | memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t));
|
---|
493 | #endif
|
---|
494 | #if MAX_NO_RFCOMM_MULTIPLEXERS > 0
|
---|
495 | memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t));
|
---|
496 | #endif
|
---|
497 | #if MAX_NO_RFCOMM_SERVICES > 0
|
---|
498 | memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t));
|
---|
499 | #endif
|
---|
500 | #if MAX_NO_RFCOMM_CHANNELS > 0
|
---|
501 | memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t));
|
---|
502 | #endif
|
---|
503 | #if MAX_NO_DB_MEM_DEVICE_NAMES > 0
|
---|
504 | 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));
|
---|
505 | #endif
|
---|
506 | #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0
|
---|
507 | 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));
|
---|
508 | #endif
|
---|
509 | #if MAX_NO_DB_MEM_SERVICES > 0
|
---|
510 | memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t));
|
---|
511 | #endif
|
---|
512 | #if MAX_NO_BNEP_SERVICES > 0
|
---|
513 | memory_pool_create(&bnep_service_pool, bnep_service_storage, MAX_NO_BNEP_SERVICES, sizeof(bnep_service_t));
|
---|
514 | #endif
|
---|
515 | #if MAX_NO_BNEP_CHANNELS > 0
|
---|
516 | memory_pool_create(&bnep_channel_pool, bnep_channel_storage, MAX_NO_BNEP_CHANNELS, sizeof(bnep_channel_t));
|
---|
517 | #endif
|
---|
518 | #ifdef HAVE_BLE
|
---|
519 | #if MAX_NO_GATT_CLIENTS > 0
|
---|
520 | memory_pool_create(&gatt_client_pool, gatt_client_storage, MAX_NO_GATT_CLIENTS, sizeof(gatt_client_t));
|
---|
521 | #endif
|
---|
522 | #if MAX_NO_GATT_SUBCLIENTS > 0
|
---|
523 | memory_pool_create(&gatt_subclient_pool, gatt_subclient_storage, MAX_NO_GATT_SUBCLIENTS, sizeof(gatt_subclient_t));
|
---|
524 | #endif
|
---|
525 | #endif
|
---|
526 | }
|
---|