1 // Copyright 2015-2022 Espressif Systems (Shanghai) PTE LTD
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
21 #include <sys/queue.h>
22 #include <freertos/FreeRTOS.h>
23 #include <freertos/portmacro.h>
26 #define MEMPOOL_FAIL -1
28 #define MALLOC(x) malloc(x)
29 #define MEM_ALLOC(x) heap_caps_malloc(x, MALLOC_CAP_DMA)
30 #define FREE(x) do { \
39 #define MEMPOOL_NAME_STR_SIZE 32
41 #define MEMPOOL_ALIGNMENT_BYTES 4
42 #define MEMPOOL_ALIGNMENT_MASK (MEMPOOL_ALIGNMENT_BYTES-1)
43 #define IS_MEMPOOL_ALIGNED(VAL) (!((VAL)& MEMPOOL_ALIGNMENT_MASK))
44 #define MEMPOOL_ALIGNED(VAL) ((VAL) + MEMPOOL_ALIGNMENT_BYTES - \
45 ((VAL)& MEMPOOL_ALIGNMENT_MASK))
47 #define MEMSET_REQUIRED 1
48 #define MEMSET_NOT_REQUIRED 0
51 #ifdef CONFIG_ESP_CACHE_MALLOC
52 struct mempool_entry {
53 SLIST_ENTRY(mempool_entry) entries;
56 typedef SLIST_HEAD(slisthead, mempool_entry) mempool_t;
65 struct mempool * mempool_create(uint32_t block_size);
66 void mempool_destroy(struct mempool* mp);
67 void * mempool_alloc(struct mempool* mp, int nbytes, int need_memset);
68 void mempool_free(struct mempool* mp, void *mem);