Embedded Artistry Framework
Embedded Systems C++ Framework
Macros | Functions | Variables
malloc_freertos.c File Reference
#include <assert.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <malloc.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
Include dependency graph for malloc_freertos.c:

Macros

#define FREERTOS_HEAP_REGION_CNT   2
 NOTE: This FreeRTOS malloc implementation requires heap_5.c. More...
 

Functions

static int cmp_heap (const void *a, const void *b)
 
void malloc_addblock (void *addr, size_t size)
 malloc_addblock must be called before memory allocation calls are made. More...
 
 __attribute__ ((weak))
 
void * malloc (size_t size)
 Allocates size bytes of uninitialized storage. More...
 
void free (void *ptr)
 Deallocates allocated memory space. More...
 

Variables

static const uint8_t heap_region_max = FREERTOS_HEAP_REGION_CNT
 Maximum number of heap regions that can be specified. More...
 
static volatile uint8_t heap_region_cnt = 0
 Current number of allocated heap regions. More...
 
static HeapRegion_t heap_regions [FREERTOS_HEAP_REGION_CNT+1]
 FreeRTOS internal memory pool stucture when using heap_5.c. More...
 
static volatile bool initialized_ = false
 Flag that is used in malloc() to cause competing threads to wait until initialization is completed before allocating memory. More...
 

Macro Definition Documentation

◆ FREERTOS_HEAP_REGION_CNT

#define FREERTOS_HEAP_REGION_CNT   2

NOTE: This FreeRTOS malloc implementation requires heap_5.c.

Please define the correct heap_region for your project.Your application can define this macro to increase the number of heap regions

Function Documentation

◆ __attribute__()

__attribute__ ( (weak)  )

◆ cmp_heap()

static int cmp_heap ( const void *  a,
const void *  b 
)
static

References a, and b.

Referenced by __attribute__().

◆ free()

void free ( void *  ptr)

Deallocates allocated memory space.

Deallocates the space previously allocated by

See also
malloc,
calloc,
realloc. If ptr is a null pointer, the function does nothing.

The behavior is undefined if the value of ptr does not equal a value returned earlier by

See also
malloc,
calloc,
realloc.

The behavior is undefined if the memory area referred to by ptr has already been deallocated, that is, free() or realloc has already been called with ptr as the argument and no calls to malloc, calloc or realloc resulted in a pointer equal to ptr afterwards.

The behavior is undefined if after free returns, an access is made through the pointer ptr (unless another allocation function happened to result in a pointer value equal to ptr)

Parameters
ptrpointer to the memory to deallocate

free should NEVER be called before malloc is init'd

References assert, and initialized_.

◆ malloc()

void* malloc ( size_t  size)

Allocates size bytes of uninitialized storage.

If size is zero, the behavior is implementation defined (null pointer may be returned, or some non-null pointer may be returned that may not be used to access storage, but has to be passed to

See also
free). malloc is thread-safe: it behaves as though only accessing the memory locations visible through its argument, and not any static storage.
Parameters
sizenumber of bytes to allocate
Returns
On success, returns the pointer to the beginning of newly allocated memory. The returned pointer must be deallocated with
See also
free() or
realloc(). On failure, returns a null pointer.

References initialized_, and NULL.

◆ malloc_addblock()

void malloc_addblock ( void *  addr,
size_t  size 
)

malloc_addblock must be called before memory allocation calls are made.

Assign blocks of memory for use by malloc().

In this FreeRTOS implementation, malloc() calls will block until memory has been allocated

References assert, heap_region_cnt, heap_region_max, and heap_regions.

Variable Documentation

◆ heap_region_cnt

volatile uint8_t heap_region_cnt = 0
static

Current number of allocated heap regions.

Referenced by __attribute__(), and malloc_addblock().

◆ heap_region_max

const uint8_t heap_region_max = FREERTOS_HEAP_REGION_CNT
static

Maximum number of heap regions that can be specified.

Referenced by malloc_addblock().

◆ heap_regions

HeapRegion_t heap_regions[FREERTOS_HEAP_REGION_CNT+1]
static

FreeRTOS internal memory pool stucture when using heap_5.c.

The block with the lowest starting address should appear first in the array

An additional block is allocated to serve as a NULL terminator

Referenced by __attribute__(), and malloc_addblock().

◆ initialized_

volatile bool initialized_ = false
static

Flag that is used in malloc() to cause competing threads to wait until initialization is completed before allocating memory.

Referenced by __attribute__(), free(), and malloc().