mirror of
https://github.com/espressif/esp-nimble.git
synced 2026-06-05 21:04:49 +00:00
fix(nimble): Use nimble platform mem malloc / free APIs
This commit is contained in:
+25
-23
@@ -64,6 +64,8 @@
|
||||
#if MYNEWT_VAL(BLE_GATT_CACHING)
|
||||
#include "host/ble_esp_gattc_cache.h"
|
||||
#endif
|
||||
#include "esp_nimble_mem.h"
|
||||
|
||||
#if NIMBLE_BLE_CONNECT
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATTC)
|
||||
@@ -3313,7 +3315,7 @@ int ble_gattc_get_service(uint16_t conn_handle,
|
||||
rc = ble_gattc_check_valid_param(svc_num, offset);
|
||||
if (rc != 0) {
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
return rc;
|
||||
@@ -3323,7 +3325,7 @@ int ble_gattc_get_service(uint16_t conn_handle,
|
||||
|
||||
//free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -3342,7 +3344,7 @@ int ble_gattc_get_all_char(uint16_t conn_handle,
|
||||
rc = ble_gattc_check_valid_param(char_num, offset);
|
||||
if (rc != 0) {
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
return rc;
|
||||
@@ -3352,7 +3354,7 @@ int ble_gattc_get_all_char(uint16_t conn_handle,
|
||||
|
||||
//free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -3370,7 +3372,7 @@ int ble_gattc_get_all_descr(uint16_t conn_handle,
|
||||
rc = ble_gattc_check_valid_param(descr_num, offset);
|
||||
if (rc != 0) {
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
return rc;
|
||||
@@ -3380,7 +3382,7 @@ int ble_gattc_get_all_descr(uint16_t conn_handle,
|
||||
|
||||
// free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -3400,7 +3402,7 @@ int ble_gattc_get_char_by_uuid(uint16_t conn_handle,
|
||||
rc = ble_gattc_check_valid_param(char_num, 0);
|
||||
if (rc != 0) {
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
return rc;
|
||||
@@ -3410,7 +3412,7 @@ int ble_gattc_get_char_by_uuid(uint16_t conn_handle,
|
||||
|
||||
// free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -3432,7 +3434,7 @@ int ble_gattc_get_descr_by_uuid(uint16_t conn_handle,
|
||||
rc = ble_gattc_check_valid_param(descr_num, 0);
|
||||
if (rc != 0) {
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
return rc;
|
||||
@@ -3442,7 +3444,7 @@ int ble_gattc_get_descr_by_uuid(uint16_t conn_handle,
|
||||
|
||||
// free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -3461,7 +3463,7 @@ int ble_gattc_get_descr_by_char_handle(uint16_t conn_handle,
|
||||
rc = ble_gattc_check_valid_param(descr_num, 0);
|
||||
if (rc != 0) {
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
return rc;
|
||||
@@ -3471,7 +3473,7 @@ int ble_gattc_get_descr_by_char_handle(uint16_t conn_handle,
|
||||
|
||||
// free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -3493,7 +3495,7 @@ int ble_gattc_get_include_service(uint16_t conn_handle,
|
||||
rc = ble_gattc_check_valid_param(incl_num,0);
|
||||
if (rc != 0) {
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
*count = 0;
|
||||
return rc;
|
||||
@@ -3503,7 +3505,7 @@ int ble_gattc_get_include_service(uint16_t conn_handle,
|
||||
|
||||
//free the db buffer after used.
|
||||
if (db) {
|
||||
free(db);
|
||||
nimble_platform_mem_free(db);
|
||||
}
|
||||
return 0;
|
||||
|
||||
@@ -3537,7 +3539,7 @@ int ble_gattc_get_db(uint16_t conn_handle,
|
||||
if (db) {
|
||||
*count = num;
|
||||
memcpy(result, db, num * sizeof(ble_gattc_db_elem_t)); // Copy data
|
||||
free(db); // Free allocated memory
|
||||
nimble_platform_mem_free(db); // Free allocated memory
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -5387,7 +5389,7 @@ static int ble_gattc_cccd_register_cb(uint16_t conn_handle, const struct ble_gat
|
||||
/* GATT procedure completed reset active flag */
|
||||
gatt_proc_active = false;
|
||||
if (cccd_reg_flag) {
|
||||
free(cccd_reg_flag);
|
||||
nimble_platform_mem_free(cccd_reg_flag);
|
||||
}
|
||||
} else if (error->status == 0) {
|
||||
if (cccd_reg_flag && *cccd_reg_flag &&
|
||||
@@ -5410,7 +5412,7 @@ static int ble_gattc_cccd_register_cb(uint16_t conn_handle, const struct ble_gat
|
||||
BLE_HS_LOG(WARN, "GATT descriptor discovery failed with status = %d", error->status);
|
||||
gatt_proc_active = false;
|
||||
if (cccd_reg_flag) {
|
||||
free(cccd_reg_flag);
|
||||
nimble_platform_mem_free(cccd_reg_flag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5425,7 +5427,7 @@ int ble_gattc_register_for_notification(uint16_t conn_handle, uint16_t char_val_
|
||||
return BLE_HS_EBUSY;
|
||||
}
|
||||
|
||||
bool *cccd_reg_flag = (bool *)malloc(sizeof(bool));
|
||||
bool *cccd_reg_flag = (bool *)nimble_platform_mem_malloc(sizeof(bool));
|
||||
if (!cccd_reg_flag) {
|
||||
BLE_HS_LOG(ERROR, "Failed to allocate memory for CCCD Reg Flag.");
|
||||
return BLE_HS_ENOMEM;
|
||||
@@ -5439,7 +5441,7 @@ int ble_gattc_register_for_notification(uint16_t conn_handle, uint16_t char_val_
|
||||
ble_gattc_cccd_register_cb, cccd_reg_flag);
|
||||
if (rc != 0) {
|
||||
gatt_proc_active = false;
|
||||
free(cccd_reg_flag);
|
||||
nimble_platform_mem_free(cccd_reg_flag);
|
||||
}
|
||||
|
||||
return rc;
|
||||
@@ -5456,7 +5458,7 @@ static int ble_gattc_cccd_unregister_cb(uint16_t conn_handle, const struct ble_g
|
||||
/* GATT procedure completed reset active flag */
|
||||
gatt_proc_active = false;
|
||||
if (cccd_unreg_flag) {
|
||||
free(cccd_unreg_flag);
|
||||
nimble_platform_mem_free(cccd_unreg_flag);
|
||||
}
|
||||
} else if (error->status == 0) {
|
||||
if (cccd_unreg_flag && *cccd_unreg_flag &&
|
||||
@@ -5479,7 +5481,7 @@ static int ble_gattc_cccd_unregister_cb(uint16_t conn_handle, const struct ble_g
|
||||
BLE_HS_LOG(WARN, "GATT descriptor discovery failed with status = %d", error->status);
|
||||
gatt_proc_active = false;
|
||||
if (cccd_unreg_flag) {
|
||||
free(cccd_unreg_flag);
|
||||
nimble_platform_mem_free(cccd_unreg_flag);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5495,7 +5497,7 @@ int ble_gattc_unregister_for_notification(uint16_t conn_handle, uint16_t char_va
|
||||
}
|
||||
|
||||
int rc;
|
||||
bool *cccd_unreg_flag = (bool *)malloc(sizeof(bool));
|
||||
bool *cccd_unreg_flag = (bool *)nimble_platform_mem_malloc(sizeof(bool));
|
||||
|
||||
if (!cccd_unreg_flag) {
|
||||
BLE_HS_LOG(ERROR, "Failed to allocate memory for CCCD Reg Flag");
|
||||
@@ -5509,7 +5511,7 @@ int ble_gattc_unregister_for_notification(uint16_t conn_handle, uint16_t char_va
|
||||
ble_gattc_cccd_unregister_cb, cccd_unreg_flag);
|
||||
if (rc != 0) {
|
||||
gatt_proc_active = false;
|
||||
free(cccd_unreg_flag);
|
||||
nimble_platform_mem_free(cccd_unreg_flag);
|
||||
}
|
||||
|
||||
return rc;
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
#include "host/ble_hs.h"
|
||||
#include "ble_hs_priv.h"
|
||||
#include "ble_gattc_cache_priv.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATT_CACHING)
|
||||
/* Gatt Procedure macros */
|
||||
@@ -999,7 +1000,7 @@ void ble_gattc_get_service_with_uuid(uint16_t conn_handle,
|
||||
}
|
||||
|
||||
// Allocate memory for the GATT database
|
||||
void *buffer = malloc(db_size * sizeof(ble_gattc_db_elem_t));
|
||||
void *buffer = nimble_platform_mem_malloc(db_size * sizeof(ble_gattc_db_elem_t));
|
||||
if (!buffer) {
|
||||
BLE_HS_LOG(WARN, "%s(), no resource.", __func__);
|
||||
*count = 0;
|
||||
@@ -1066,7 +1067,7 @@ void ble_gattc_get_db_with_operation(uint16_t conn_handle,
|
||||
}
|
||||
|
||||
// Allocate memory for the GATT database
|
||||
void *buffer = malloc(db_size * sizeof(ble_gattc_db_elem_t));
|
||||
void *buffer = nimble_platform_mem_malloc(db_size * sizeof(ble_gattc_db_elem_t));
|
||||
if (!buffer) {
|
||||
BLE_HS_LOG(WARN, "%s(), no resource.", __func__);
|
||||
*count = 0;
|
||||
@@ -1221,7 +1222,7 @@ static void ble_gattc_get_gatt_db_impl(struct ble_gattc_cache_conn *peer,
|
||||
}
|
||||
db_size = (*db_num > db_size) ? db_size : (*db_num);
|
||||
// Allocate memory for the GATT database
|
||||
void *buffer = malloc(db_size * sizeof(ble_gattc_db_elem_t));
|
||||
void *buffer = nimble_platform_mem_malloc(db_size * sizeof(ble_gattc_db_elem_t));
|
||||
if (!buffer) {
|
||||
BLE_HS_LOG(WARN, "%s(), no resource.", __func__);
|
||||
*count = 0;
|
||||
@@ -2122,20 +2123,20 @@ ble_gattc_cache_conn_get_svc_changed_handle(uint16_t conn_handle)
|
||||
void
|
||||
ble_gattc_cache_conn_free_mem(void)
|
||||
{
|
||||
free(ble_gattc_cache_conn_mem);
|
||||
nimble_platform_mem_free(ble_gattc_cache_conn_mem);
|
||||
ble_gattc_cache_conn_mem = NULL;
|
||||
|
||||
free(ble_gattc_cache_conn_svc_mem);
|
||||
nimble_platform_mem_free(ble_gattc_cache_conn_svc_mem);
|
||||
ble_gattc_cache_conn_svc_mem = NULL;
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
free(ble_gattc_cache_conn_incl_svc_mem);
|
||||
nimble_platform_mem_free(ble_gattc_cache_conn_incl_svc_mem);
|
||||
ble_gattc_cache_conn_incl_svc_mem = NULL;
|
||||
#endif
|
||||
free(ble_gattc_cache_conn_chr_mem);
|
||||
nimble_platform_mem_free(ble_gattc_cache_conn_chr_mem);
|
||||
ble_gattc_cache_conn_chr_mem = NULL;
|
||||
|
||||
free(ble_gattc_cache_conn_dsc_mem);
|
||||
nimble_platform_mem_free(ble_gattc_cache_conn_dsc_mem);
|
||||
ble_gattc_cache_conn_dsc_mem = NULL;
|
||||
}
|
||||
|
||||
@@ -2166,7 +2167,7 @@ ble_gattc_cache_conn_init()
|
||||
/* Free memory first in case this function gets called more than once. */
|
||||
ble_gattc_cache_conn_free_mem();
|
||||
|
||||
ble_gattc_cache_conn_mem = malloc(
|
||||
ble_gattc_cache_conn_mem = nimble_platform_mem_malloc(
|
||||
OS_MEMPOOL_BYTES(max_ble_gattc_cache_conns, sizeof(struct ble_gattc_cache_conn)));
|
||||
if (ble_gattc_cache_conn_mem == NULL) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
@@ -2181,7 +2182,7 @@ ble_gattc_cache_conn_init()
|
||||
goto err;
|
||||
}
|
||||
|
||||
ble_gattc_cache_conn_svc_mem = malloc(
|
||||
ble_gattc_cache_conn_svc_mem = nimble_platform_mem_malloc(
|
||||
OS_MEMPOOL_BYTES(max_svcs, sizeof(struct ble_gattc_cache_conn_svc)));
|
||||
if (ble_gattc_cache_conn_svc_mem == NULL) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
@@ -2197,7 +2198,7 @@ ble_gattc_cache_conn_init()
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(BLE_GATT_CACHING_INCLUDE_SERVICES)
|
||||
ble_gattc_cache_conn_incl_svc_mem = malloc(
|
||||
ble_gattc_cache_conn_incl_svc_mem = nimble_platform_mem_malloc(
|
||||
OS_MEMPOOL_BYTES(max_incl_svcs, sizeof(struct ble_gattc_cache_conn_incl_svc)));
|
||||
if (ble_gattc_cache_conn_incl_svc_mem == NULL) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
@@ -2212,7 +2213,7 @@ ble_gattc_cache_conn_init()
|
||||
goto err;
|
||||
}
|
||||
#endif
|
||||
ble_gattc_cache_conn_chr_mem = malloc(
|
||||
ble_gattc_cache_conn_chr_mem = nimble_platform_mem_malloc(
|
||||
OS_MEMPOOL_BYTES(max_chrs, sizeof(struct ble_gattc_cache_conn_chr)));
|
||||
if (ble_gattc_cache_conn_chr_mem == NULL) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
@@ -2227,7 +2228,7 @@ ble_gattc_cache_conn_init()
|
||||
goto err;
|
||||
}
|
||||
|
||||
ble_gattc_cache_conn_dsc_mem = malloc(
|
||||
ble_gattc_cache_conn_dsc_mem = nimble_platform_mem_malloc(
|
||||
OS_MEMPOOL_BYTES(max_dscs, sizeof(struct ble_gattc_cache_conn_dsc)));
|
||||
if (ble_gattc_cache_conn_dsc_mem == NULL) {
|
||||
rc = BLE_HS_ENOMEM;
|
||||
|
||||
@@ -3065,7 +3065,7 @@ void ble_gatts_free_svcs(void)
|
||||
/* Ensure the memory is freed only if it was previously allocated */
|
||||
if (ble_gatts_svc_defs != NULL) {
|
||||
/* Free the memory for the service definitions */
|
||||
free(ble_gatts_svc_defs);
|
||||
nimble_platform_mem_free(ble_gatts_svc_defs);
|
||||
/* Set the pointer to NULL to avoid dangling pointer */
|
||||
ble_gatts_svc_defs = NULL;
|
||||
/* Reset the number of service definitions to 0 */
|
||||
|
||||
@@ -40,6 +40,8 @@
|
||||
#include "host/ble_hs_iso.h"
|
||||
#endif /* MYNEWT_VAL(BLE_ISO) */
|
||||
|
||||
#include "esp_nimble_mem.h"
|
||||
|
||||
#define BLE_HS_HCI_EVT_COUNT (MYNEWT_VAL(BLE_TRANSPORT_EVT_COUNT) + \
|
||||
MYNEWT_VAL(BLE_TRANSPORT_EVT_DISCARDABLE_COUNT))
|
||||
|
||||
@@ -723,12 +725,12 @@ ble_hs_rx_data(struct os_mbuf *om, void *arg)
|
||||
|
||||
#if ((BT_HCI_LOG_INCLUDED == TRUE) && SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED)
|
||||
uint16_t len = OS_MBUF_PKTHDR(om)->omp_len + 1;
|
||||
uint8_t *data = (uint8_t *)malloc(len);
|
||||
uint8_t *data = (uint8_t *)nimble_platform_mem_malloc(len);
|
||||
assert(data != NULL);
|
||||
data[0] = 0x02;
|
||||
os_mbuf_copydata(om, 0, len - 1, &data[1]);
|
||||
bt_hci_log_record_hci_data(HCI_LOG_DATA_TYPE_C2H_ACL, &data[1], len - 1);
|
||||
free(data);
|
||||
nimble_platform_mem_free(data);
|
||||
#endif // (BT_HCI_LOG_INCLUDED == TRUE)
|
||||
|
||||
/* If flow control is enabled, mark this packet with its corresponding
|
||||
|
||||
@@ -1691,7 +1691,7 @@ void ble_adv_list_deinit(void)
|
||||
|
||||
SLIST_FOREACH_SAFE(device, &ble_adv_list, next, temp) {
|
||||
SLIST_REMOVE(&ble_adv_list, device, ble_addr_list_entry, next);
|
||||
free(device);
|
||||
nimble_platform_mem_free(device);
|
||||
}
|
||||
|
||||
ble_npl_mutex_release(&adv_list_lock);
|
||||
@@ -1743,7 +1743,7 @@ void ble_adv_list_refresh(void)
|
||||
|
||||
SLIST_FOREACH_SAFE(device, &ble_adv_list, next, temp) {
|
||||
SLIST_REMOVE(&ble_adv_list, device, ble_addr_list_entry, next);
|
||||
free(device);
|
||||
nimble_platform_mem_free(device);
|
||||
}
|
||||
|
||||
ble_npl_mutex_release(&adv_list_lock);
|
||||
|
||||
@@ -181,7 +181,7 @@ ble_hs_hci_iso_tx_now(uint16_t conn_handle, const uint8_t *sdu, uint16_t sdu_len
|
||||
|
||||
dlh_len = (ts_flag ? BLE_HCI_ISO_DATA_LOAD_TS_SZ : 0) + BLE_HCI_ISO_DATA_LOAD_HDR_SZ;
|
||||
|
||||
frag = malloc(BLE_HCI_ISO_DATA_HDR_SZ + dlh_len + sdu_len);
|
||||
frag = nimble_platform_mem_malloc(BLE_HCI_ISO_DATA_HDR_SZ + dlh_len + sdu_len);
|
||||
if (frag == NULL) {
|
||||
return BLE_HS_ENOMEM;
|
||||
}
|
||||
|
||||
@@ -237,7 +237,7 @@ ble_hci_sock_acl_tx(struct os_mbuf *om)
|
||||
len += m->om_len;
|
||||
}
|
||||
|
||||
buf = (uint8_t *)malloc(len);
|
||||
buf = (uint8_t *)nimble_platform_mem_malloc(len);
|
||||
|
||||
buf[0] = BLE_HCI_UART_H4_ACL;
|
||||
|
||||
@@ -348,7 +348,7 @@ ble_hci_sock_cmdevt_tx(uint8_t *hci_ev, uint8_t h4_type)
|
||||
STATS_INC(hci_sock_stats, omsg);
|
||||
STATS_INCN(hci_sock_stats, obytes, len + 1);
|
||||
|
||||
buf = (uint8_t *)malloc(len + 1);
|
||||
buf = (uint8_t *)nimble_platform_mem_malloc(len + 1);
|
||||
|
||||
buf[0] = h4_type;
|
||||
memcpy(&buf[1], hci_ev, len);
|
||||
@@ -783,7 +783,7 @@ ble_hci_sock_init_task(void)
|
||||
{
|
||||
os_stack_t *pstack;
|
||||
|
||||
pstack = malloc(sizeof(os_stack_t)*BLE_SOCK_STACK_SIZE);
|
||||
pstack = nimble_platform_mem_malloc(sizeof(os_stack_t)*BLE_SOCK_STACK_SIZE);
|
||||
assert(pstack);
|
||||
os_task_init(&ble_sock_task, "hci_sock", ble_hci_sock_ack_handler, NULL,
|
||||
MYNEWT_VAL(BLE_SOCK_TASK_PRIO), BLE_NPL_TIME_FOREVER, pstack,
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
#include "hal/hal_uart.h"
|
||||
#include "esp_log.h"
|
||||
#include "esp_attr.h"
|
||||
#include "esp_nimble_mem.h"
|
||||
|
||||
static const char *TAG = "hal_uart";
|
||||
|
||||
@@ -54,7 +55,7 @@ void hal_uart_deinit_cbs(void)
|
||||
static void IRAM_ATTR hci_uart_rx_task(void *pvParameters)
|
||||
{
|
||||
uart_event_t event;
|
||||
uint8_t* dtmp = (uint8_t*) malloc(RD_BUF_SIZE);
|
||||
uint8_t* dtmp = (uint8_t*) nimble_platform_mem_malloc(RD_BUF_SIZE);
|
||||
while(hci_uart.uart_opened) {
|
||||
//Waiting for UART event.
|
||||
if(xQueueReceive(hci_uart.evt_queue, (void * )&event, (TickType_t)portMAX_DELAY)) {
|
||||
@@ -108,7 +109,7 @@ static void IRAM_ATTR hci_uart_rx_task(void *pvParameters)
|
||||
}
|
||||
}
|
||||
}
|
||||
free(dtmp);
|
||||
nimble_platform_mem_free(dtmp);
|
||||
dtmp = NULL;
|
||||
hci_uart.rx_task_handler = NULL;
|
||||
vTaskDelete(NULL);
|
||||
|
||||
@@ -36,6 +36,8 @@
|
||||
|
||||
#include "soc/soc_caps.h"
|
||||
|
||||
#include "esp_nimble_mem.h"
|
||||
|
||||
portMUX_TYPE ble_port_mutex = portMUX_INITIALIZER_UNLOCKED;
|
||||
|
||||
#if CONFIG_BT_NIMBLE_USE_ESP_TIMER
|
||||
@@ -179,7 +181,7 @@ npl_freertos_event_init(struct ble_npl_event *ev, ble_npl_event_fn *fn,
|
||||
}
|
||||
#else
|
||||
if(!ev->event) {
|
||||
ev->event = malloc(sizeof(struct ble_npl_event_freertos));
|
||||
ev->event = nimble_platform_mem_malloc(sizeof(struct ble_npl_event_freertos));
|
||||
}
|
||||
#endif
|
||||
event = (struct ble_npl_event_freertos *)ev->event;
|
||||
@@ -197,7 +199,7 @@ npl_freertos_event_deinit(struct ble_npl_event *ev)
|
||||
#if OS_MEM_ALLOC
|
||||
os_memblock_put(&ble_freertos_ev_pool,ev->event);
|
||||
#else
|
||||
free(ev->event);
|
||||
nimble_platform_mem_free(ev->event);
|
||||
#endif
|
||||
ev->event = NULL;
|
||||
}
|
||||
@@ -226,7 +228,7 @@ npl_freertos_eventq_init(struct ble_npl_eventq *evq)
|
||||
}
|
||||
#else
|
||||
if(!evq->eventq) {
|
||||
evq->eventq = malloc(sizeof(struct ble_npl_eventq_freertos));
|
||||
evq->eventq = nimble_platform_mem_malloc(sizeof(struct ble_npl_eventq_freertos));
|
||||
eventq = (struct ble_npl_eventq_freertos*)evq->eventq;
|
||||
BLE_LL_ASSERT(eventq);
|
||||
|
||||
@@ -247,7 +249,7 @@ npl_freertos_eventq_deinit(struct ble_npl_eventq *evq)
|
||||
#if OS_MEM_ALLOC
|
||||
os_memblock_put(&ble_freertos_evq_pool,eventq);
|
||||
#else
|
||||
free((void *)eventq);
|
||||
nimble_platform_mem_free((void *)eventq);
|
||||
#endif
|
||||
evq->eventq = NULL;
|
||||
}
|
||||
@@ -411,7 +413,7 @@ npl_freertos_mutex_init(struct ble_npl_mutex *mu)
|
||||
}
|
||||
#else
|
||||
if(!mu->mutex) {
|
||||
mu->mutex = malloc(sizeof(struct ble_npl_mutex_freertos));
|
||||
mu->mutex = nimble_platform_mem_malloc(sizeof(struct ble_npl_mutex_freertos));
|
||||
mutex = (struct ble_npl_mutex_freertos *)mu->mutex;
|
||||
|
||||
if (!mutex) {
|
||||
@@ -442,7 +444,7 @@ npl_freertos_mutex_deinit(struct ble_npl_mutex *mu)
|
||||
#if OS_MEM_ALLOC
|
||||
os_memblock_put(&ble_freertos_mutex_pool,mutex);
|
||||
#else
|
||||
free((void *)mutex);
|
||||
nimble_platform_mem_free((void *)mutex);
|
||||
#endif
|
||||
mu->mutex = NULL;
|
||||
|
||||
@@ -558,7 +560,7 @@ npl_freertos_sem_init(struct ble_npl_sem *sem, uint16_t tokens)
|
||||
}
|
||||
#else
|
||||
if(!sem->sem) {
|
||||
sem->sem = malloc(sizeof(struct ble_npl_sem_freertos));
|
||||
sem->sem = nimble_platform_mem_malloc(sizeof(struct ble_npl_sem_freertos));
|
||||
semaphor = (struct ble_npl_sem_freertos *)sem->sem;
|
||||
|
||||
if (!semaphor) {
|
||||
@@ -589,7 +591,7 @@ npl_freertos_sem_deinit(struct ble_npl_sem *sem)
|
||||
#if OS_MEM_ALLOC
|
||||
os_memblock_put(&ble_freertos_sem_pool,semaphor);
|
||||
#else
|
||||
free((void *)semaphor);
|
||||
nimble_platform_mem_free((void *)semaphor);
|
||||
#endif
|
||||
sem->sem = NULL;
|
||||
|
||||
@@ -751,7 +753,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
|
||||
#else
|
||||
|
||||
if(!co->co) {
|
||||
co->co = malloc(sizeof(struct ble_npl_callout_freertos));
|
||||
co->co = nimble_platform_mem_malloc(sizeof(struct ble_npl_callout_freertos));
|
||||
callout = (struct ble_npl_callout_freertos *)co->co;
|
||||
if (!callout) {
|
||||
return -1;
|
||||
@@ -771,7 +773,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
|
||||
|
||||
if (esp_timer_create(&create_args, &callout->handle) != ESP_OK) {
|
||||
ble_npl_event_deinit(&callout->ev);
|
||||
free((void *)callout);
|
||||
nimble_platform_mem_free((void *)callout);
|
||||
co->co = NULL;
|
||||
return -1;
|
||||
}
|
||||
@@ -780,7 +782,7 @@ npl_freertos_callout_init(struct ble_npl_callout *co, struct ble_npl_eventq *evq
|
||||
|
||||
if (!callout->handle) {
|
||||
ble_npl_event_deinit(&callout->ev);
|
||||
free((void *)callout);
|
||||
nimble_platform_mem_free((void *)callout);
|
||||
co->co = NULL;
|
||||
return -1;
|
||||
}
|
||||
@@ -821,7 +823,7 @@ npl_freertos_callout_deinit(struct ble_npl_callout *co)
|
||||
#if OS_MEM_ALLOC
|
||||
os_memblock_put(&ble_freertos_co_pool,callout);
|
||||
#else
|
||||
free((void *)callout);
|
||||
nimble_platform_mem_free((void *)callout);
|
||||
#endif
|
||||
|
||||
co->co = NULL;
|
||||
@@ -1137,7 +1139,7 @@ struct npl_funcs_t * npl_freertos_funcs_get(void)
|
||||
|
||||
void npl_freertos_funcs_init(void)
|
||||
{
|
||||
npl_funcs = (struct npl_funcs_t *)malloc(sizeof(struct npl_funcs_t));
|
||||
npl_funcs = (struct npl_funcs_t *)nimble_platform_mem_malloc(sizeof(struct npl_funcs_t));
|
||||
if(!npl_funcs) {
|
||||
printf("npl funcs init failed\n");
|
||||
assert(0);
|
||||
@@ -1150,26 +1152,26 @@ int npl_freertos_mempool_init(void)
|
||||
int rc = -1;
|
||||
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
|
||||
ble_freertos_ev_buf = malloc(OS_MEMPOOL_SIZE(BLE_TOTAL_EV_COUNT, sizeof (struct ble_npl_event_freertos)) * sizeof(os_membuf_t));
|
||||
ble_freertos_ev_buf = nimble_platform_mem_malloc(OS_MEMPOOL_SIZE(BLE_TOTAL_EV_COUNT, sizeof (struct ble_npl_event_freertos)) * sizeof(os_membuf_t));
|
||||
if(!ble_freertos_ev_buf) {
|
||||
goto _error;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_CONTROLLER_ENABLED
|
||||
ble_freertos_evq_buf = malloc(OS_MEMPOOL_SIZE(BLE_TOTAL_EVQ_COUNT, sizeof (struct ble_npl_eventq_freertos)) * sizeof(os_membuf_t));
|
||||
ble_freertos_evq_buf = nimble_platform_mem_malloc(OS_MEMPOOL_SIZE(BLE_TOTAL_EVQ_COUNT, sizeof (struct ble_npl_eventq_freertos)) * sizeof(os_membuf_t));
|
||||
if(!ble_freertos_evq_buf) {
|
||||
goto _error;
|
||||
}
|
||||
ble_freertos_co_buf = malloc(OS_MEMPOOL_SIZE(BLE_TOTAL_CO_COUNT, sizeof (struct ble_npl_callout_freertos)) * sizeof(os_membuf_t));
|
||||
ble_freertos_co_buf = nimble_platform_mem_malloc(OS_MEMPOOL_SIZE(BLE_TOTAL_CO_COUNT, sizeof (struct ble_npl_callout_freertos)) * sizeof(os_membuf_t));
|
||||
if(!ble_freertos_co_buf) {
|
||||
goto _error;
|
||||
}
|
||||
ble_freertos_sem_buf = malloc(OS_MEMPOOL_SIZE(BLE_TOTAL_SEM_COUNT, sizeof (struct ble_npl_sem_freertos)) * sizeof(os_membuf_t));
|
||||
ble_freertos_sem_buf = nimble_platform_mem_malloc(OS_MEMPOOL_SIZE(BLE_TOTAL_SEM_COUNT, sizeof (struct ble_npl_sem_freertos)) * sizeof(os_membuf_t));
|
||||
if(!ble_freertos_sem_buf) {
|
||||
goto _error;
|
||||
}
|
||||
ble_freertos_mutex_buf = malloc( OS_MEMPOOL_SIZE(BLE_TOTAL_MUTEX_COUNT, sizeof (struct ble_npl_mutex_freertos)) * sizeof(os_membuf_t));
|
||||
ble_freertos_mutex_buf = nimble_platform_mem_malloc( OS_MEMPOOL_SIZE(BLE_TOTAL_MUTEX_COUNT, sizeof (struct ble_npl_mutex_freertos)) * sizeof(os_membuf_t));
|
||||
if(!ble_freertos_mutex_buf) {
|
||||
goto _error;
|
||||
}
|
||||
@@ -1214,26 +1216,26 @@ _error:
|
||||
|
||||
#if CONFIG_BT_CONTROLLER_ENABLED
|
||||
if(ble_freertos_evq_buf) {
|
||||
free(ble_freertos_evq_buf);
|
||||
nimble_platform_mem_free(ble_freertos_evq_buf);
|
||||
ble_freertos_evq_buf = NULL;
|
||||
}
|
||||
if(ble_freertos_co_buf) {
|
||||
free(ble_freertos_co_buf);
|
||||
nimble_platform_mem_free(ble_freertos_co_buf);
|
||||
ble_freertos_co_buf = NULL;
|
||||
}
|
||||
if(ble_freertos_sem_buf) {
|
||||
free(ble_freertos_sem_buf);
|
||||
nimble_platform_mem_free(ble_freertos_sem_buf);
|
||||
ble_freertos_sem_buf = NULL;
|
||||
}
|
||||
if(ble_freertos_mutex_buf) {
|
||||
free(ble_freertos_mutex_buf);
|
||||
nimble_platform_mem_free(ble_freertos_mutex_buf);
|
||||
ble_freertos_mutex_buf = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
|
||||
if(ble_freertos_ev_buf) {
|
||||
free(ble_freertos_ev_buf);
|
||||
nimble_platform_mem_free(ble_freertos_ev_buf);
|
||||
ble_freertos_ev_buf = NULL;
|
||||
}
|
||||
return -1;
|
||||
@@ -1247,26 +1249,26 @@ void npl_freertos_mempool_deinit(void)
|
||||
{
|
||||
#if SOC_ESP_NIMBLE_CONTROLLER && CONFIG_BT_CONTROLLER_ENABLED
|
||||
if(ble_freertos_ev_buf) {
|
||||
free(ble_freertos_ev_buf);
|
||||
nimble_platform_mem_free(ble_freertos_ev_buf);
|
||||
ble_freertos_ev_buf = NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if CONFIG_BT_CONTROLLER_ENABLED
|
||||
if(ble_freertos_evq_buf) {
|
||||
free(ble_freertos_evq_buf);
|
||||
nimble_platform_mem_free(ble_freertos_evq_buf);
|
||||
ble_freertos_evq_buf = NULL;
|
||||
}
|
||||
if(ble_freertos_co_buf) {
|
||||
free(ble_freertos_co_buf);
|
||||
nimble_platform_mem_free(ble_freertos_co_buf);
|
||||
ble_freertos_co_buf = NULL;
|
||||
}
|
||||
if(ble_freertos_sem_buf) {
|
||||
free(ble_freertos_sem_buf);
|
||||
nimble_platform_mem_free(ble_freertos_sem_buf);
|
||||
ble_freertos_sem_buf = NULL;
|
||||
}
|
||||
if(ble_freertos_mutex_buf) {
|
||||
free(ble_freertos_mutex_buf);
|
||||
nimble_platform_mem_free(ble_freertos_mutex_buf);
|
||||
ble_freertos_mutex_buf = NULL;
|
||||
}
|
||||
#endif
|
||||
@@ -1275,7 +1277,7 @@ void npl_freertos_mempool_deinit(void)
|
||||
void npl_freertos_funcs_deinit(void)
|
||||
{
|
||||
if (npl_funcs) {
|
||||
free(npl_funcs);
|
||||
nimble_platform_mem_free(npl_funcs);
|
||||
}
|
||||
npl_funcs = NULL;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user