mirror of
https://github.com/FreeRTOS/FreeRTOS-Kernel.git
synced 2025-04-20 05:21:59 -04:00
Add xPortGetFreeHeapSize() function.
This commit is contained in:
parent
9468e36040
commit
e90ba3e57f
|
@ -99,6 +99,8 @@ only for ports that are using the MPU. */
|
||||||
|
|
||||||
#define pvPortMalloc MPU_pvPortMalloc
|
#define pvPortMalloc MPU_pvPortMalloc
|
||||||
#define vPortFree MPU_vPortFree
|
#define vPortFree MPU_vPortFree
|
||||||
|
#define xPortGetFreeHeapSize MPU_xPortGetFreeHeapSize
|
||||||
|
#define vPortInitialiseBlocks MPU_vPortInitialiseBlocks
|
||||||
|
|
||||||
/* Remove the privileged function macro. */
|
/* Remove the privileged function macro. */
|
||||||
#define PRIVILEGED_FUNCTION
|
#define PRIVILEGED_FUNCTION
|
||||||
|
|
|
@ -350,6 +350,7 @@ extern "C" {
|
||||||
void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;
|
void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION;
|
||||||
void vPortFree( void *pv ) PRIVILEGED_FUNCTION;
|
void vPortFree( void *pv ) PRIVILEGED_FUNCTION;
|
||||||
void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;
|
void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION;
|
||||||
|
size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Setup the hardware ready for the scheduler to take control. This generally
|
* Setup the hardware ready for the scheduler to take control. This generally
|
||||||
|
|
|
@ -1025,3 +1025,27 @@ portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();
|
||||||
|
|
||||||
portRESET_PRIVILEGE( xRunningPrivileged );
|
portRESET_PRIVILEGE( xRunningPrivileged );
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
void MPU_vPortInitialiseBlocks( void )
|
||||||
|
{
|
||||||
|
portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();
|
||||||
|
|
||||||
|
vPortInitialiseBlocks();
|
||||||
|
|
||||||
|
portRESET_PRIVILEGE( xRunningPrivileged );
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
size_t MPU_xPortGetFreeHeapSize( void )
|
||||||
|
{
|
||||||
|
size_t xReturn;
|
||||||
|
portBASE_TYPE xRunningPrivileged = prvRaisePrivilege();
|
||||||
|
|
||||||
|
xReturn = xPortGetFreeHeapSize();
|
||||||
|
|
||||||
|
portRESET_PRIVILEGE( xRunningPrivileged );
|
||||||
|
|
||||||
|
return xReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -136,5 +136,12 @@ void vPortInitialiseBlocks( void )
|
||||||
/* Only required when static memory is not cleared. */
|
/* Only required when static memory is not cleared. */
|
||||||
xNextFreeByte = ( size_t ) 0;
|
xNextFreeByte = ( size_t ) 0;
|
||||||
}
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
size_t xPortGetFreeHeapSize( void )
|
||||||
|
{
|
||||||
|
return ( configTOTAL_HEAP_SIZE - xNextFreeByte );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -93,6 +93,10 @@ static const unsigned short heapSTRUCT_SIZE = ( sizeof( xBlockLink ) + portBYTE
|
||||||
/* Create a couple of list links to mark the start and end of the list. */
|
/* Create a couple of list links to mark the start and end of the list. */
|
||||||
static xBlockLink xStart, xEnd;
|
static xBlockLink xStart, xEnd;
|
||||||
|
|
||||||
|
/* Keeps track of the number of free bytes remaining, but says nothing about
|
||||||
|
fragmentation. */
|
||||||
|
static size_t xFreeBytesRemaining = configTOTAL_HEAP_SIZE;
|
||||||
|
|
||||||
/* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */
|
/* STATIC FUNCTIONS ARE DEFINED AS MACROS TO MINIMIZE THE FUNCTION CALL DEPTH. */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -211,6 +215,8 @@ void *pvReturn = NULL;
|
||||||
/* Insert the new block into the list of free blocks. */
|
/* Insert the new block into the list of free blocks. */
|
||||||
prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );
|
prvInsertBlockIntoFreeList( ( pxNewBlockLink ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
xFreeBytesRemaining -= xWantedSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -248,9 +254,16 @@ xBlockLink *pxLink;
|
||||||
{
|
{
|
||||||
/* Add this block to the list of free blocks. */
|
/* Add this block to the list of free blocks. */
|
||||||
prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) );
|
prvInsertBlockIntoFreeList( ( ( xBlockLink * ) pxLink ) );
|
||||||
|
xFreeBytesRemaining += pxLink->xBlockSize;
|
||||||
}
|
}
|
||||||
xTaskResumeAll();
|
xTaskResumeAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
size_t xPortGetFreeHeapSize( void )
|
||||||
|
{
|
||||||
|
return xFreeBytesRemaining;
|
||||||
|
}
|
||||||
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue