E:/Projects/AvrLib/kernel/heapmanager.c File Reference

#include <stdlib.h>
#include "HeapManager.h"
#include <avr/io.h>

Include dependency graph for heapmanager.c:

Go to the source code of this file.

Functions

void * HeapAlloc (HEAP_BLOCK *pHB, size_t len)
 This function is used to allocate memory from a heap.
void HeapFree (HEAP_BLOCK *pHB, void *p)
 Free a block of memory back to a heap.
HEAP_BLOCKHeapInit (char *start, char *end)
 Initialize a heap block object.


Detailed Description

Definition in file heapmanager.c.


Function Documentation

void* HeapAlloc ( HEAP_BLOCK pHB,
size_t  len 
)

This function is used to allocate memory from a heap.

The code for this function was lifted directly out of the WINAVR libc library. This was originally malloc writen by Joerg Wunsch and modified by Jim Patchell to turn it into a bit more of an object oriented function. The object is a HEAP_BLOCK.

Parameters:
pHB pointer to a heap block object
len size of desired memory block
Returns:
pointer to memory block, or NULL on FAIL!

Definition at line 68 of file heapmanager.c.

References HEAP_BLOCK::__flp, HEAP_BLOCK::Blocker, HEAP_BLOCK::BrkVal, HEAP_BLOCK::End, HEAP_BLOCK::Margin, __freelist::nx, PendSemaphore(), PostSemaphore(), STACK_POINTER, HEAP_BLOCK::Start, and __freelist::sz.

Referenced by AllocStack().

void HeapFree ( HEAP_BLOCK pHB,
void *  p 
)

Free a block of memory back to a heap.

The code for this function was lifted directly out of the WINAVR libc library. This was originally malloc writen by Joerg Wunsch and modified by Jim Patchell to turn it into a bit more of an object oriented function. The object is a HEAP_BLOCK.

Parameters:
pHB pointer to a HEAP_BLOCK object to free memory to
p pointer to the block of memory to free

Definition at line 209 of file heapmanager.c.

References HEAP_BLOCK::__flp, HEAP_BLOCK::Blocker, __freelist::nx, PendSemaphore(), PostSemaphore(), and __freelist::sz.

HEAP_BLOCK* HeapInit ( char *  start,
char *  end 
)

Initialize a heap block object.

this function is used to initialize a heap block. The user passes this function a pointer to the start and end if a block of memory that is going to be used as the heap. This function does a lot of things to that memory. One is to create a semaphore in the block of memory so that calling HeapAlloc and HeapFree will be thread safe.

So, one must remember that not all of the block will be available for allocation.

Parameters:
start pointer to start of memory to use for heap
end pointer to end of memory to use for heap
Returns:
pointer to HEAP_BLOCK object upon success

Definition at line 298 of file heapmanager.c.

References HEAP_BLOCK::__flp, HEAP_BLOCK::Blocker, HEAP_BLOCK::BrkVal, CreateSemaphore(), HEAP_BLOCK::End, HEAP_BLOCK::Margin, SEMAPHORE_MODE_BLOCKING, and HEAP_BLOCK::Start.

Referenced by OSInit().


Generated on Sun Aug 31 13:30:58 2008 for FrankenRTOS by  doxygen 1.5.6