mesh: provide mesh_network_pdu memory pool

This commit is contained in:
Matthias Ringwald 2018-11-01 15:28:39 +01:00
parent 20537b9f41
commit ebb73e1fb1
4 changed files with 108 additions and 3 deletions

View File

@ -0,0 +1,56 @@
/*
* Copyright (C) 2018 BlueKitchen GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holders nor the names of
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* 4. Any redistribution, use, or modification is done solely for
* personal benefit and not for any commercial purpose or for
* monetary gain.
*
* THIS SOFTWARE IS PROVIDED BY BLUEKITCHEN GMBH AND CONTRIBUTORS
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MATTHIAS
* RINGWALD OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Please inquire about commercial licensing options at
* contact@bluekitchen-gmbh.com
*
*/
#ifndef __MESH_NETWORK
#define __MESH_NETWORK
#include "btstack_linked_list.h"
#if defined __cplusplus
extern "C" {
#endif
typedef struct {
btstack_linked_item_t item;
uint8_t pdu[29];
} mesh_network_pdu_t;
#if defined __cplusplus
}
#endif
#endif

View File

@ -895,6 +895,45 @@ void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry){
#endif
// MARK: mesh_network_pdu_t
#if !defined(HAVE_MALLOC) && !defined(MAX_NR_MESH_NETWORK_PDUS)
#if defined(MAX_NO_MESH_NETWORK_PDUS)
#error "Deprecated MAX_NO_MESH_NETWORK_PDUS defined instead of MAX_NR_MESH_NETWORK_PDUS. Please update your btstack_config.h to use MAX_NR_MESH_NETWORK_PDUS."
#else
#define MAX_NR_MESH_NETWORK_PDUS 0
#endif
#endif
#ifdef MAX_NR_MESH_NETWORK_PDUS
#if MAX_NR_MESH_NETWORK_PDUS > 0
static mesh_network_pdu_t mesh_network_pdu_storage[MAX_NR_MESH_NETWORK_PDUS];
static btstack_memory_pool_t mesh_network_pdu_pool;
mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
return (mesh_network_pdu_t *) btstack_memory_pool_get(&mesh_network_pdu_pool);
}
void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
btstack_memory_pool_free(&mesh_network_pdu_pool, mesh_network_pdu);
}
#else
mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
return NULL;
}
void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
// silence compiler warning about unused parameter in a portable way
(void) mesh_network_pdu;
};
#endif
#elif defined(HAVE_MALLOC)
mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void){
return (mesh_network_pdu_t*) malloc(sizeof(mesh_network_pdu_t));
}
void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu){
free(mesh_network_pdu);
}
#endif
#endif
// init
void btstack_memory_init(void){
@ -953,5 +992,8 @@ void btstack_memory_init(void){
#if MAX_NR_SM_LOOKUP_ENTRIES > 0
btstack_memory_pool_create(&sm_lookup_entry_pool, sm_lookup_entry_storage, MAX_NR_SM_LOOKUP_ENTRIES, sizeof(sm_lookup_entry_t));
#endif
#if MAX_NR_MESH_NETWORK_PDUS > 0
btstack_memory_pool_create(&mesh_network_pdu_pool, mesh_network_pdu_storage, MAX_NR_MESH_NETWORK_PDUS, sizeof(mesh_network_pdu_t));
#endif
#endif
}

View File

@ -72,6 +72,7 @@ extern "C" {
#ifdef ENABLE_BLE
#include "ble/gatt_client.h"
#include "ble/sm.h"
#include "ble/mesh/mesh_network.h"
#endif
/* API_START */
@ -143,6 +144,9 @@ whitelist_entry_t * btstack_memory_whitelist_entry_get(void);
void btstack_memory_whitelist_entry_free(whitelist_entry_t *whitelist_entry);
sm_lookup_entry_t * btstack_memory_sm_lookup_entry_get(void);
void btstack_memory_sm_lookup_entry_free(sm_lookup_entry_t *sm_lookup_entry);
// mesh_network_pdu
mesh_network_pdu_t * btstack_memory_mesh_network_pdu_get(void);
void btstack_memory_mesh_network_pdu_free(mesh_network_pdu_t *mesh_network_pdu);
#endif
#if defined __cplusplus

View File

@ -78,6 +78,7 @@ extern "C" {
#ifdef ENABLE_BLE
#include "ble/gatt_client.h"
#include "ble/sm.h"
#include "ble/mesh/mesh_network.h"
#endif
/* API_START */
@ -194,10 +195,12 @@ list_of_structs = [
["avdtp_stream_endpoint"],
["avdtp_connection"],
["avrcp_connection"],
["avrcp_browsing_connection"]
["avrcp_browsing_connection"],
]
list_of_le_structs = [
["gatt_client", "whitelist_entry", "sm_lookup_entry"],
['mesh_network_pdu']
]
list_of_le_structs = [["gatt_client", "whitelist_entry", "sm_lookup_entry"]]
"""
"""