heap_1.c File Reference

#include <stdlib.h>
#include "FreeRTOS.h"
#include "task.h"

Go to the source code of this file.

Data Structures

union  xRTOS_HEAP

Defines

#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE

Functions

void * pvPortMalloc (size_t xWantedSize)
void vPortFree (void *pv)
void vPortInitialiseBlocks (void)
size_t xPortGetFreeHeapSize (void)

Variables

static union xRTOS_HEAP xHeap
static size_t xNextFreeByte = ( size_t ) 0


Define Documentation

#define MPU_WRAPPERS_INCLUDED_FROM_API_FILE

Definition at line 67 of file heap_1.c.


Function Documentation

void* pvPortMalloc ( size_t  xWantedSize  ) 

Definition at line 89 of file heap_1.c.

References configTOTAL_HEAP_SIZE, portBYTE_ALIGNMENT, xRTOS_HEAP::ucHeap, vTaskSuspendAll(), xHeap, xNextFreeByte, and xTaskResumeAll().

00090 {
00091 void *pvReturn = NULL; 
00092 
00093     /* Ensure that blocks are always aligned to the required number of bytes. */
00094     #if portBYTE_ALIGNMENT != 1
00095         if( xWantedSize & portBYTE_ALIGNMENT_MASK )
00096         {
00097             /* Byte alignment required. */
00098             xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
00099         }
00100     #endif
00101 
00102     vTaskSuspendAll();
00103     {
00104         /* Check there is enough room left for the allocation. */
00105         if( ( ( xNextFreeByte + xWantedSize ) < configTOTAL_HEAP_SIZE ) &&
00106             ( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */
00107         {
00108             /* Return the next free byte then increment the index past this
00109             block. */
00110             pvReturn = &( xHeap.ucHeap[ xNextFreeByte ] );
00111             xNextFreeByte += xWantedSize;           
00112         }   
00113     }
00114     xTaskResumeAll();
00115     
00116     #if( configUSE_MALLOC_FAILED_HOOK == 1 )
00117     {
00118         if( pvReturn == NULL )
00119         {
00120             extern void vApplicationMallocFailedHook( void );
00121             vApplicationMallocFailedHook();
00122         }
00123     }
00124     #endif  
00125 
00126     return pvReturn;
00127 }

void vPortFree ( void *  pv  ) 

Definition at line 130 of file heap_1.c.

00131 {
00132     /* Memory cannot be freed using this scheme.  See heap_2.c and heap_3.c 
00133     for alternative implementations, and the memory management pages of 
00134     http://www.FreeRTOS.org for more information. */
00135     ( void ) pv;
00136 }

void vPortInitialiseBlocks ( void   ) 

Definition at line 139 of file heap_1.c.

References xNextFreeByte.

00140 {
00141     /* Only required when static memory is not cleared. */
00142     xNextFreeByte = ( size_t ) 0;
00143 }

size_t xPortGetFreeHeapSize ( void   ) 

Definition at line 146 of file heap_1.c.

References configTOTAL_HEAP_SIZE, and xNextFreeByte.

00147 {
00148     return ( configTOTAL_HEAP_SIZE - xNextFreeByte );
00149 }


Variable Documentation

union xRTOS_HEAP xHeap [static]

Referenced by pvPortMalloc().

size_t xNextFreeByte = ( size_t ) 0 [static]

Definition at line 86 of file heap_1.c.

Referenced by pvPortMalloc(), vPortInitialiseBlocks(), and xPortGetFreeHeapSize().


Generated on Thu Dec 17 20:02:01 2009 for AVR32 UC3 - FreeRTOS Real Time Kernel by  doxygen 1.5.5