From 0b087acf843a66d4e8e3fcc30c36953be17d5ccf Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Fri, 3 Apr 2015 00:01:51 +0300 Subject: [PATCH] Provide replacements for malloc, free and other libc functions #11 --- .../esp8266/cores/esp8266/libc_replacements.c | 101 ++++++++++++++++++ hardware/esp8266com/esp8266/platform.txt | 4 +- 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 hardware/esp8266com/esp8266/cores/esp8266/libc_replacements.c diff --git a/hardware/esp8266com/esp8266/cores/esp8266/libc_replacements.c b/hardware/esp8266com/esp8266/cores/esp8266/libc_replacements.c new file mode 100644 index 0000000000..9346ac4df1 --- /dev/null +++ b/hardware/esp8266com/esp8266/cores/esp8266/libc_replacements.c @@ -0,0 +1,101 @@ +/* + libc_replacements.c - replaces libc functions with functions + from Espressif SDK + + Copyright (c) 2015 Ivan Grokhotkov. All rights reserved. + This file is part of the esp8266 core for Arduino environment. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include + +#include "ets_sys.h" +#include "os_type.h" +#include "osapi.h" +#include "mem.h" +#include "user_interface.h" + + +void* malloc(size_t size) { + return os_malloc(size); +} + +void free(void* ptr) { + os_free(ptr); +} + +void* realloc(void* ptr, size_t size) { + return os_realloc(ptr, size); +} + +int printf(const char* format, ...) { + va_list arglist; + va_start(arglist, format); + ets_vprintf(format, arglist); + va_end(arglist); +} + +int sprintf(char* buffer, const char* format, ...) { + va_list arglist; + va_start(arglist, format); + ets_vsprintf(buffer, format, arglist); + va_end(arglist); +} + +int snprintf(char* buffer, size_t size, const char* format, ...) { + va_list arglist; + va_start(arglist, format); + ets_vsnprintf(buffer, size, format, arglist); + va_end(arglist); +} + +int memcmp(const void *s1, const void *s2, size_t n) { + return ets_memcmp(s1, s2, n); +} + +void* memcpy(void *dest, const void *src, size_t n) { + return ets_memcpy(dest, src, n); +} + +void* memset(void *s, int c, size_t n) { + return ets_memset(s, c, n); +} + +int strcmp(const char *s1, const char *s2) { + return ets_strcmp(s1, s2); +} + +char* strcpy(char *dest, const char *src) { + return ets_strcpy(dest, src); +} + +size_t strlen(const char *s) { + return ets_strlen(s); +} + +int strncmp(const char *s1, const char *s2, size_t len) { + return ets_strncmp(s1, s2, len); +} + +char *strncpy(char *dest, const char *src, size_t n) { + return ets_strncpy(dest, src, n); +} + +char *ets_strstr(const char *haystack, const char *needle) { + return strstr(haystack, needle); +} + diff --git a/hardware/esp8266com/esp8266/platform.txt b/hardware/esp8266com/esp8266/platform.txt index 40e8292358..065267dba0 100644 --- a/hardware/esp8266com/esp8266/platform.txt +++ b/hardware/esp8266com/esp8266/platform.txt @@ -23,7 +23,7 @@ compiler.S.flags=-c -g -x assembler-with-cpp -MMD compiler.c.elf.ldscript=eagle.app.v6.ld compiler.c.elf.flags=-nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static "-L{compiler.sdk.path}/lib" "-L{compiler.sdk.path}/ld" "-T{compiler.c.elf.ldscript}" compiler.c.elf.cmd=xtensa-lx106-elf-gcc -compiler.c.elf.libs=-lc -lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp +compiler.c.elf.libs=-lgcc -lhal -lphy -lnet80211 -llwip -lwpa -lmain -lpp compiler.cpp.cmd=xtensa-lx106-elf-g++ compiler.cpp.flags=-c -Os -mlongcalls -mtext-section-literals -fno-exceptions -fno-rtti -std=c++11 -MMD @@ -66,7 +66,7 @@ recipe.S.o.pattern="{compiler.path}{compiler.c.cmd}" {compiler.cpreprocessor.fla recipe.ar.pattern="{compiler.path}{compiler.ar.cmd}" {compiler.ar.flags} {compiler.ar.extra_flags} "{build.path}/{archive_file}" "{object_file}" ## Combine gc-sections, archives, and objects -recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/{archive_file}" {compiler.c.elf.libs} -Wl,--end-group "-L{build.path}" +recipe.c.combine.pattern="{compiler.path}{compiler.c.elf.cmd}" {compiler.c.elf.flags} {compiler.c.elf.extra_flags} -o "{build.path}/{build.project_name}.elf" -Wl,--start-group {object_files} "{build.path}/{archive_file}" {compiler.c.elf.libs} -Wl,--end-group -lc "-L{build.path}" ## Create eeprom recipe.objcopy.eep.pattern=