2022-06-17 09:37:48 -04:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "esp_attr.h"
|
|
|
|
#include "esp_heap_caps.h"
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
|
|
|
IRAM_ATTR void *bt_osi_mem_malloc(size_t size)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL
|
|
|
|
return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
|
|
|
|
#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL
|
|
|
|
return heap_caps_malloc(size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT);
|
|
|
|
#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT
|
|
|
|
return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
|
|
|
|
#else
|
|
|
|
return malloc(size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
IRAM_ATTR void *bt_osi_mem_calloc(size_t n, size_t size)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL
|
|
|
|
return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
|
|
|
|
#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL
|
|
|
|
return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT);
|
|
|
|
#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT
|
|
|
|
return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT);
|
|
|
|
#else
|
|
|
|
return calloc(n, size);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
IRAM_ATTR void *bt_osi_mem_malloc_internal(size_t size)
|
|
|
|
{
|
2022-11-24 23:35:36 -05:00
|
|
|
return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT|MALLOC_CAP_DMA);
|
2022-06-17 09:37:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
IRAM_ATTR void *bt_osi_mem_calloc_internal(size_t n, size_t size)
|
|
|
|
{
|
2022-11-24 23:35:36 -05:00
|
|
|
return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT|MALLOC_CAP_DMA);
|
2022-06-17 09:37:48 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
IRAM_ATTR void bt_osi_mem_free(void *ptr)
|
|
|
|
{
|
|
|
|
heap_caps_free(ptr);
|
|
|
|
}
|