Skip to content

Commit

Permalink
Initial version of the umm_malloc integration.
Browse files Browse the repository at this point in the history
  • Loading branch information
Slavey Karadzhov committed Apr 14, 2016
1 parent 444ffd6 commit 7f82800
Show file tree
Hide file tree
Showing 14 changed files with 3,027 additions and 7 deletions.
23 changes: 21 additions & 2 deletions Sming/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,21 @@ EXTRA_INCDIR = include system/include Wiring Libraries SmingCore rboot rboot/

# libraries used in this project, mainly provided by the SDK
USER_LIBDIR = compiler/lib
LIBS = microc microgcc hal phy pp net80211 lwip wpa main

ENABLE_CUSTOM_HEAP ?= 1
ifeq ($(ENABLE_CUSTOM_HEAP),1)
MODULES += custom_heap custom_heap/umm_malloc
EXTRA_INCDIR += custom_heap

LIBMAIN = mainmm
LIBMAIN_SRC = $(addprefix $(SDK_LIBDIR)/,libmain.a)
LIBMAIN_DST = $(USER_LIBDIR)/lib$(LIBMAIN).a
else
LIBMAIN = main
LIBMAIN_DST = $()
endif

LIBS = microc microgcc hal phy pp net80211 lwip wpa $(LIBMAIN)

# compiler flags using during compilation of source files. Add '-pg' for debugging
CFLAGS = -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections -D__ets__ -DICACHE_FLASH -DARDUINO=106
Expand Down Expand Up @@ -209,8 +223,13 @@ endef

.PHONY: all checkdirs clean spiffy test samples recurse-samples $(SAMPLES_DIRS)

all: checkdirs $(APP_AR)
all: checkdirs $(LIBMAIN_DST) $(APP_AR)

$(LIBMAIN_DST): $(LIBMAIN_SRC)
$(vecho) "Preparing for custom heap implementation"
$(Q) cp $^ $@
$(Q) $(AR) -d $@ mem_manager.o

ifeq ($(ENABLE_GDB), 1)
gdbstub/Makefile:
$(Q) echo "No espgdbstub submodule found. Using git to fetch it..."
Expand Down
9 changes: 8 additions & 1 deletion Sming/Makefile-project.mk
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,16 @@ MODULES ?= app # default to app if not set by user
EXTRA_INCDIR ?= include # default to include if not set by user
EXTRA_INCDIR += $(SMING_HOME)/include $(SMING_HOME)/ $(SMING_HOME)/system/include $(SMING_HOME)/Wiring $(SMING_HOME)/Libraries $(SMING_HOME)/SmingCore $(SDK_BASE)/../include $(SMING_HOME)/rboot $(SMING_HOME)/rboot/appcode

ENABLE_CUSTOM_HEAP ?= 1

LIBMAIN = main
ifeq ($(ENABLE_CUSTOM_HEAP),1)
LIBMAIN = mainmm
endif

# libraries used in this project, mainly provided by the SDK
USER_LIBDIR = $(SMING_HOME)/compiler/lib/
LIBS = microc microgcc hal phy pp net80211 lwip wpa main sming crypto pwm smartconfig $(EXTRA_LIBS)
LIBS = microc microgcc hal phy pp net80211 lwip wpa $(LIBMAIN) sming crypto pwm smartconfig $(EXTRA_LIBS)

# compiler flags using during compilation of source files
CFLAGS = -Wpointer-arith -Wundef -Werror -Wl,-EL -nostdlib -mlongcalls -mtext-section-literals -finline-functions -fdata-sections -ffunction-sections -D__ets__ -DICACHE_FLASH -DARDUINO=106 $(USER_CFLAGS)
Expand Down
16 changes: 12 additions & 4 deletions Sming/Makefile-rboot.mk
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,27 @@ else
endif
CXXFLAGS = $(CFLAGS) -fno-rtti -fno-exceptions -std=c++11 -felide-constructors

ENABLE_CUSTOM_HEAP ?= 1

USER_LIBDIR = $(SMING_HOME)/compiler/lib/

# libmain must be modified for rBoot big flash support (just one symbol gets weakened)
LIBMAIN = main
LIBMAIN_SRC = $(addprefix $(SDK_LIBDIR)/,libmain.a)
ifeq ($(ENABLE_CUSTOM_HEAP),1)
LIBMAIN = mainmm
LIBMAIN_SRC := $(USER_LIBDIR)lib$(LIBMAIN).a
endif

ifeq ($(RBOOT_BIG_FLASH),1)
LIBMAIN = main2
LIBMAIN_SRC = $(addprefix $(SDK_LIBDIR)/,libmain.a)
LIBMAIN_DST = $(addprefix $(BUILD_BASE)/,libmain2.a)
CFLAGS += -DBOOT_BIG_FLASH
else
LIBMAIN = main
LIBMAIN_DST = $()
endif
# libraries used in this project, mainly provided by the SDK
USER_LIBDIR = $(SMING_HOME)/compiler/lib/
LIBS = microc microgcc hal phy pp net80211 lwip wpa $(LIBMAIN) sming crypto pwm smartconfig $(EXTRA_LIBS)
LIBS = microc microgcc hal phy pp net80211 lwip wpa $(LIBMAIN) sming crypto pwm smartconfig $(EXTRA_LIBS)

# we will use global WiFi settings from Eclipse Environment Variables, if possible
WIFI_SSID ?= ""
Expand Down
4 changes: 4 additions & 0 deletions Sming/compiler/ld/eagle.app.v6.cpp.ld
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ SECTIONS
{
_irom0_text_start = ABSOLUTE(.);
*(.irom0.literal .irom.literal .irom.text.literal .irom0.text .irom.text)
/*
*.c.o( EXCLUDE_FILE (umm_malloc.c.o) .literal*, \
EXCLUDE_FILE (umm_malloc.c.o) .text*)
*/
out/build/app_app.a:*(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
*libsming.a:*(.literal .text .literal.* .text.* .stub .gnu.warning .gnu.linkonce.literal.* .gnu.linkonce.t.*.literal .gnu.linkonce.t.*)
_irom0_text_end = ABSOLUTE(.);
Expand Down
50 changes: 50 additions & 0 deletions Sming/custom_heap/heap.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* heap.c - overrides of SDK heap handling functions
* Copyright (c) 2016 Ivan Grokhotkov. All rights reserved.
* This file is distributed under MIT license.
*/

#include <stdlib.h>
#include <c_types.h>
#include "umm_malloc/umm_malloc.h"

#define IRAM_ATTR __attribute__((section(".iram.text")))

void* IRAM_ATTR pvPortMalloc(size_t size, const char* file, int line)
{
return malloc(size);
}

void IRAM_ATTR vPortFree(void *ptr, const char* file, int line)
{
free(ptr);
}

void* IRAM_ATTR pvPortCalloc(size_t count, size_t size, const char* file, int line)
{
return calloc(count, size);
}

void* IRAM_ATTR pvPortRealloc(void *ptr, size_t size, const char* file, int line)
{
return realloc(ptr, size);
}

void* IRAM_ATTR pvPortZalloc(size_t size, const char* file, int line)
{
return calloc(1, size);
}

size_t xPortGetFreeHeapSize(void)
{
return umm_free_heap_size();
}

size_t IRAM_ATTR xPortWantedSizeAlign(size_t size)
{
return (size + 3) & ~((size_t) 3);
}

void system_show_malloc(void)
{
umm_info(NULL, 1);
}
22 changes: 22 additions & 0 deletions Sming/custom_heap/umm_malloc/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Ralph Hempel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Loading

0 comments on commit 7f82800

Please sign in to comment.