# cppi_heap.h File Reference

Header file for the linked list library. More...

## Functions

void | cppi_internal_heap_cache_begin (Cppi_HeapDesc *desc)
void * | cppi_internal_heap_malloc (Cppi_HeapDesc *desc, uint32_t size)
void | cppi_internal_heap_free (Cppi_HeapDesc *desc, void *ptr)
void | cppi_internal_heap_release (Cppi_HeapDesc *desc)
void | cppi_internal_heap_add (Cppi_HeapDesc *desc, void *heap, uint32_t heapSize)

## Detailed Description

Header file for the linked list library.

  NOTE: (C) Copyright 2012 Texas Instruments, Inc.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of Texas Instruments Incorporated nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

## Function Documentation

void cppi_internal_heap_add | ( | Cppi_HeapDesc * | desc,
|  | void * | heap,
|  | uint32_t | heapSize |
| ) |  |  |

Description
This function adds a new block to the internal heap.

The new chunk of memory is aligned to desc->alignPow2, which must be large enough so no partial cache lines will be on either side of the block.

Cache assumptions: Caller manages cache for desc. This can be done by calling cppi_internal_heap_cache_begin () BEFORE any items from the heap get dirtied.

Callee writes back any changes.

Function is called inside a semaphore protecting heap from multicore

Qmss_getQosSchedStats*

Parameters:

  `[in]` | desc | Heap descriptor which includes free list and size parameters
  `[in]` | heap | Pre-allocated heap. If NULL, will allocate a new block of heapSize from Cppi_osalMalloc(). This is normally used with a static heap else NULL.
  `[in]` | heapSize | Size of heap, or size to allocate from Cppi_osalMalloc().

Return values:

  | Not | Applicable

void cppi_internal_heap_cache_begin | ( | Cppi_HeapDesc * | desc | ) |

Description
Prepares the cache before accessing heap. This must be called before anything in the heap is dirtied, thus it will usually be called at the beginning of a function that may use the heap functions.

Cache assumptions: Invalidates desc Invalidates head of blockFreeList Invalidates head of allocatedBlockList

Parameters:

  `[in]` | desc | Heap descriptor which includes free list and size parameters

void cppi_internal_heap_free | ( | Cppi_HeapDesc * | desc,
|  | void * | ptr |
| ) |  |  |

Description
This function returns ptr to internal heap free list. It will never return memory through Cppi_osalFree. Memory is only returned on cppi_exit().

Cache assumptions: Caller manages cache for desc. This can be done by calling cppi_internal_heap_cache_begin () BEFORE any items from the heap get dirtied.

Callee writes back any changes.

Function is called inside a semaphore protecting heap from multicore

Parameters:

  `[in]` | desc | Heap descriptor which includes free list and size parameters
  `[in]` | ptr | Previously allocated pointer

Return values:

  | Not | Applicable

void* cppi_internal_heap_malloc | ( | Cppi_HeapDesc * | desc,
|  | uint32_t | size |
| ) |  |  |

Description
This function allocates from internal heap if available. If not available, allocates using Cppi_osalMalloc. If Cppi_osalMalloc fails, or the size is > CPPI_BLOCK_CHUNK_SIZE, then this function CAN return NULL.

Cache assumptions: Caller manages cache for desc. This can be done by calling cppi_internal_heap_cache_begin () BEFORE any items from the heap get dirtied.

Callee writes back any changes.

Function is called inside a semaphore protecting heap from multicore

Parameters:

  `[in]` | desc | Heap descriptor which includes free list and size parameters
  `[in]` | size | Allocated size.

Return values:

  | New | pointer or NULL on error.

void cppi_internal_heap_release | ( | Cppi_HeapDesc * | desc | ) |

Description
This function returns all memory allocated from Cppi_osalMalloc. It should only used as part of cppi_exit().

Cache assumptions: Caller manages cache for desc

Callee manages cache for allocatedBlockList

Nothing from internal heap is dirty (caller wrote back dirty lines)

Function is called inside a semaphore protecting heap from multicore

Parameters:

  `[in]` | desc | Heap descriptor which includes free list and size parameters

Return values:

  | Not | Applicable

Copyright 2012, Texas Instruments Incorporated