VSF Documented
esp_heap_caps.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * Clean-room re-implementation of ESP-IDF public API "esp_heap_caps.h".
20 *
21 * This file is authored from the ESP-IDF v5.x public API reference only.
22 * No code is copied or derived from the ESP-IDF source tree. Flag values
23 * and function signatures are kept compatible so that unmodified ESP-IDF
24 * example applications can compile and link against this header.
25 *
26 * VSF backend: all capabilities are served from the single managed heap
27 * (service/heap/vsf_heap). The caps bitmask is therefore accepted but
28 * largely ignored -- allocations succeed whenever the underlying heap
29 * can satisfy the request. This mirrors host / single-pool IDF builds.
30 */
31
32#ifndef __VSF_ESPIDF_ESP_HEAP_CAPS_H__
33#define __VSF_ESPIDF_ESP_HEAP_CAPS_H__
34
35#include <stdint.h>
36#include <stddef.h>
37#include <stdbool.h>
38
39#include "esp_err.h"
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45/*============================ MACROS ========================================*/
46
47/* Bit values fixed by ESP-IDF public API contract. */
48#define MALLOC_CAP_EXEC (1u << 0)
49#define MALLOC_CAP_32BIT (1u << 1)
50#define MALLOC_CAP_8BIT (1u << 2)
51#define MALLOC_CAP_DMA (1u << 3)
52#define MALLOC_CAP_PID2 (1u << 4)
53#define MALLOC_CAP_PID3 (1u << 5)
54#define MALLOC_CAP_PID4 (1u << 6)
55#define MALLOC_CAP_PID5 (1u << 7)
56#define MALLOC_CAP_PID6 (1u << 8)
57#define MALLOC_CAP_PID7 (1u << 9)
58#define MALLOC_CAP_SPIRAM (1u << 10)
59#define MALLOC_CAP_INTERNAL (1u << 11)
60#define MALLOC_CAP_DEFAULT (1u << 12)
61#define MALLOC_CAP_IRAM_8BIT (1u << 13)
62#define MALLOC_CAP_RETENTION (1u << 14)
63#define MALLOC_CAP_RTCRAM (1u << 16)
64#define MALLOC_CAP_TCM (1u << 17)
65#define MALLOC_CAP_INVALID (1u << 31)
66
67/*============================ TYPES =========================================*/
68
69/* Public layout taken from ESP-IDF v5.x API reference. */
70typedef struct multi_heap_info {
79
80/*============================ PROTOTYPES ====================================*/
81
82/*
83 * Caveat: the VSF backend is a single flat heap, so the caps argument is
84 * accepted and validated (MALLOC_CAP_INVALID fails) but otherwise ignored.
85 * All queries report figures for the whole heap regardless of caps.
86 */
87
88extern void *heap_caps_malloc(size_t size, uint32_t caps);
89extern void heap_caps_free(void *ptr);
90extern void *heap_caps_realloc(void *ptr, size_t size, uint32_t caps);
91extern void *heap_caps_calloc(size_t n, size_t size, uint32_t caps);
92
93extern void *heap_caps_aligned_alloc(size_t alignment, size_t size, uint32_t caps);
94extern void heap_caps_aligned_free(void *ptr);
95extern void *heap_caps_aligned_calloc(size_t alignment, size_t n, size_t size, uint32_t caps);
96
97extern size_t heap_caps_get_total_size(uint32_t caps);
98extern size_t heap_caps_get_free_size(uint32_t caps);
101
102extern void heap_caps_get_info(multi_heap_info_t *info, uint32_t caps);
103
104extern bool heap_caps_check_integrity_all(bool print_errors);
105extern bool heap_caps_check_integrity(uint32_t caps, bool print_errors);
106
107#ifdef __cplusplus
108}
109#endif
110
111#endif // __VSF_ESPIDF_ESP_HEAP_CAPS_H__
void * heap_caps_calloc(size_t n, size_t size, uint32_t caps)
Definition esp_heap_caps_port.c:115
void heap_caps_get_info(multi_heap_info_t *info, uint32_t caps)
Definition esp_heap_caps_port.c:241
bool heap_caps_check_integrity_all(bool print_errors)
Definition esp_heap_caps_port.c:267
bool heap_caps_check_integrity(uint32_t caps, bool print_errors)
Definition esp_heap_caps_port.c:274
void heap_caps_aligned_free(void *ptr)
Definition esp_heap_caps_port.c:147
void * heap_caps_aligned_alloc(size_t alignment, size_t size, uint32_t caps)
Definition esp_heap_caps_port.c:135
void * heap_caps_malloc(size_t size, uint32_t caps)
Definition esp_heap_caps_port.c:85
void * heap_caps_aligned_calloc(size_t alignment, size_t n, size_t size, uint32_t caps)
Definition esp_heap_caps_port.c:156
size_t heap_caps_get_largest_free_block(uint32_t caps)
Definition esp_heap_caps_port.c:227
void * heap_caps_realloc(void *ptr, size_t size, uint32_t caps)
Definition esp_heap_caps_port.c:101
size_t heap_caps_get_minimum_free_size(uint32_t caps)
Definition esp_heap_caps_port.c:211
size_t heap_caps_get_free_size(uint32_t caps)
Definition esp_heap_caps_port.c:195
size_t heap_caps_get_total_size(uint32_t caps)
Definition esp_heap_caps_port.c:181
struct multi_heap_info multi_heap_info_t
void heap_caps_free(void *ptr)
Definition esp_heap_caps_port.c:93
unsigned uint32_t
Definition stdint.h:9
Definition esp_heap_caps.h:70
size_t free_blocks
Definition esp_heap_caps.h:76
size_t allocated_blocks
Definition esp_heap_caps.h:75
size_t total_allocated_bytes
Definition esp_heap_caps.h:72
size_t minimum_free_bytes
Definition esp_heap_caps.h:74
size_t total_blocks
Definition esp_heap_caps.h:77
size_t total_free_bytes
Definition esp_heap_caps.h:71
size_t largest_free_block
Definition esp_heap_caps.h:73
uint_fast32_t alignment
Definition vsf_heap.h:172
uint32_t size
Definition vsf_memfs.h:50
Generated from commit: vsfteam/vsf@015f4d1