From f5ba70cd202300421f8a93fe59071f72d54a45c5 Mon Sep 17 00:00:00 2001 From: Mariano Alvira Date: Sun, 6 Feb 2011 14:29:01 -0500 Subject: [PATCH] add heap and _sbrk to mc13224v --- cpu/mc1322x/contiki-misc.c | 23 +++++++++++++++++++++++ cpu/mc1322x/mc1322x.lds | 4 ++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/cpu/mc1322x/contiki-misc.c b/cpu/mc1322x/contiki-misc.c index 9744e943d..30ab28447 100644 --- a/cpu/mc1322x/contiki-misc.c +++ b/cpu/mc1322x/contiki-misc.c @@ -36,6 +36,7 @@ #include #include "contiki.h" #include "mc1322x.h" +#include int raise(void) { @@ -49,3 +50,25 @@ void srand(unsigned int seed) { int rand(void) { return (int)*MACA_RANDOM; } + +extern int __HEAP_START; +extern int __HEAP_END; + +caddr_t _sbrk ( int incr ) +{ + static unsigned char *heap = NULL; + unsigned char *prev_heap; + + if (heap == NULL) { + heap = (unsigned char *)&__HEAP_START; + } + prev_heap = heap; + /* check removed to show basic approach */ + + if((heap + incr) >= (unsigned char *)&__HEAP_END) return((void *)-1); + + heap += incr; + + return (caddr_t) prev_heap; +} + diff --git a/cpu/mc1322x/mc1322x.lds b/cpu/mc1322x/mc1322x.lds index 85cf11df7..df3ca8895 100644 --- a/cpu/mc1322x/mc1322x.lds +++ b/cpu/mc1322x/mc1322x.lds @@ -215,11 +215,11 @@ HEAP_SIZE = 1024; . = ALIGN(32 / 8); .heap : { - __heap_start__ = . ; + __heap_start__ = . ; PROVIDE(__HEAP_START = .); *(.heap); . += HEAP_SIZE; . = ALIGN (4); - __heap_end__ = . ; + __heap_end__ = . ; PROVIDE(__HEAP_END = .); }