mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-29 14:52:12 +01:00
OP-900 Various fixes from OPReview-435
+review OPReview-435
This commit is contained in:
parent
f005485e63
commit
61be4811f5
@ -105,54 +105,49 @@ void *pvPortMallocGeneric( size_t xWantedSize, size_t alignment);
|
||||
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
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 & mask )
|
||||
{
|
||||
/* Byte alignment required. */
|
||||
xWantedSize += ( alignment - ( xWantedSize & mask ) );
|
||||
}
|
||||
#endif
|
||||
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 & mask) {
|
||||
/* Byte alignment required. */
|
||||
xWantedSize += (alignment - (xWantedSize & mask));
|
||||
}
|
||||
#endif
|
||||
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
if( pucAlignedHeap == NULL )
|
||||
{
|
||||
/* Ensure the heap starts on a correctly aligned boundary. */
|
||||
pucAlignedHeap = ( unsigned char * ) ( ( ( portPOINTER_SIZE_TYPE ) &ucHeap[ alignment ] ) & ( ( portPOINTER_SIZE_TYPE ) ~ mask ) );
|
||||
}
|
||||
vTaskSuspendAll();
|
||||
{
|
||||
if (pucAlignedHeap == NULL ) {
|
||||
/* Ensure the heap starts on a correctly aligned boundary. */
|
||||
pucAlignedHeap = (unsigned char *) (((portPOINTER_SIZE_TYPE ) &ucHeap[alignment]) & ((portPOINTER_SIZE_TYPE ) ~mask));
|
||||
}
|
||||
|
||||
/* Check there is enough room left for the allocation. */
|
||||
if( ( ( xNextFreeByte + xWantedSize ) < configADJUSTED_HEAP_SIZE ) &&
|
||||
( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) )/* Check for overflow. */
|
||||
{
|
||||
/* Return the next free byte then increment the index past this
|
||||
block. */
|
||||
pvReturn = pucAlignedHeap + xNextFreeByte;
|
||||
xNextFreeByte += xWantedSize;
|
||||
}
|
||||
}
|
||||
xTaskResumeAll();
|
||||
/* Check there is enough room left for the allocation. */
|
||||
if (((xNextFreeByte + xWantedSize) < configADJUSTED_HEAP_SIZE)&&
|
||||
( ( xNextFreeByte + xWantedSize ) > xNextFreeByte ) ){
|
||||
/* Check for overflow. */
|
||||
/* Return the next free byte then increment the index past this block. */
|
||||
pvReturn = pucAlignedHeap + xNextFreeByte;
|
||||
xNextFreeByte += xWantedSize;
|
||||
}
|
||||
}
|
||||
xTaskResumeAll();
|
||||
|
||||
#if( configUSE_MALLOC_FAILED_HOOK == 1 )
|
||||
{
|
||||
if( pvReturn == NULL )
|
||||
{
|
||||
extern void vApplicationMallocFailedHook( void );
|
||||
vApplicationMallocFailedHook();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#if( configUSE_MALLOC_FAILED_HOOK == 1 )
|
||||
{
|
||||
if( pvReturn == NULL ) {
|
||||
extern void vApplicationMallocFailedHook( void );
|
||||
vApplicationMallocFailedHook();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
return pvReturn;
|
||||
return pvReturn;
|
||||
}
|
||||
|
||||
void *pvPortMalloc( size_t xWantedSize){
|
||||
void *pvPortMalloc(size_t xWantedSize) {
|
||||
return pvPortMallocGeneric(xWantedSize, portBYTE_HEAP_ALIGNMENT);
|
||||
}
|
||||
|
||||
|
@ -8,6 +8,7 @@ Brief list of modifications:
|
||||
*Allow heap_1.c for modification of max heap size at runtime;
|
||||
*use section ".heap" for heap.
|
||||
|
||||
Memory manager now handles two different kind of alignments for F1, portBYTE_ALIGNMENT for standard mallocs, and portBYTE_HEAP_ALIGNMENT for stack(aligned) allocs
|
||||
|
||||
|
||||
|
||||
|
@ -115,6 +115,8 @@ extern "C" {
|
||||
#define portBYTE_HEAP_ALIGNMENT 4 // this value is used to allocate heap
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
extern void *pvPortMallocGeneric( size_t xWantedSize, size_t alignment);
|
||||
#define pvPortMallocAligned( x, puxStackBuffer ) ( ( ( puxStackBuffer ) == NULL ) ? ( pvPortMallocGeneric( ( x ) , portBYTE_ALIGNMENT) ) : ( puxStackBuffer ) )
|
||||
|
||||
/* Scheduler utilities. */
|
||||
extern void vPortYieldFromISR( void );
|
||||
|
@ -111,7 +111,7 @@ extern "C" {
|
||||
/* Architecture specifics. */
|
||||
#define portSTACK_GROWTH ( -1 )
|
||||
#define portTICK_RATE_MS ( ( portTickType ) 1000 / configTICK_RATE_HZ )
|
||||
#define portBYTE_ALIGNMENT 8
|
||||
#define portBYTE_ALIGNMENT 8 // APCS 8 bytes aligned stack for external calls
|
||||
/*-----------------------------------------------------------*/
|
||||
|
||||
|
||||
|
@ -91,9 +91,6 @@ 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