2015-06-02 05:06:40 +00:00
|
|
|
/*
|
|
|
|
* Stub functions called by binary espressif libraries
|
|
|
|
*
|
|
|
|
* Part of esp-open-rtos
|
2015-06-05 01:46:25 +00:00
|
|
|
* Copyright (C) 2015 Superhouse Automation Pty Ltd
|
2015-06-02 05:06:40 +00:00
|
|
|
* BSD Licensed as described in the file LICENSE
|
|
|
|
*/
|
2015-05-06 08:44:20 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include "FreeRTOS.h"
|
|
|
|
|
2015-06-02 00:43:08 +00:00
|
|
|
/* SDK uses errno. errno was defined in libudhcp.a
|
2015-05-21 02:21:26 +00:00
|
|
|
but that library has been removed. */
|
|
|
|
int errno;
|
|
|
|
|
2015-05-26 01:10:26 +00:00
|
|
|
/* newlib uses __errno in some contexts */
|
|
|
|
int *__errno(void) {
|
|
|
|
return &errno;
|
|
|
|
}
|
|
|
|
|
2015-05-06 08:44:20 +00:00
|
|
|
/* 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();
|
|
|
|
}
|