Zephyr Project API 3.7.0
A Scalable Open Source RTOS
|
Shared Multi-Heap (SMH) interface. More...
Data Structures | |
struct | shared_multi_heap_region |
SMH region struct. More... | |
Macros | |
#define | MAX_SHARED_MULTI_HEAP_ATTR SMH_REG_ATTR_NUM |
Maximum number of standard attributes. | |
Enumerations | |
enum | shared_multi_heap_attr { SMH_REG_ATTR_CACHEABLE , SMH_REG_ATTR_NON_CACHEABLE , SMH_REG_ATTR_NUM } |
SMH region attributes enumeration type. More... | |
Functions | |
int | shared_multi_heap_pool_init (void) |
Init the pool. | |
void * | shared_multi_heap_alloc (enum shared_multi_heap_attr attr, size_t bytes) |
Allocate memory from the memory shared multi-heap pool. | |
void * | shared_multi_heap_aligned_alloc (enum shared_multi_heap_attr attr, size_t align, size_t bytes) |
Allocate aligned memory from the memory shared multi-heap pool. | |
void | shared_multi_heap_free (void *block) |
Free memory from the shared multi-heap pool. | |
int | shared_multi_heap_add (struct shared_multi_heap_region *region, void *user_data) |
Add an heap region to the shared multi-heap pool. | |
Shared Multi-Heap (SMH) interface.
The shared multi-heap manager uses the multi-heap allocator to manage a set of memory regions with different capabilities / attributes (cacheable, non-cacheable, etc...).
All the different regions can be added at run-time to the shared multi-heap pool providing an opaque "attribute" value (an integer or enum value) that can be used by drivers or applications to request memory with certain capabilities.
This framework is commonly used as follow:
#define MAX_SHARED_MULTI_HEAP_ATTR SMH_REG_ATTR_NUM |
#include <include/zephyr/multi_heap/shared_multi_heap.h>
Maximum number of standard attributes.
#include <include/zephyr/multi_heap/shared_multi_heap.h>
SMH region attributes enumeration type.
Enumeration type for some common memory region attributes.
Enumerator | |
---|---|
SMH_REG_ATTR_CACHEABLE | cacheable |
SMH_REG_ATTR_NON_CACHEABLE | non-cacheable |
SMH_REG_ATTR_NUM | must be the last item |
int shared_multi_heap_add | ( | struct shared_multi_heap_region * | region, |
void * | user_data | ||
) |
#include <include/zephyr/multi_heap/shared_multi_heap.h>
Add an heap region to the shared multi-heap pool.
This adds a shared multi-heap region to the multi-heap pool.
user_data | pointer to any data for the heap. |
region | pointer to the memory region to be added. |
0 | on success. |
-EINVAL | when the region attribute is out-of-bound. |
-ENOMEM | when there are no more heaps available. |
other | errno codes |
void * shared_multi_heap_aligned_alloc | ( | enum shared_multi_heap_attr | attr, |
size_t | align, | ||
size_t | bytes | ||
) |
#include <include/zephyr/multi_heap/shared_multi_heap.h>
Allocate aligned memory from the memory shared multi-heap pool.
Allocates a block of memory of the specified size in bytes and with a specified capability / attribute. Takes an additional parameter specifying a power of two alignment in bytes.
attr | capability / attribute requested for the memory block. |
align | power of two alignment for the returned pointer, in bytes. |
bytes | requested size of the allocation in bytes. |
ptr | a valid pointer to heap memory. |
err | NULL if no memory is available. |
void * shared_multi_heap_alloc | ( | enum shared_multi_heap_attr | attr, |
size_t | bytes | ||
) |
#include <include/zephyr/multi_heap/shared_multi_heap.h>
Allocate memory from the memory shared multi-heap pool.
Allocates a block of memory of the specified size in bytes and with a specified capability / attribute. The opaque attribute parameter is used by the backend to select the correct heap to allocate memory from.
attr | capability / attribute requested for the memory block. |
bytes | requested size of the allocation in bytes. |
ptr | a valid pointer to heap memory. |
err | NULL if no memory is available. |
void shared_multi_heap_free | ( | void * | block | ) |
#include <include/zephyr/multi_heap/shared_multi_heap.h>
Free memory from the shared multi-heap pool.
Used to free the passed block of memory that must be the return value of a previously call to shared_multi_heap_alloc or shared_multi_heap_aligned_alloc.
block | block to free, must be a pointer to a block allocated by shared_multi_heap_alloc or shared_multi_heap_aligned_alloc. |
int shared_multi_heap_pool_init | ( | void | ) |
#include <include/zephyr/multi_heap/shared_multi_heap.h>
Init the pool.
This must be the first function to be called to initialize the shared multi-heap pool. All the individual heaps must be added later with shared_multi_heap_add.
0 | on success. |
-EALREADY | when the pool was already inited. |
other | errno codes |