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