From 887d0354a0aa4e1209175c9e1544b36851b7c96b Mon Sep 17 00:00:00 2001 From: hathach Date: Sat, 8 Apr 2017 16:32:58 +0700 Subject: [PATCH] revert syscall --- cores/nRF5/syscall_newlib.c | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/cores/nRF5/syscall_newlib.c b/cores/nRF5/syscall_newlib.c index 2b28d0ed..16224a60 100644 --- a/cores/nRF5/syscall_newlib.c +++ b/cores/nRF5/syscall_newlib.c @@ -40,7 +40,38 @@ #include "Arduino.h" -// linker provide end symbol is enough for nanolib's sbrk() +// TODO linker provide end symbol is enough for nanolib's sbrk() +// Verify this later with upgrade toolchain in the next release + +// defined in linker script +extern unsigned char __HeapBase[]; +extern unsigned char __HeapLimit[]; + +static unsigned char *sbrk_heap_top = __HeapBase; + +//volatile uint32_t first_sbrk = 0; +//volatile uint32_t last_sbrk = 0; + +caddr_t _sbrk( int incr ) +{ + unsigned char *prev_heap; + + if ( sbrk_heap_top + incr > __HeapLimit ) + { + /* Out of dynamic memory heap space */ + errno = ENOMEM; + return (caddr_t) -1; + } + + prev_heap = sbrk_heap_top; + +// if ( !first_sbrk) first_sbrk = sbrk_heap_top; +// last_sbrk = sbrk_heap_top; + + sbrk_heap_top += incr; + + return (caddr_t) prev_heap; +} #if 0 void __malloc_lock(struct _reent *ptr)