mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-20 10:54:14 +01:00
OP-900 Changed memory allocation strategy for F1 to use portBYTE_ALIGNMENT alignment for stacks and portBYTE_HEAP_ALIGNMENT for generic mallocs
+review OPReview-435
This commit is contained in:
parent
c801ca681c
commit
81156ad132
@ -98,23 +98,24 @@ static unsigned char ucHeap[ configTOTAL_HEAP_SIZE ] __attribute__ ((section ("
|
||||
static size_t xNextFreeByte = ( size_t ) 0;
|
||||
|
||||
static size_t currentTOTAL_HEAP_SIZE = configTOTAL_HEAP_SIZE;
|
||||
void *pvPortMallocGeneric( size_t xWantedSize, size_t alignment);
|
||||
|
||||
/* A few bytes might be lost to byte aligning the heap start address. */
|
||||
#define configADJUSTED_HEAP_SIZE (currentTOTAL_HEAP_SIZE - portBYTE_ALIGNMENT)
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void *pvPortMalloc( size_t xWantedSize )
|
||||
void *pvPortMallocGeneric( size_t xWantedSize, size_t alignment)
|
||||
{
|
||||
void *pvReturn = NULL;
|
||||
static unsigned char *pucAlignedHeap = NULL;
|
||||
|
||||
size_t mask = alignment-1;
|
||||
/* Ensure that blocks are always aligned to the required number of bytes. */
|
||||
#if portBYTE_ALIGNMENT != 1
|
||||
if( xWantedSize & portBYTE_ALIGNMENT_MASK )
|
||||
if( xWantedSize & mask )
|
||||
{
|
||||
/* Byte alignment required. */
|
||||
xWantedSize += ( portBYTE_ALIGNMENT - ( xWantedSize & portBYTE_ALIGNMENT_MASK ) );
|
||||
/* Byte alignment required. */
|
||||
xWantedSize += ( alignment - ( xWantedSize & mask ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -123,7 +124,7 @@ static unsigned char *pucAlignedHeap = NULL;
|
||||
if( pucAlignedHeap == NULL )
|
||||
{
|
||||
/* Ensure the heap starts on a correctly aligned boundary. */
|
||||
pucAlignedHeap = ( unsigned char * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ portBYTE_ALIGNMENT ] ) & ( ( portPOINTER_SIZE_TYPE ) ~portBYTE_ALIGNMENT_MASK ) );
|
||||
pucAlignedHeap = ( unsigned char * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ alignment ] ) & ( ( portPOINTER_SIZE_TYPE ) ~ mask ) );
|
||||
}
|
||||
|
||||
/* Check there is enough room left for the allocation. */
|
||||
@ -150,6 +151,11 @@ static unsigned char *pucAlignedHeap = NULL;
|
||||
|
||||
return pvReturn;
|
||||
}
|
||||
|
||||
void *pvPortMalloc( size_t xWantedSize){
|
||||
return pvPortMallocGeneric(xWantedSize, portBYTE_HEAP_ALIGNMENT);
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
void vPortFree( void *pv )
|
||||
|
@ -111,7 +111,8 @@ extern "C" {
|
||||
/* Architecture specifics. */
|
||||
#define portSTACK_GROWTH ( -1 )
|
||||
#define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ )
|
||||
#define portBYTE_ALIGNMENT 4
|
||||
#define portBYTE_ALIGNMENT 8 // APCS 8 bytes aligned stack for external calls
|
||||
#define portBYTE_HEAP_ALIGNMENT 4 // this value is used to allocate heap
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
|
@ -111,7 +111,7 @@ extern "C" {
|
||||
/* Architecture specifics. */
|
||||
#define portSTACK_GROWTH ( -1 )
|
||||
#define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ )
|
||||
#define portBYTE_ALIGNMENT 4
|
||||
#define portBYTE_ALIGNMENT 8
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
|
@ -91,6 +91,8 @@ do {\
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 1
|
||||
#endif
|
||||
|
||||
void *pvPortMallocGeneric( size_t xWantedSize, size_t alignment);
|
||||
#define pvPortMallocAligned( x, puxStackBuffer ) ( ( ( puxStackBuffer ) == NULL ) ? ( pvPortMallocGeneric( ( x ) , portBYTE_ALIGNMENT) ) : ( puxStackBuffer ) )
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
@ -91,6 +91,8 @@ do {\
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 1
|
||||
#endif
|
||||
|
||||
void *pvPortMallocGeneric( size_t xWantedSize, size_t alignment);
|
||||
#define pvPortMallocAligned( x, puxStackBuffer ) ( ( ( puxStackBuffer ) == NULL ) ? ( pvPortMallocGeneric( ( x ) , portBYTE_ALIGNMENT) ) : ( puxStackBuffer ) )
|
||||
|
||||
/**
|
||||
* @}
|
||||
|
Loading…
x
Reference in New Issue
Block a user