|
13 | 13 | extern "C" { |
14 | 14 | #endif |
15 | 15 |
|
| 16 | +#if ESP_IDF_VERSION_MAJOR >= 5 |
16 | 17 | // #pragma message "This file should be replaced with bt_osi_mem.h, used here for compatibility" |
17 | 18 |
|
18 | 19 | #include "bt_osi_mem.h" |
19 | 20 | #define nimble_platform_mem_malloc bt_osi_mem_malloc |
20 | 21 | #define nimble_platform_mem_calloc bt_osi_mem_calloc |
21 | 22 | #define nimble_platform_mem_free bt_osi_mem_free |
22 | 23 |
|
| 24 | +#else |
| 25 | + |
| 26 | +#include "esp_attr.h" |
| 27 | +#include "esp_heap_caps.h" |
| 28 | +#include "nimconfig.h" |
| 29 | +#include "../include/esp_nimble_mem.h" |
| 30 | + |
| 31 | +IRAM_ATTR void *nimble_platform_mem_malloc(size_t size) |
| 32 | +{ |
| 33 | +#ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL |
| 34 | + return heap_caps_malloc(size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); |
| 35 | +#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL |
| 36 | + return heap_caps_malloc(size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); |
| 37 | +#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT |
| 38 | + return heap_caps_malloc_prefer(size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); |
| 39 | +#else |
| 40 | + return malloc(size); |
| 41 | +#endif |
| 42 | +} |
| 43 | + |
| 44 | +IRAM_ATTR void *nimble_platform_mem_calloc(size_t n, size_t size) |
| 45 | +{ |
| 46 | +#ifdef CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_INTERNAL |
| 47 | + return heap_caps_calloc(n, size, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); |
| 48 | +#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_EXTERNAL |
| 49 | + return heap_caps_calloc(n, size, MALLOC_CAP_SPIRAM|MALLOC_CAP_8BIT); |
| 50 | +#elif CONFIG_BT_NIMBLE_MEM_ALLOC_MODE_IRAM_8BIT |
| 51 | + return heap_caps_calloc_prefer(n, size, 2, MALLOC_CAP_INTERNAL|MALLOC_CAP_IRAM_8BIT, MALLOC_CAP_INTERNAL|MALLOC_CAP_8BIT); |
| 52 | +#else |
| 53 | + return calloc(n, size); |
| 54 | +#endif |
| 55 | +} |
| 56 | + |
| 57 | +IRAM_ATTR void nimble_platform_mem_free(void *ptr) |
| 58 | +{ |
| 59 | + heap_caps_free(ptr); |
| 60 | +} |
| 61 | + |
23 | 62 | #ifdef __cplusplus |
24 | 63 | } |
25 | 64 | #endif |
|
0 commit comments