From 965df7faefabdd5f571b5eb46d45470223c91e12 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Mon, 24 Jan 2011 10:35:19 +0100 Subject: Adding sbrk, and fixing a couple of other makefile problems. --- Makefile | 2 +- arch/config.mk | 2 -- os/Makefile | 3 ++- os/src/sbrk.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ target-rules.mk | 2 +- 5 files changed, 51 insertions(+), 5 deletions(-) create mode 100644 os/src/sbrk.c diff --git a/Makefile b/Makefile index 6670cb7..8de95f8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,5 @@ TARGET = demo.bin -LIBS = -LFreeRTOS -Larch -Los -lFreeRTOS -larch -los +LIBS = FreeRTOS/libFreeRTOS.a arch/libarch.a -lc os/libos.a export ROOTDIR = $(CURDIR) diff --git a/arch/config.mk b/arch/config.mk index a475d59..f182a95 100644 --- a/arch/config.mk +++ b/arch/config.mk @@ -1,5 +1,3 @@ -include $(ROOTDIR)/common.mk - ifeq ($(CPU),arm) ifeq ($(CPU_FLAVOR),lpc1768) TARGET_INCLUDES += $(ROOTDIR)/arch/arm/lpc17xx/Core/CM3/DeviceSupport/NXP/LPC17xx $(ROOTDIR)/arch/arm/lpc17xx/Core/CM3/CoreSupport $(ROOTDIR)/arch/arm/lpc17xx/Drivers/include diff --git a/os/Makefile b/os/Makefile index 6f6ce2e..070566d 100644 --- a/os/Makefile +++ b/os/Makefile @@ -4,8 +4,9 @@ all: $(TARGET_LIB) include $(ROOTDIR)/common.mk include config.mk +include $(ROOTDIR)/FreeRTOS/config.mk -TARGET_SRCS = src/init.c +TARGET_SRCS = src/init.c src/sbrk.c include $(ROOTDIR)/target-rules.mk diff --git a/os/src/sbrk.c b/os/src/sbrk.c new file mode 100644 index 0000000..3c674ba --- /dev/null +++ b/os/src/sbrk.c @@ -0,0 +1,47 @@ +#include +#include +#include + +#include "FreeRTOS.h" +#include "task.h" +#include "mpu_wrappers.h" + +// Mostly stolen from mbed-freertos + +extern unsigned int __cs3_heap_start, __cs3_heap_end; + +/* Low-level bulk RAM allocator -- used by Newlib's Malloc */ +void *heap_end = NULL; +PRIVILEGED_FUNCTION void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr) +{ + void *prev_heap_end, *next_heap_end, *ret; + + taskENTER_CRITICAL(); + { + /* Initialize on first call */ + if (heap_end == NULL) + { + heap_end = (void *)&__cs3_heap_start; + } + + prev_heap_end = heap_end; + + /* Align to always be on 8-byte boundaries */ + next_heap_end = (void *)((((unsigned int)heap_end + incr) + 7) & ~7); + + /* Check if this allocation would exceed the end of the ram - would probably get into the stack first however */ + if (next_heap_end > (void *)&__cs3_heap_end) + { + ptr->_errno = ENOMEM; + ret = NULL; + } + else + { + heap_end = next_heap_end; + ret = (void *)prev_heap_end; + } + } + taskEXIT_CRITICAL(); + return ret; +} + diff --git a/target-rules.mk b/target-rules.mk index acb398c..5b976bc 100644 --- a/target-rules.mk +++ b/target-rules.mk @@ -20,7 +20,7 @@ $(TARGET_ELF): $(TARGET_OBJS) $(TARGET_BIN): $(TARGET_ELF) $(E) [TB] Creating $@ - $(Q)$(TARGET_OBJDUMP) $< -O binary $@ + $(Q)$(TARGET_OBJCOPY) $< -O binary $@ $(TARGET_LIB): $(TARGET_OBJS) $(E) [TLIB] Creating $@ -- cgit v1.2.3