Use allocation strategy for dynamic buffers in NimBLE host stack

This commit is contained in:
Hrishikesh Dhayagude
2020-08-03 23:37:28 +05:30
committed by Prasad Alatkar
parent 1950e55e6d
commit 4983d5ed35
5 changed files with 21 additions and 16 deletions
+2 -1
View File
@@ -28,6 +28,7 @@
#include "bleuart/bleuart.h"
#include "os/endian.h"
#include "console/console.h"
#include "esp_nimble_mem.h"
/* ble uart attr read handle */
uint16_t g_bleuart_attr_read_handle;
@@ -198,6 +199,6 @@ bleuart_init(void)
rc = console_init(bleuart_uart_read);
SYSINIT_PANIC_ASSERT(rc == 0);
console_buf = malloc(MYNEWT_VAL(BLEUART_MAX_INPUT));
console_buf = nimble_platform_mem_malloc(MYNEWT_VAL(BLEUART_MAX_INPUT));
SYSINIT_PANIC_ASSERT(console_buf != NULL);
}
+3 -2
View File
@@ -24,6 +24,7 @@
#include "nimble/ble.h"
#include "host/ble_uuid.h"
#include "ble_hs_priv.h"
#include "esp_nimble_mem.h"
/**
* ATT server - Attribute Protocol
@@ -2668,7 +2669,7 @@ ble_att_svr_reset(void)
static void
ble_att_svr_free_start_mem(void)
{
free(ble_att_svr_entry_mem);
nimble_platform_mem_free(ble_att_svr_entry_mem);
ble_att_svr_entry_mem = NULL;
}
@@ -2680,7 +2681,7 @@ ble_att_svr_start(void)
ble_att_svr_free_start_mem();
if (ble_hs_max_attrs > 0) {
ble_att_svr_entry_mem = malloc(
ble_att_svr_entry_mem = nimble_platform_mem_malloc(
OS_MEMPOOL_BYTES(ble_hs_max_attrs,
sizeof (struct ble_att_svr_entry)));
if (ble_att_svr_entry_mem == NULL) {
+6 -5
View File
@@ -24,6 +24,7 @@
#include "host/ble_uuid.h"
#include "host/ble_store.h"
#include "ble_hs_priv.h"
#include "esp_nimble_mem.h"
#define BLE_GATTS_INCLUDE_SZ 6
#define BLE_GATTS_CHR_MAX_SZ 19
@@ -1154,7 +1155,7 @@ ble_gatts_connection_broken(uint16_t conn_handle)
static void
ble_gatts_free_svc_defs(void)
{
free(ble_gatts_svc_defs);
nimble_platform_mem_free(ble_gatts_svc_defs);
ble_gatts_svc_defs = NULL;
ble_gatts_num_svc_defs = 0;
}
@@ -1162,10 +1163,10 @@ ble_gatts_free_svc_defs(void)
static void
ble_gatts_free_mem(void)
{
free(ble_gatts_clt_cfg_mem);
nimble_platform_mem_free(ble_gatts_clt_cfg_mem);
ble_gatts_clt_cfg_mem = NULL;
free(ble_gatts_svc_entries);
nimble_platform_mem_free(ble_gatts_svc_entries);
ble_gatts_svc_entries = NULL;
}
@@ -1209,7 +1210,7 @@ ble_gatts_start(void)
}
if (ble_hs_max_client_configs > 0) {
ble_gatts_clt_cfg_mem = malloc(
ble_gatts_clt_cfg_mem = nimble_platform_mem_malloc(
OS_MEMPOOL_BYTES(ble_hs_max_client_configs,
sizeof (struct ble_gatts_clt_cfg)));
if (ble_gatts_clt_cfg_mem == NULL) {
@@ -1220,7 +1221,7 @@ ble_gatts_start(void)
if (ble_hs_max_services > 0) {
ble_gatts_svc_entries =
malloc(ble_hs_max_services * sizeof *ble_gatts_svc_entries);
nimble_platform_mem_malloc(ble_hs_max_services * sizeof *ble_gatts_svc_entries);
if (ble_gatts_svc_entries == NULL) {
rc = BLE_HS_ENOMEM;
goto done;
+5 -4
View File
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include "os/os.h"
#include "mem/mem.h"
#include "esp_nimble_mem.h"
/**
* Generic mempool allocation function. Used with basic and extended mempools.
@@ -31,7 +32,7 @@ mem_malloc_mempool_gen(uint16_t num_blocks, uint32_t block_size,
block_size = OS_ALIGN(block_size, OS_ALIGNMENT);
if (num_blocks > 0) {
*out_buf = malloc(OS_MEMPOOL_BYTES(num_blocks, block_size));
*out_buf = nimble_platform_mem_malloc(OS_MEMPOOL_BYTES(num_blocks, block_size));
if (*out_buf == NULL) {
return OS_ENOMEM;
}
@@ -72,7 +73,7 @@ mem_malloc_mempool(struct os_mempool *mempool, uint16_t num_blocks,
rc = os_mempool_init(mempool, num_blocks, block_size, buf, name);
if (rc != 0) {
free(buf);
nimble_platform_mem_free(buf);
return rc;
}
@@ -113,7 +114,7 @@ mem_malloc_mempool_ext(struct os_mempool_ext *mpe, uint16_t num_blocks,
rc = os_mempool_ext_init(mpe, num_blocks, block_size, buf, name);
if (rc != 0) {
free(buf);
nimble_platform_mem_free(buf);
return rc;
}
@@ -160,7 +161,7 @@ mem_malloc_mbuf_pool(struct os_mempool *mempool,
rc = os_mbuf_pool_init(mbuf_pool, mempool, block_size, num_blocks);
if (rc != 0) {
free(buf);
nimble_platform_mem_free(buf);
return rc;
}
+5 -4
View File
@@ -20,6 +20,7 @@
#include <assert.h>
#include "os/os.h"
#include "mem/mem.h"
#include "esp_nimble_mem.h"
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
#define SYSINIT_MSYS_1_MEMBLOCK_SIZE \
@@ -62,14 +63,14 @@ int
os_msys_buf_alloc(void)
{
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
os_msys_init_1_data = (os_membuf_t *)calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_1_MEMPOOL_SIZE));
os_msys_init_1_data = (os_membuf_t *)nimble_platform_mem_calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_1_MEMPOOL_SIZE));
if (!os_msys_init_1_data) {
return -1;
}
#endif
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
os_msys_init_2_data = (os_membuf_t *)calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_2_MEMPOOL_SIZE));
os_msys_init_2_data = (os_membuf_t *)nimble_platform_mem_calloc(1, (sizeof(os_membuf_t) * SYSINIT_MSYS_2_MEMPOOL_SIZE));
if (!os_msys_init_2_data) {
return -1;
}
@@ -82,12 +83,12 @@ void
os_msys_buf_free(void)
{
#if MYNEWT_VAL(MSYS_1_BLOCK_COUNT) > 0
free(os_msys_init_1_data);
nimble_platform_mem_free(os_msys_init_1_data);
os_msys_init_1_data = NULL;
#endif
#if MYNEWT_VAL(MSYS_2_BLOCK_COUNT) > 0
free(os_msys_init_2_data);
nimble_platform_mem_free(os_msys_init_2_data);
os_msys_init_2_data = NULL;
#endif