Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FatFileSystem TB6612FNG2 mbed
BTstack/btstack_memory.c@0:de03cbbcd0ff, 2015-11-30 (annotated)
- Committer:
- mbed_Cookbook_SE
- Date:
- Mon Nov 30 09:32:15 2015 +0000
- Revision:
- 0:de03cbbcd0ff
??
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 1 | /* |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 2 | * Copyright (C) 2009-2012 by Matthias Ringwald |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 3 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 4 | * Redistribution and use in source and binary forms, with or without |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 5 | * modification, are permitted provided that the following conditions |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 6 | * are met: |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 7 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 8 | * 1. Redistributions of source code must retain the above copyright |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 9 | * notice, this list of conditions and the following disclaimer. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 11 | * notice, this list of conditions and the following disclaimer in the |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 12 | * documentation and/or other materials provided with the distribution. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 13 | * 3. Neither the name of the copyright holders nor the names of |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 14 | * contributors may be used to endorse or promote products derived |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 15 | * from this software without specific prior written permission. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 16 | * 4. Any redistribution, use, or modification is done solely for |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 17 | * personal benefit and not for any commercial purpose or for |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 18 | * monetary gain. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 19 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 20 | * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 21 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 23 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 24 | * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 25 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 26 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 27 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 28 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 29 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 30 | * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 31 | * SUCH DAMAGE. |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 32 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 33 | * Please inquire about commercial licensing options at btstack@ringwald.ch |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 34 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 35 | */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 36 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 37 | /* |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 38 | * btstsack_memory.h |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 39 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 40 | * @brief BTstack memory management via configurable memory pools |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 41 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 42 | * @note code semi-atuomatically generated by btstack_memory_generator.py |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 43 | * |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 44 | */ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 45 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 46 | #include "btstack_memory.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 47 | #include "btstack/memory_pool.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 48 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 49 | #include <stdlib.h> |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 50 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 51 | #include "config.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 52 | #include "hci.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 53 | #include "l2cap.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 54 | #include "rfcomm.h" |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 55 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 56 | // MARK: hci_connection_t |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 57 | #ifdef MAX_NO_HCI_CONNECTIONS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 58 | #if MAX_NO_HCI_CONNECTIONS > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 59 | static hci_connection_t hci_connection_storage[MAX_NO_HCI_CONNECTIONS]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 60 | static memory_pool_t hci_connection_pool; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 61 | void * btstack_memory_hci_connection_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 62 | return memory_pool_get(&hci_connection_pool); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 63 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 64 | void btstack_memory_hci_connection_free(void *hci_connection){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 65 | memory_pool_free(&hci_connection_pool, hci_connection); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 66 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 67 | #else |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 68 | void * btstack_memory_hci_connection_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 69 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 70 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 71 | void btstack_memory_hci_connection_free(void *hci_connection){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 72 | }; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 73 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 74 | #elif defined(HAVE_MALLOC) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 75 | void * btstack_memory_hci_connection_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 76 | return malloc(sizeof(hci_connection_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 77 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 78 | void btstack_memory_hci_connection_free(void *hci_connection){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 79 | free(hci_connection); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 80 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 81 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 82 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 83 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 84 | // MARK: l2cap_service_t |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 85 | #ifdef MAX_NO_L2CAP_SERVICES |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 86 | #if MAX_NO_L2CAP_SERVICES > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 87 | static l2cap_service_t l2cap_service_storage[MAX_NO_L2CAP_SERVICES]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 88 | static memory_pool_t l2cap_service_pool; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 89 | void * btstack_memory_l2cap_service_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 90 | return memory_pool_get(&l2cap_service_pool); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 91 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 92 | void btstack_memory_l2cap_service_free(void *l2cap_service){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 93 | memory_pool_free(&l2cap_service_pool, l2cap_service); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 94 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 95 | #else |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 96 | void * btstack_memory_l2cap_service_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 97 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 98 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 99 | void btstack_memory_l2cap_service_free(void *l2cap_service){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 100 | }; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 101 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 102 | #elif defined(HAVE_MALLOC) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 103 | void * btstack_memory_l2cap_service_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 104 | return malloc(sizeof(l2cap_service_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 105 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 106 | void btstack_memory_l2cap_service_free(void *l2cap_service){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 107 | free(l2cap_service); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 108 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 109 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 110 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 111 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 112 | // MARK: l2cap_channel_t |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 113 | #ifdef MAX_NO_L2CAP_CHANNELS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 114 | #if MAX_NO_L2CAP_CHANNELS > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 115 | static l2cap_channel_t l2cap_channel_storage[MAX_NO_L2CAP_CHANNELS]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 116 | static memory_pool_t l2cap_channel_pool; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 117 | void * btstack_memory_l2cap_channel_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 118 | return memory_pool_get(&l2cap_channel_pool); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 119 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 120 | void btstack_memory_l2cap_channel_free(void *l2cap_channel){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 121 | memory_pool_free(&l2cap_channel_pool, l2cap_channel); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 122 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 123 | #else |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 124 | void * btstack_memory_l2cap_channel_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 125 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 126 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 127 | void btstack_memory_l2cap_channel_free(void *l2cap_channel){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 128 | }; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 129 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 130 | #elif defined(HAVE_MALLOC) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 131 | void * btstack_memory_l2cap_channel_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 132 | return malloc(sizeof(l2cap_channel_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 133 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 134 | void btstack_memory_l2cap_channel_free(void *l2cap_channel){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 135 | free(l2cap_channel); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 136 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 137 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 138 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 139 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 140 | // MARK: rfcomm_multiplexer_t |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 141 | #ifdef MAX_NO_RFCOMM_MULTIPLEXERS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 142 | #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 143 | static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NO_RFCOMM_MULTIPLEXERS]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 144 | static memory_pool_t rfcomm_multiplexer_pool; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 145 | void * btstack_memory_rfcomm_multiplexer_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 146 | return memory_pool_get(&rfcomm_multiplexer_pool); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 147 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 148 | void btstack_memory_rfcomm_multiplexer_free(void *rfcomm_multiplexer){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 149 | memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 150 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 151 | #else |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 152 | void * btstack_memory_rfcomm_multiplexer_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 153 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 154 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 155 | void btstack_memory_rfcomm_multiplexer_free(void *rfcomm_multiplexer){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 156 | }; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 157 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 158 | #elif defined(HAVE_MALLOC) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 159 | void * btstack_memory_rfcomm_multiplexer_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 160 | return malloc(sizeof(rfcomm_multiplexer_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 161 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 162 | void btstack_memory_rfcomm_multiplexer_free(void *rfcomm_multiplexer){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 163 | free(rfcomm_multiplexer); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 164 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 165 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 166 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 167 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 168 | // MARK: rfcomm_service_t |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 169 | #ifdef MAX_NO_RFCOMM_SERVICES |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 170 | #if MAX_NO_RFCOMM_SERVICES > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 171 | static rfcomm_service_t rfcomm_service_storage[MAX_NO_RFCOMM_SERVICES]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 172 | static memory_pool_t rfcomm_service_pool; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 173 | void * btstack_memory_rfcomm_service_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 174 | return memory_pool_get(&rfcomm_service_pool); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 175 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 176 | void btstack_memory_rfcomm_service_free(void *rfcomm_service){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 177 | memory_pool_free(&rfcomm_service_pool, rfcomm_service); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 178 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 179 | #else |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 180 | void * btstack_memory_rfcomm_service_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 181 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 182 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 183 | void btstack_memory_rfcomm_service_free(void *rfcomm_service){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 184 | }; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 185 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 186 | #elif defined(HAVE_MALLOC) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 187 | void * btstack_memory_rfcomm_service_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 188 | return malloc(sizeof(rfcomm_service_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 189 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 190 | void btstack_memory_rfcomm_service_free(void *rfcomm_service){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 191 | free(rfcomm_service); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 192 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 193 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 194 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 195 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 196 | // MARK: rfcomm_channel_t |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 197 | #ifdef MAX_NO_RFCOMM_CHANNELS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 198 | #if MAX_NO_RFCOMM_CHANNELS > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 199 | static rfcomm_channel_t rfcomm_channel_storage[MAX_NO_RFCOMM_CHANNELS]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 200 | static memory_pool_t rfcomm_channel_pool; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 201 | void * btstack_memory_rfcomm_channel_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 202 | return memory_pool_get(&rfcomm_channel_pool); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 203 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 204 | void btstack_memory_rfcomm_channel_free(void *rfcomm_channel){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 205 | memory_pool_free(&rfcomm_channel_pool, rfcomm_channel); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 206 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 207 | #else |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 208 | void * btstack_memory_rfcomm_channel_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 209 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 210 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 211 | void btstack_memory_rfcomm_channel_free(void *rfcomm_channel){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 212 | }; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 213 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 214 | #elif defined(HAVE_MALLOC) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 215 | void * btstack_memory_rfcomm_channel_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 216 | return malloc(sizeof(rfcomm_channel_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 217 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 218 | void btstack_memory_rfcomm_channel_free(void *rfcomm_channel){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 219 | free(rfcomm_channel); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 220 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 221 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 222 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 223 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 224 | // MARK: db_mem_device_name_t |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 225 | #ifdef MAX_NO_DB_MEM_DEVICE_NAMES |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 226 | #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 227 | static db_mem_device_name_t db_mem_device_name_storage[MAX_NO_DB_MEM_DEVICE_NAMES]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 228 | static memory_pool_t db_mem_device_name_pool; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 229 | void * btstack_memory_db_mem_device_name_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 230 | return memory_pool_get(&db_mem_device_name_pool); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 231 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 232 | void btstack_memory_db_mem_device_name_free(void *db_mem_device_name){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 233 | memory_pool_free(&db_mem_device_name_pool, db_mem_device_name); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 234 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 235 | #else |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 236 | void * btstack_memory_db_mem_device_name_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 237 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 238 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 239 | void btstack_memory_db_mem_device_name_free(void *db_mem_device_name){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 240 | }; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 241 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 242 | #elif defined(HAVE_MALLOC) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 243 | void * btstack_memory_db_mem_device_name_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 244 | return malloc(sizeof(db_mem_device_name_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 245 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 246 | void btstack_memory_db_mem_device_name_free(void *db_mem_device_name){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 247 | free(db_mem_device_name); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 248 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 249 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 250 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 251 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 252 | // MARK: db_mem_device_link_key_t |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 253 | #ifdef MAX_NO_DB_MEM_DEVICE_LINK_KEYS |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 254 | #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 255 | static db_mem_device_link_key_t db_mem_device_link_key_storage[MAX_NO_DB_MEM_DEVICE_LINK_KEYS]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 256 | static memory_pool_t db_mem_device_link_key_pool; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 257 | void * btstack_memory_db_mem_device_link_key_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 258 | return memory_pool_get(&db_mem_device_link_key_pool); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 259 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 260 | void btstack_memory_db_mem_device_link_key_free(void *db_mem_device_link_key){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 261 | memory_pool_free(&db_mem_device_link_key_pool, db_mem_device_link_key); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 262 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 263 | #else |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 264 | void * btstack_memory_db_mem_device_link_key_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 265 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 266 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 267 | void btstack_memory_db_mem_device_link_key_free(void *db_mem_device_link_key){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 268 | }; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 269 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 270 | #elif defined(HAVE_MALLOC) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 271 | void * btstack_memory_db_mem_device_link_key_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 272 | return malloc(sizeof(db_mem_device_link_key_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 273 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 274 | void btstack_memory_db_mem_device_link_key_free(void *db_mem_device_link_key){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 275 | free(db_mem_device_link_key); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 276 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 277 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 278 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 279 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 280 | // MARK: db_mem_service_t |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 281 | #ifdef MAX_NO_DB_MEM_SERVICES |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 282 | #if MAX_NO_DB_MEM_SERVICES > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 283 | static db_mem_service_t db_mem_service_storage[MAX_NO_DB_MEM_SERVICES]; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 284 | static memory_pool_t db_mem_service_pool; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 285 | void * btstack_memory_db_mem_service_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 286 | return memory_pool_get(&db_mem_service_pool); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 287 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 288 | void btstack_memory_db_mem_service_free(void *db_mem_service){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 289 | memory_pool_free(&db_mem_service_pool, db_mem_service); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 290 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 291 | #else |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 292 | void * btstack_memory_db_mem_service_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 293 | return NULL; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 294 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 295 | void btstack_memory_db_mem_service_free(void *db_mem_service){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 296 | }; |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 297 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 298 | #elif defined(HAVE_MALLOC) |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 299 | void * btstack_memory_db_mem_service_get(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 300 | return malloc(sizeof(db_mem_service_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 301 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 302 | void btstack_memory_db_mem_service_free(void *db_mem_service){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 303 | free(db_mem_service); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 304 | } |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 305 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 306 | |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 307 | // init |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 308 | void btstack_memory_init(void){ |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 309 | #if MAX_NO_HCI_CONNECTIONS > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 310 | memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 311 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 312 | #if MAX_NO_L2CAP_SERVICES > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 313 | memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 314 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 315 | #if MAX_NO_L2CAP_CHANNELS > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 316 | memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 317 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 318 | #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 319 | memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 320 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 321 | #if MAX_NO_RFCOMM_SERVICES > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 322 | memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 323 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 324 | #if MAX_NO_RFCOMM_CHANNELS > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 325 | memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 326 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 327 | #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 328 | 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)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 329 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 330 | #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 331 | 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)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 332 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 333 | #if MAX_NO_DB_MEM_SERVICES > 0 |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 334 | memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t)); |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 335 | #endif |
| mbed_Cookbook_SE | 0:de03cbbcd0ff | 336 | } |