BLE demo for mbed Ported RunningElectronics's SBDBT firmware for BLE. It can communicate with iOS
Dependencies: FatFileSystem mbed
Fork of BTstack by
btstack_memory.c
00001 /* 00002 * Copyright (C) 2009-2012 by Matthias Ringwald 00003 * 00004 * Redistribution and use in source and binary forms, with or without 00005 * modification, are permitted provided that the following conditions 00006 * are met: 00007 * 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. Neither the name of the copyright holders nor the names of 00014 * contributors may be used to endorse or promote products derived 00015 * from this software without specific prior written permission. 00016 * 4. Any redistribution, use, or modification is done solely for 00017 * personal benefit and not for any commercial purpose or for 00018 * monetary gain. 00019 * 00020 * THIS SOFTWARE IS PROVIDED BY MATTHIAS RINGWALD AND CONTRIBUTORS 00021 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 00022 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 00023 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS 00024 * RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 00025 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 00026 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 00027 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 00028 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00029 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00030 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00031 * SUCH DAMAGE. 00032 * 00033 * Please inquire about commercial licensing options at btstack@ringwald.ch 00034 * 00035 */ 00036 00037 /* 00038 * btstsack_memory.h 00039 * 00040 * @brief BTstack memory management via configurable memory pools 00041 * 00042 * @note code semi-atuomatically generated by btstack_memory_generator.py 00043 * 00044 */ 00045 00046 #include "btstack_memory.h" 00047 #include "btstack/memory_pool.h" 00048 00049 #include <stdlib.h> 00050 00051 #include "config.h" 00052 #include "hci.h" 00053 #include "l2cap.h" 00054 #include "rfcomm.h" 00055 00056 // MARK: hci_connection_t 00057 #ifdef MAX_NO_HCI_CONNECTIONS 00058 #if MAX_NO_HCI_CONNECTIONS > 0 00059 static hci_connection_t hci_connection_storage[MAX_NO_HCI_CONNECTIONS]; 00060 static memory_pool_t hci_connection_pool; 00061 void * btstack_memory_hci_connection_get(void){ 00062 return memory_pool_get(&hci_connection_pool); 00063 } 00064 void btstack_memory_hci_connection_free(void *hci_connection){ 00065 memory_pool_free(&hci_connection_pool, hci_connection); 00066 } 00067 #else 00068 void * btstack_memory_hci_connection_get(void){ 00069 return NULL; 00070 } 00071 void btstack_memory_hci_connection_free(void *hci_connection){ 00072 }; 00073 #endif 00074 #elif defined(HAVE_MALLOC) 00075 void * btstack_memory_hci_connection_get(void){ 00076 return malloc(sizeof(hci_connection_t)); 00077 } 00078 void btstack_memory_hci_connection_free(void *hci_connection){ 00079 free(hci_connection); 00080 } 00081 #endif 00082 00083 00084 // MARK: l2cap_service_t 00085 #ifdef MAX_NO_L2CAP_SERVICES 00086 #if MAX_NO_L2CAP_SERVICES > 0 00087 static l2cap_service_t l2cap_service_storage[MAX_NO_L2CAP_SERVICES]; 00088 static memory_pool_t l2cap_service_pool; 00089 void * btstack_memory_l2cap_service_get(void){ 00090 return memory_pool_get(&l2cap_service_pool); 00091 } 00092 void btstack_memory_l2cap_service_free(void *l2cap_service){ 00093 memory_pool_free(&l2cap_service_pool, l2cap_service); 00094 } 00095 #else 00096 void * btstack_memory_l2cap_service_get(void){ 00097 return NULL; 00098 } 00099 void btstack_memory_l2cap_service_free(void *l2cap_service){ 00100 }; 00101 #endif 00102 #elif defined(HAVE_MALLOC) 00103 void * btstack_memory_l2cap_service_get(void){ 00104 return malloc(sizeof(l2cap_service_t)); 00105 } 00106 void btstack_memory_l2cap_service_free(void *l2cap_service){ 00107 free(l2cap_service); 00108 } 00109 #endif 00110 00111 00112 // MARK: l2cap_channel_t 00113 #ifdef MAX_NO_L2CAP_CHANNELS 00114 #if MAX_NO_L2CAP_CHANNELS > 0 00115 static l2cap_channel_t l2cap_channel_storage[MAX_NO_L2CAP_CHANNELS]; 00116 static memory_pool_t l2cap_channel_pool; 00117 void * btstack_memory_l2cap_channel_get(void){ 00118 return memory_pool_get(&l2cap_channel_pool); 00119 } 00120 void btstack_memory_l2cap_channel_free(void *l2cap_channel){ 00121 memory_pool_free(&l2cap_channel_pool, l2cap_channel); 00122 } 00123 #else 00124 void * btstack_memory_l2cap_channel_get(void){ 00125 return NULL; 00126 } 00127 void btstack_memory_l2cap_channel_free(void *l2cap_channel){ 00128 }; 00129 #endif 00130 #elif defined(HAVE_MALLOC) 00131 void * btstack_memory_l2cap_channel_get(void){ 00132 return malloc(sizeof(l2cap_channel_t)); 00133 } 00134 void btstack_memory_l2cap_channel_free(void *l2cap_channel){ 00135 free(l2cap_channel); 00136 } 00137 #endif 00138 00139 00140 // MARK: rfcomm_multiplexer_t 00141 #ifdef MAX_NO_RFCOMM_MULTIPLEXERS 00142 #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 00143 static rfcomm_multiplexer_t rfcomm_multiplexer_storage[MAX_NO_RFCOMM_MULTIPLEXERS]; 00144 static memory_pool_t rfcomm_multiplexer_pool; 00145 void * btstack_memory_rfcomm_multiplexer_get(void){ 00146 return memory_pool_get(&rfcomm_multiplexer_pool); 00147 } 00148 void btstack_memory_rfcomm_multiplexer_free(void *rfcomm_multiplexer){ 00149 memory_pool_free(&rfcomm_multiplexer_pool, rfcomm_multiplexer); 00150 } 00151 #else 00152 void * btstack_memory_rfcomm_multiplexer_get(void){ 00153 return NULL; 00154 } 00155 void btstack_memory_rfcomm_multiplexer_free(void *rfcomm_multiplexer){ 00156 }; 00157 #endif 00158 #elif defined(HAVE_MALLOC) 00159 void * btstack_memory_rfcomm_multiplexer_get(void){ 00160 return malloc(sizeof(rfcomm_multiplexer_t)); 00161 } 00162 void btstack_memory_rfcomm_multiplexer_free(void *rfcomm_multiplexer){ 00163 free(rfcomm_multiplexer); 00164 } 00165 #endif 00166 00167 00168 // MARK: rfcomm_service_t 00169 #ifdef MAX_NO_RFCOMM_SERVICES 00170 #if MAX_NO_RFCOMM_SERVICES > 0 00171 static rfcomm_service_t rfcomm_service_storage[MAX_NO_RFCOMM_SERVICES]; 00172 static memory_pool_t rfcomm_service_pool; 00173 void * btstack_memory_rfcomm_service_get(void){ 00174 return memory_pool_get(&rfcomm_service_pool); 00175 } 00176 void btstack_memory_rfcomm_service_free(void *rfcomm_service){ 00177 memory_pool_free(&rfcomm_service_pool, rfcomm_service); 00178 } 00179 #else 00180 void * btstack_memory_rfcomm_service_get(void){ 00181 return NULL; 00182 } 00183 void btstack_memory_rfcomm_service_free(void *rfcomm_service){ 00184 }; 00185 #endif 00186 #elif defined(HAVE_MALLOC) 00187 void * btstack_memory_rfcomm_service_get(void){ 00188 return malloc(sizeof(rfcomm_service_t)); 00189 } 00190 void btstack_memory_rfcomm_service_free(void *rfcomm_service){ 00191 free(rfcomm_service); 00192 } 00193 #endif 00194 00195 00196 // MARK: rfcomm_channel_t 00197 #ifdef MAX_NO_RFCOMM_CHANNELS 00198 #if MAX_NO_RFCOMM_CHANNELS > 0 00199 static rfcomm_channel_t rfcomm_channel_storage[MAX_NO_RFCOMM_CHANNELS]; 00200 static memory_pool_t rfcomm_channel_pool; 00201 void * btstack_memory_rfcomm_channel_get(void){ 00202 return memory_pool_get(&rfcomm_channel_pool); 00203 } 00204 void btstack_memory_rfcomm_channel_free(void *rfcomm_channel){ 00205 memory_pool_free(&rfcomm_channel_pool, rfcomm_channel); 00206 } 00207 #else 00208 void * btstack_memory_rfcomm_channel_get(void){ 00209 return NULL; 00210 } 00211 void btstack_memory_rfcomm_channel_free(void *rfcomm_channel){ 00212 }; 00213 #endif 00214 #elif defined(HAVE_MALLOC) 00215 void * btstack_memory_rfcomm_channel_get(void){ 00216 return malloc(sizeof(rfcomm_channel_t)); 00217 } 00218 void btstack_memory_rfcomm_channel_free(void *rfcomm_channel){ 00219 free(rfcomm_channel); 00220 } 00221 #endif 00222 00223 00224 // MARK: db_mem_device_name_t 00225 #ifdef MAX_NO_DB_MEM_DEVICE_NAMES 00226 #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 00227 static db_mem_device_name_t db_mem_device_name_storage[MAX_NO_DB_MEM_DEVICE_NAMES]; 00228 static memory_pool_t db_mem_device_name_pool; 00229 void * btstack_memory_db_mem_device_name_get(void){ 00230 return memory_pool_get(&db_mem_device_name_pool); 00231 } 00232 void btstack_memory_db_mem_device_name_free(void *db_mem_device_name){ 00233 memory_pool_free(&db_mem_device_name_pool, db_mem_device_name); 00234 } 00235 #else 00236 void * btstack_memory_db_mem_device_name_get(void){ 00237 return NULL; 00238 } 00239 void btstack_memory_db_mem_device_name_free(void *db_mem_device_name){ 00240 }; 00241 #endif 00242 #elif defined(HAVE_MALLOC) 00243 void * btstack_memory_db_mem_device_name_get(void){ 00244 return malloc(sizeof(db_mem_device_name_t)); 00245 } 00246 void btstack_memory_db_mem_device_name_free(void *db_mem_device_name){ 00247 free(db_mem_device_name); 00248 } 00249 #endif 00250 00251 00252 // MARK: db_mem_device_link_key_t 00253 #ifdef MAX_NO_DB_MEM_DEVICE_LINK_KEYS 00254 #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 00255 static db_mem_device_link_key_t db_mem_device_link_key_storage[MAX_NO_DB_MEM_DEVICE_LINK_KEYS]; 00256 static memory_pool_t db_mem_device_link_key_pool; 00257 void * btstack_memory_db_mem_device_link_key_get(void){ 00258 return memory_pool_get(&db_mem_device_link_key_pool); 00259 } 00260 void btstack_memory_db_mem_device_link_key_free(void *db_mem_device_link_key){ 00261 memory_pool_free(&db_mem_device_link_key_pool, db_mem_device_link_key); 00262 } 00263 #else 00264 void * btstack_memory_db_mem_device_link_key_get(void){ 00265 return NULL; 00266 } 00267 void btstack_memory_db_mem_device_link_key_free(void *db_mem_device_link_key){ 00268 }; 00269 #endif 00270 #elif defined(HAVE_MALLOC) 00271 void * btstack_memory_db_mem_device_link_key_get(void){ 00272 return malloc(sizeof(db_mem_device_link_key_t)); 00273 } 00274 void btstack_memory_db_mem_device_link_key_free(void *db_mem_device_link_key){ 00275 free(db_mem_device_link_key); 00276 } 00277 #endif 00278 00279 00280 // MARK: db_mem_service_t 00281 #ifdef MAX_NO_DB_MEM_SERVICES 00282 #if MAX_NO_DB_MEM_SERVICES > 0 00283 static db_mem_service_t db_mem_service_storage[MAX_NO_DB_MEM_SERVICES]; 00284 static memory_pool_t db_mem_service_pool; 00285 void * btstack_memory_db_mem_service_get(void){ 00286 return memory_pool_get(&db_mem_service_pool); 00287 } 00288 void btstack_memory_db_mem_service_free(void *db_mem_service){ 00289 memory_pool_free(&db_mem_service_pool, db_mem_service); 00290 } 00291 #else 00292 void * btstack_memory_db_mem_service_get(void){ 00293 return NULL; 00294 } 00295 void btstack_memory_db_mem_service_free(void *db_mem_service){ 00296 }; 00297 #endif 00298 #elif defined(HAVE_MALLOC) 00299 void * btstack_memory_db_mem_service_get(void){ 00300 return malloc(sizeof(db_mem_service_t)); 00301 } 00302 void btstack_memory_db_mem_service_free(void *db_mem_service){ 00303 free(db_mem_service); 00304 } 00305 #endif 00306 00307 // init 00308 void btstack_memory_init(void){ 00309 #if MAX_NO_HCI_CONNECTIONS > 0 00310 memory_pool_create(&hci_connection_pool, hci_connection_storage, MAX_NO_HCI_CONNECTIONS, sizeof(hci_connection_t)); 00311 #endif 00312 #if MAX_NO_L2CAP_SERVICES > 0 00313 memory_pool_create(&l2cap_service_pool, l2cap_service_storage, MAX_NO_L2CAP_SERVICES, sizeof(l2cap_service_t)); 00314 #endif 00315 #if MAX_NO_L2CAP_CHANNELS > 0 00316 memory_pool_create(&l2cap_channel_pool, l2cap_channel_storage, MAX_NO_L2CAP_CHANNELS, sizeof(l2cap_channel_t)); 00317 #endif 00318 #if MAX_NO_RFCOMM_MULTIPLEXERS > 0 00319 memory_pool_create(&rfcomm_multiplexer_pool, rfcomm_multiplexer_storage, MAX_NO_RFCOMM_MULTIPLEXERS, sizeof(rfcomm_multiplexer_t)); 00320 #endif 00321 #if MAX_NO_RFCOMM_SERVICES > 0 00322 memory_pool_create(&rfcomm_service_pool, rfcomm_service_storage, MAX_NO_RFCOMM_SERVICES, sizeof(rfcomm_service_t)); 00323 #endif 00324 #if MAX_NO_RFCOMM_CHANNELS > 0 00325 memory_pool_create(&rfcomm_channel_pool, rfcomm_channel_storage, MAX_NO_RFCOMM_CHANNELS, sizeof(rfcomm_channel_t)); 00326 #endif 00327 #if MAX_NO_DB_MEM_DEVICE_NAMES > 0 00328 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)); 00329 #endif 00330 #if MAX_NO_DB_MEM_DEVICE_LINK_KEYS > 0 00331 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)); 00332 #endif 00333 #if MAX_NO_DB_MEM_SERVICES > 0 00334 memory_pool_create(&db_mem_service_pool, db_mem_service_storage, MAX_NO_DB_MEM_SERVICES, sizeof(db_mem_service_t)); 00335 #endif 00336 }
Generated on Thu Jul 14 2022 15:03:48 by 1.7.2