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