AM261x MCU+ SDK: Heap

| AM261x MCU+ SDK 26.00.00 |

Heap

# Features Supported

- Ability to create multiple user defined heaps
- Alloc and free APIs
- Detailed heap statistics
- Thread safe APIs with RTOS
- Minimum alignment of HeapP_BYTE_ALIGNMENT for all allocations

# Features NOT Supported

- Memory allocation with alignment as a input. Users should allocate extra and align after allocation.

# Important Usage Guidelines

NA

# Example Usage

Include the below file to access the APIs,

#include <stdio.h>
#include <kernel/dpl/HeapP.h>
#include <kernel/dpl/DebugP.h>

Example usage to define a heap memory and heap handle

/* Heap memory, recommend to align to HeapP_BYTE_ALIGNMENT */
#define MY_HEAP_MEM_SIZE (32*1024u)
uint8_t gMyHeapMem[MY_HEAP_MEM_SIZE] __attribute__((aligned(HeapP_BYTE_ALIGNMENT)));
/* Heap handle */
HeapP_Object gMyHeapObj;

Example usage to create a heap,

HeapP_construct(&gMyHeapObj, gMyHeapMem, MY_HEAP_MEM_SIZE);

Example usage to alloc and free memory,

void *ptr;
/* allocate memory from heap */
ptr = HeapP_alloc(&gMyHeapObj, 1024u);
DebugP_assert(ptr!=NULL);
/* use the memory */
/* free the memory back to the same heap */
HeapP_free(&gMyHeapObj, ptr);

# API

APIs for Heap management

HeapP_alloc
void * HeapP_alloc(HeapP_Object *heapObj, size_t allocSize)
Alloc memory from user defined heap.
HeapP.h
__attribute__
struct lld_sockaddr __attribute__
This is the SecureBoot Stream type which holds the data for a specific bootloader to HSM call....
DebugP.h
HeapP_free
int32_t HeapP_free(HeapP_Object *heapObj, void *ptr)
Free memory from user defined heap.
DebugP_assert
#define DebugP_assert(expression)
Function to call for assert check.
Definition: DebugP.h:187
HeapP_construct
int32_t HeapP_construct(HeapP_Object *heapObj, void *heapAddr, size_t heapSize)
Create a user defined heap.
HeapP_Object
Opaque heap object used with the heap APIs.
Definition: HeapP.h:128
HeapP_BYTE_ALIGNMENT
#define HeapP_BYTE_ALIGNMENT
Minimum alignment for heap allocations, in units of bytes.
Definition: HeapP.h:56