diff --git a/cores/nRF5/freertos/Source/include/portable.h b/cores/nRF5/freertos/Source/include/portable.h index 8aac353e..8209f050 100644 --- a/cores/nRF5/freertos/Source/include/portable.h +++ b/cores/nRF5/freertos/Source/include/portable.h @@ -128,6 +128,8 @@ void vPortDefineHeapRegions( const HeapRegion_t * const pxHeapRegions ) PRIVILEG */ void *pvPortMalloc( size_t xSize ) PRIVILEGED_FUNCTION; void vPortFree( void *pv ) PRIVILEGED_FUNCTION; +void *pvPortRealloc( void *ptr, size_t xWantedSize ) PRIVILEGED_FUNCTION; +void *pvPortCalloc( size_t nmemb, size_t xWantedSize ) 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 4edae90f..1d07d7f2 100644 --- a/cores/nRF5/freertos/Source/portable/MemMang/heap_3.c +++ b/cores/nRF5/freertos/Source/portable/MemMang/heap_3.c @@ -59,6 +59,8 @@ task.h is included from an application file. */ // require "-Wl,--wrap=malloc -Wl,--wrap=free" linker option extern void *__real_malloc(size_t size); extern void __real_free(void *ptr); +extern void *__real_realloc(void *ptr, size_t _size); +extern void *__real_calloc(size_t nmemb, size_t _size); void* __wrap_malloc (size_t c) { @@ -70,6 +72,17 @@ void __wrap_free (void *ptr) return (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) ? vPortFree(ptr) : __real_free(ptr); } +void* __wrap_realloc (void *ptr, size_t c) +{ + return (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) ? pvPortRealloc(ptr, c) : __real_realloc(ptr, c); +} + +void* __wrap_calloc (size_t nmemb, size_t c) +{ + return (xTaskGetSchedulerState() == taskSCHEDULER_RUNNING) ? pvPortCalloc(nmemb, c) : __real_calloc(nmemb, c); +} + + void *pvPortMalloc( size_t xWantedSize ) { void *pvReturn; @@ -107,3 +120,53 @@ void vPortFree( void *pv ) ( void ) xTaskResumeAll(); } } +/*-----------------------------------------------------------*/ + +void *pvPortRealloc( void *ptr, size_t xWantedSize ) +{ +void *pvReturn; + + vTaskSuspendAll(); + { + pvReturn = __real_realloc( ptr, xWantedSize ); + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + } + #endif + + return pvReturn; +} +/*-----------------------------------------------------------*/ + +void *pvPortCalloc( size_t nmemb, size_t xWantedSize ) +{ +void *pvReturn; + + vTaskSuspendAll(); + { + pvReturn = __real_calloc( nmemb, xWantedSize ); + traceMALLOC( pvReturn, xWantedSize ); + } + ( void ) xTaskResumeAll(); + + #if( configUSE_MALLOC_FAILED_HOOK == 1 ) + { + if( pvReturn == NULL ) + { + extern void vApplicationMallocFailedHook( void ); + vApplicationMallocFailedHook(); + } + } + #endif + + return pvReturn; +} \ No newline at end of file diff --git a/platform.txt b/platform.txt index ac8575e1..6b890fe8 100644 --- a/platform.txt +++ b/platform.txt @@ -49,7 +49,7 @@ compiler.elf2bin.flags=-O binary compiler.elf2bin.cmd=arm-none-eabi-objcopy compiler.elf2hex.flags=-O ihex compiler.elf2hex.cmd=arm-none-eabi-objcopy -compiler.ldflags=-mcpu={build.mcu} -mthumb {build.float_flags} -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--wrap=malloc -Wl,--wrap=free --specs=nano.specs --specs=nosys.specs +compiler.ldflags=-mcpu={build.mcu} -mthumb {build.float_flags} -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--wrap=malloc -Wl,--wrap=free -Wl,--wrap=realloc -Wl,--wrap=calloc --specs=nano.specs --specs=nosys.specs compiler.size.cmd=arm-none-eabi-size # this can be overriden in boards.txt