diff --git a/cores/nRF5/freertos/source/include/portable.h b/cores/nRF5/freertos/source/include/portable.h index 73386cb5..beaccc43 100644 --- a/cores/nRF5/freertos/source/include/portable.h +++ b/cores/nRF5/freertos/source/include/portable.h @@ -162,6 +162,8 @@ void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ); */ void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION; void vPortFree( void *pv ) PRIVILEGED_FUNCTION; +void *pvPortRealloc( void* pv, size_t new_size) PRIVILEGED_FUNCTION; + void vPortInitialiseBlocks( void ) PRIVILEGED_FUNCTION; size_t xPortGetFreeHeapSize( void ) PRIVILEGED_FUNCTION; size_t xPortGetMinimumEverFreeHeapSize( void ) PRIVILEGED_FUNCTION; diff --git a/cores/nRF5/freertos/source/portable/MemMang/heap_3.c b/cores/nRF5/freertos/source/portable/MemMang/heap_3.c index c2ea0cd8..a89e36a0 100644 --- a/cores/nRF5/freertos/source/portable/MemMang/heap_3.c +++ b/cores/nRF5/freertos/source/portable/MemMang/heap_3.c @@ -94,7 +94,7 @@ task.h is included from an application file. */ void *pvPortMalloc( size_t xWantedSize ) { -void *pvReturn; + void *pvReturn; vTaskSuspendAll(); { @@ -130,4 +130,28 @@ void vPortFree( void *pv ) } } +void *pvPortRealloc( void* pv, size_t new_size) +{ + void *pvReturn; + + vTaskSuspendAll(); + { + pvReturn = realloc( pv, new_size ); + traceMALLOC( pvReturn, new_size ); + } + ( void ) xTaskResumeAll(); + + #if( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + } + #endif + + return pvReturn; +} + diff --git a/cores/nRF5/rtos.h b/cores/nRF5/rtos.h index 50601073..8d9d5364 100644 --- a/cores/nRF5/rtos.h +++ b/cores/nRF5/rtos.h @@ -66,5 +66,10 @@ static inline void rtos_free( void *pv ) return (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) ? free(pv) : vPortFree(pv); } +static inline void* rtos_realloc(void* pv, size_t new_size) +{ + return (xTaskGetSchedulerState() == taskSCHEDULER_NOT_STARTED) ? realloc(pv, new_size) : pvPortRealloc(pv, new_size); +} + #endif #endif /* RTOS_H_ */ diff --git a/libraries/nffs/src/kernel/os/include/os/os_malloc.h b/libraries/nffs/src/kernel/os/include/os/os_malloc.h index 5f53bea5..feaf4501 100644 --- a/libraries/nffs/src/kernel/os/include/os/os_malloc.h +++ b/libraries/nffs/src/kernel/os/include/os/os_malloc.h @@ -33,8 +33,8 @@ extern "C" { #undef free #define free rtos_free -//#undef realloc -//#define realloc rtos_realloc +#undef realloc +#define realloc rtos_realloc #ifdef __cplusplus }