Swap memory management to FreeRTOS-style, fixed heap size
This commit is contained in:
parent
cd705f8b93
commit
b3c674d89d
3 changed files with 88 additions and 73 deletions
FreeRTOS/Source/portable/esp8266
80
FreeRTOS/Source/portable/esp8266/sdk_compat.c
Normal file
80
FreeRTOS/Source/portable/esp8266/sdk_compat.c
Normal file
|
@ -0,0 +1,80 @@
|
|||
/* this file provides function aliasing/etc that are needed for
|
||||
compatibility with other binary espressif libraries */
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
/* Enable/Disable Interrupts
|
||||
|
||||
Called from many of the linked libraries to protect critical sections.
|
||||
*/
|
||||
|
||||
/*
|
||||
void vPortEnterCritical( void )
|
||||
{
|
||||
portDISABLE_INTERRUPTS();
|
||||
}
|
||||
|
||||
void vPortExitCritical( void )
|
||||
{
|
||||
portEXIT_CRITICAL();
|
||||
}
|
||||
*/
|
||||
|
||||
/* libc memory management functions.
|
||||
|
||||
Many of these are linked from the RTOS SDK blob libraries.
|
||||
|
||||
In esp_iot_rtos_sdk these are aliased to exception-safe versions of
|
||||
the FreeRTOS functions. I think the rationale is that they're
|
||||
sometimes called in exception contexts (ESPTODO: Verify this).
|
||||
|
||||
For now these are exception-safe wrappers to the FreeRTOS versions.
|
||||
*/
|
||||
|
||||
void *malloc(size_t nbytes) {
|
||||
void *res;
|
||||
portENTER_CRITICAL();
|
||||
res = pvPortMalloc(nbytes);
|
||||
portEXIT_CRITICAL();
|
||||
return res;
|
||||
}
|
||||
|
||||
void *calloc(size_t count, size_t size) {
|
||||
void *res;
|
||||
size_t nbytes = count * size;
|
||||
portENTER_CRITICAL();
|
||||
res = pvPortMalloc(nbytes);
|
||||
portEXIT_CRITICAL();
|
||||
if(res) {
|
||||
memset(res, 0, nbytes);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void *zalloc(size_t nbytes) {
|
||||
return calloc(1, nbytes);
|
||||
}
|
||||
|
||||
void *realloc(void *old, size_t newsize) {
|
||||
void *new;
|
||||
portENTER_CRITICAL();
|
||||
if(newsize == 0) {
|
||||
vPortFree(old);
|
||||
return 0;
|
||||
}
|
||||
/* realloc implementation borrowed from esp_iot_rtos_sdk, could be better I think */
|
||||
new = pvPortMalloc(newsize);
|
||||
if (new) {
|
||||
memcpy(new, old, newsize);
|
||||
vPortFree(old);
|
||||
}
|
||||
portEXIT_CRITICAL();
|
||||
return new;
|
||||
}
|
||||
|
||||
void free(void *ptr) {
|
||||
portENTER_CRITICAL();
|
||||
vPortFree(ptr);
|
||||
portEXIT_CRITICAL();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue