AM263Px MCU+ SDK  10.01.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>

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_free
void HeapP_free(HeapP_Object *heap, void *ptr)
Free memory from user defined heap.
HeapP.h
HeapP_construct
void HeapP_construct(HeapP_Object *heap, void *heapAddr, size_t heapSize)
Create a user defined heap.
HeapP_alloc
void * HeapP_alloc(HeapP_Object *heap, size_t allocSize)
Alloc memory from user defined heap.
__attribute__
struct lld_sockaddr __attribute__
This is the SecureBoot Stream type which holds the data for a specific bootloader to HSM call....
DebugP.h
DebugP_assert
#define DebugP_assert(expression)
Function to call for assert check.
Definition: DebugP.h:177
HeapP_Object
Opaque heap object used with the heap APIs.
Definition: HeapP.h:77
HeapP_BYTE_ALIGNMENT
#define HeapP_BYTE_ALIGNMENT
Minimum alignment for heap allocations, in units of bytes.
Definition: HeapP.h:54