1 // Copyright 2015-2016 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.
14 #ifndef HEAP_ALLOC_CAPS_H
15 #define HEAP_ALLOC_CAPS_H
25 * @brief Flags to indicate the capabilities of the various memory systems
27 #define MALLOC_CAP_EXEC (1<<0) ///< Memory must be able to run executable code
28 #define MALLOC_CAP_32BIT (1<<1) ///< Memory must allow for aligned 32-bit data accesses
29 #define MALLOC_CAP_8BIT (1<<2) ///< Memory must allow for 8/16/...-bit data accesses
30 #define MALLOC_CAP_DMA (1<<3) ///< Memory must be able to accessed by DMA
31 #define MALLOC_CAP_PID2 (1<<4) ///< Memory must be mapped to PID2 memory space
32 #define MALLOC_CAP_PID3 (1<<5) ///< Memory must be mapped to PID3 memory space
33 #define MALLOC_CAP_PID4 (1<<6) ///< Memory must be mapped to PID4 memory space
34 #define MALLOC_CAP_PID5 (1<<7) ///< Memory must be mapped to PID5 memory space
35 #define MALLOC_CAP_PID6 (1<<8) ///< Memory must be mapped to PID6 memory space
36 #define MALLOC_CAP_PID7 (1<<9) ///< Memory must be mapped to PID7 memory space
37 #define MALLOC_CAP_SPISRAM (1<<10) ///< Memory must be in SPI SRAM
38 #define MALLOC_CAP_INVALID (1<<31) ///< Memory can't be used / list end marker
42 * @brief Initialize the capability-aware heap allocator.
44 * For the ESP32, this is called once in the startup code.
46 void heap_alloc_caps_init();
49 * @brief Enable the memory region where the startup stacks are located for allocation
51 * On startup, the pro/app CPUs have a certain memory region they use as stack, so we
52 * cannot do allocations in the regions these stack frames are. When FreeRTOS is
53 * completely started, they do not use that memory anymore and allocation there can
56 void heap_alloc_enable_nonos_stack_tag();
59 * @brief Allocate a chunk of memory which has the given capabilities
61 * @param xWantedSize Size, in bytes, of the amount of memory to allocate
62 * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
63 * of memory to be returned
65 * @return A pointer to the memory allocated on success, NULL on failure
67 void *pvPortMallocCaps(size_t xWantedSize, uint32_t caps);
70 * @brief Get the total free size of all the regions that have the given capabilities
72 * This function takes all regions capable of having the given capabilities allocated in them
73 * and adds up the free space they have.
75 * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
78 * @return Amount of free bytes in the regions
80 size_t xPortGetFreeHeapSizeCaps( uint32_t caps );
83 * @brief Get the total minimum free memory of all regions with the given capabilities
85 * This adds all the lowmarks of the regions capable of delivering the memory with the
88 * @param caps Bitwise OR of MALLOC_CAP_* flags indicating the type
91 * @return Amount of free bytes in the regions
93 size_t xPortGetMinimumEverFreeHeapSizeCaps( uint32_t caps );
98 * @brief Convenience function to check if a pointer is DMA-capable.
100 * @param ptr Pointer to check
102 * @return True if DMA-capable, false if not.
104 static inline bool esp_ptr_dma_capable( const void *ptr )
106 return ( (int)ptr >= 0x3FFAE000 && (int)ptr < 0x40000000 );
113 #endif //HEAP_ALLOC_CAPS_H